What Can I Do If two Different Values Are Returned for hits.total When the Same Statement Is Used to Query Data in Elasticsearch in the Same Condition for Twice?
Symptom
The values returned for hits.total are different when the same Elasticsearch statement is used to query data in the same query condition (for example, the value ranges from 1 to 92).
Cause Analysis
- This problem is a difficult problem in the Elasticsearch community. For details, visit https://github.com/elastic/elasticsearch/issues/25603.
- The community provides two workarounds:
- Specify the preference parameter _primary_first, which indicates that the query is preferentially performed on the primary shard. However, the query performance is affected when the number of requests with high concurrency is large.
- Add the sort parameter to the query statement to sort data by keyword in the index.
Solution
Add the sort parameter to the query statement to sort data by keyword in the index. Determine whether to change the sorting rules based on the actual service logic if sorting needs to be used.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot