-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Adapt custom routing for search and count methods #2087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks a lot for this example. After testing and digging through the code I found that routing in queries is supported since 2014, it is possible to set the route on a So you can change your code to Query query = new NativeSearchQueryBuilder()
.withRoute(routVar)
.withFilter(boolQuerybuilders)
.withPageable(PageRequest.of(0, 10))
.withSort(SortBuilders.fieldSort("testVar").order(SortOrder.DESC))
.build(); I admit that this is not easy to find. We should adapt the behaviour to first check the value set on a query, if that is not set, use the routingresolver. Then both ways would work to set the route would work. |
Thank you for the code snippet, don't know how I missed this, I was browsing through methods of most classes to find something like this. That will be great(enhancing the behavior) because if operations have routingresolver the first instinct is that it should work for everything the |
Code related to the issue: https://github.com/neeraj7483/spring-data-elastic-issue
spring-data-elastic-issue
Code for recreating the issue with custom routing
spring boot version: 2.5.8
spring-data-elastic version: 4.2.7
ElasticSearch version: 7.15.2
PREREQUISITE
Issue description
Steps to reproduce
@Routing
to set custom routing, define the number of shards and enable index creation.ReactiveElasticsearchOperations
to query data.withRouting
method ofReactiveElasticsearchOperations
to specify routing.searchForPage
orcount
method to query data (search query can be anything).While examine the result you will notice that custom routing is not taken into consideration. Also when you debug you will notice that
SearchRequest
which is created does not have any routing information associated with it itsrouting
variable is null. IF you set the routing variable to value you want everything to start working correctly.NOTE: The workaround of this issue is to create a replica of
ReactiveElasticsearchTemplate
and modify the methods to add setrouting
onSearchRequest
and everything will work fine(this is a long route because many classes used byReactiveElasticsearchTemplate
directly or indirectly are not public so you have to create a replica of every class). I have also tried subclassingReactiveElasticsearchTemplate
and overriding the required methods and providing my custom subclass while configuring things by extending classAbstractReactiveElasticsearchConfiguration
but somehow it always ends up calling the parent methods (maybe I am doing something wrong or missing a core concept).Specific steps to reproduce(as per checked-in code)
ReactiveElasticRestClientConfiguration
.test
. The documents are as follows.GET test/_search?routing=rout2 { "track_total_hits": true, "explain": true, "query": { "bool": { "filter": [ { "term": { "searchStr": "search2" } } ] } } }
GET test/_search?routing=rout1 { "track_total_hits": true, "explain": true, "query": { "bool": { "filter": [ { "term": { "searchStr": "search2" } } ] } } }
ReactiveElasticsearchOperations
'swithRouting
,count
methods./test/entity
which takesearchStr
androutVar
as query param and returns the matched documents, another endpoint is/test/entity/count
which takesearchStr
androutVar
as query param and returns the count of matched documents.TestProcessor
class is where all logic is, it is usingReactiveElasticsearchOperations
withRouting
,count
andsearchForPage
, where I am filtering onsearchStr
and routing onroutVar
.doc with
searchStr
search2 and search2 will be on rout2 andsearchStr
search1 and search1 will be on rout1.The text was updated successfully, but these errors were encountered: