You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
I want to perform some custom handling of my search result. For example, I run a search across three different indices which share some common fields. For example:
Search search = new Search.Builder(searchSourceBuilder.toString())
.addIndex("index1")
.addIndex("index2")
.addIndex("index3")
.build()
However, since these indices don't all have the exact same schema, reading this response isn't as simple as calling
Instead, I would like to iterate over each json element. Then depending on the index which the json element is from, I would like to cast the json to the corresponding class.
Currently, the Search class is tied to the SearchResult class. Therefore, if I wanted to use my own CustomSearchResult, I would need to copy/paste the entire Search class, only to change SearchResult to CustomSearchResult in the three places where it appears.
A better way to do this would be to use a generic class - GenericSearch, which implements all of the code in Search except using a generic type for the SearchResult class. The signature could look like this:
public class GenericSearch extends AbstractAction<T extends JestResult> { ... }
We can maintain backwards compatibility by using public class Search extends GenericSearch<SearchResult> {}. More importantly, anyone can use their own result handlers in a maintainable way by using either public class CustomSearch extends GenericSearch<CustomSearchResult> {} or (inline):
GenericSearch search = new GenericSearch<CustomSearchResult>.Builder(searchSourceBuilder.toString())
.addIndex("index1")
.addIndex("index2")
.addIndex("index3")
.build()
Would love to hear feedback from the team on this.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I want to perform some custom handling of my search result. For example, I run a search across three different indices which share some common fields. For example:
However, since these indices don't all have the exact same schema, reading this response isn't as simple as calling
Instead, I would like to iterate over each json element. Then depending on the index which the json element is from, I would like to cast the json to the corresponding class.
Currently, the
Search
class is tied to theSearchResult
class. Therefore, if I wanted to use my ownCustomSearchResult
, I would need to copy/paste the entireSearch
class, only to changeSearchResult
toCustomSearchResult
in the three places where it appears.A better way to do this would be to use a generic class -
GenericSearch
, which implements all of the code inSearch
except using a generic type for theSearchResult
class. The signature could look like this:We can maintain backwards compatibility by using
public class Search extends GenericSearch<SearchResult> {}
. More importantly, anyone can use their own result handlers in a maintainable way by using eitherpublic class CustomSearch extends GenericSearch<CustomSearchResult> {}
or (inline):Would love to hear feedback from the team on this.
The text was updated successfully, but these errors were encountered: