Symptom:
When the same ES query statement queries the same index data at the same time, the number of hits.total values returned by the same index data is inconsistent (switch between 1 and 92).
Cause Analysis
1. This problem is a difficult problem in the ES community. Trouble ticket number: https://github.com/elastic/elasticsearch/issues/25603. This problem has remained in the ES community for nearly two years and has not been resolved yet.
2. The community provides two workarounds:
1) Specify the preference parameter during the query. _primary_first: The query operation is preferentially performed on the primary segment.
2) The sort parameter is added to the query request statement, which is sorted by a keyword field in the index.
3. Test the two workarounds on site.
1) The preference parameter cannot be completely avoided, and the problem still occurs. In addition, the query performance is affected in the case of high concurrency and large quantity.
2) Add the sort parameter. The query result is correct.
Solution:
Workaround: The sort parameter is added to the query request statement, which is sorted by keyword in the index