-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
property totalHits is always 0 on BoolQuery Search response #53267
Comments
Thanks for opening this issue @durancu. Maybe the default (10000) for If you add: I'm not sure yet why you always get zero total hits via hlrc if you don't alter the search source build's track total hits. |
Pinging @elastic/es-core-features (:Core/Features/Java High Level REST Client) |
Hi @martijnvg, thanks for your quick response |
That is odd. What version of hlrc are you using on the client side? |
In 7.6 this is a public method: https://github.com/elastic/elasticsearch/blob/7.6/server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java#L584 In older 6.x releases this method didn't exist. |
I purged my local Maven repository, and reimport all dependencies. And have noted that elasticsearch Since I am using objects from rest-client, like SearchSourceBuilder, that's why I can access latest version of rest-client. See dependencies tree from Intellij: |
Are you using spring boot by any chance ? |
Yes, I am using Spring Boot. Sorry forgot to mention |
When using springboot with Basically you can put this in your
See documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-customize-dependency-versions |
Thanks @dadoonet for your reply.
to section, and it didn't work. I am see this is something related to SpringBoot more than ElasticSearch. |
I'm just aware that spring data elasticsearch has a new beta version IIRC which is compatible with 7.x so may be you need to use that? |
Solution was to override version of spring-boot dependencies (elasticsearch, elasticsearch-client): 1- Define property for elasticsearch version:
2- Exclude autoconfigured dependencies from elasticsearch-rest-high-level-client
3- Call elasticsearch dependencies by themselves, using same version:
This is a way to override the version, but need to be careful to prevent incompatibilities with forced dependency version. |
Describe the feature: totalHits property always returns 0, but hits contains items
Elasticsearch version (
bin/elasticsearch --version
): 7.6Plugins installed: []
JVM version (
java -version
): 8OS version (
uname -a
if on a Unix-like system): MacOSDescription of the problem including expected versus actual behavior:
I am using Java REST Client to implement a microservice that integrates to Elasticsearch (via AWS).
When I am debugging, I see totalHits is coming always as zero (0),
If I run same query in Kibana, it returns the right value of totalHits.
I create a boolQuery, with several must queries inside it. For the example I am debugging, I have a BoolQueryBuilder object, and the generated query is:
This is my request object toString:
This is the response I get:
As you can see, despites there are many hits,
totalHits
property is 0However, if I run same query in Kibana, I get a number of totalHits matching that query, that is not 0
Steps to reproduce:
1- Create a BoolQueryBuilder object
2- Add a must query to the object, using matchPhraseQuery, on a keyword column
3- Create a SearchRequest object
4- Create a SearchSourceBuilder object
5- Add BoolQueryBuilder object to SearchSourceBuilder object as query
6- Set SearchSourceBuilder object as source of SearchRequest.
7- Call Elasticsearch client using SearchRequest object and RequestOptions.DEFAULT
The text was updated successfully, but these errors were encountered: