Skip to content
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

[BUG] Search request with PIT + searchAfter and 2 sort fields loses some hits #15857

Closed
Anastasiia186 opened this issue Sep 9, 2024 · 2 comments
Labels
bug Something isn't working Clients Clients within the Core repository such as High level Rest client and low level client untriaged

Comments

@Anastasiia186
Copy link

Describe the bug

#15869

Executing a search request with a PIT + searchAfter and 2 sort fields (first one is not uniq, second one is uniq) returns less hits in total that for track_total_hits. The smaller the page size, the more data is lost, if you use scrolling, there is no problem. if you change the sorting values (only 1 uniq or first one is uniq and second one is not uniq), the problem also disappears

Related component

Clients

To Reproduce

How can one reproduce the bug?

create a search request with a PIT and 2 sort fields like

 PointInTimeBuilder pointInTimeBuilder = new PointInTimeBuilder(pitId);
 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
                .pointInTimeBuilder(pointInTimeBuilder);
        searchSourceBuilder.query(<query>);
        searchSourceBuilder.sort(SortBuilders
                .fieldSort(<not uniq field>)
                .order(SortOrder.ASC));
        searchSourceBuilder.sort(SortBuilders
                .fieldSort(<uniq fiel>)
                .order(SortOrder.ASC));
        searchSourceBuilder.size(10_000)

_____________

"sort": [
  {
      "<not uniq field>":{
        "order": "asc"
      }
    },
    {
      "<uniq fiels>": {
        "order": "asc"
      }
    }
  ]

run this query several times using searchAfter like:

searchSourceBuilder.searchAfter(prevSearch.getHits().getHits()[prevSearch.getHits().getHits().length - 1].getSortValues());
SearchRequest searchRequest = new SearchRequest();
searchRequest.source(searchSourceBuilder);
restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT)

and notice that in total you have less hits that returns in track_total_hits:
total using PIT = 1999953
"total": {
"value": 2000000,
"relation": "eq"
}

Expected behavior

A search response in total returns the same number of hits as for track_total_hits

Additional Details

SpringBoot application

@Anastasiia186 Anastasiia186 added bug Something isn't working untriaged labels Sep 9, 2024
@github-actions github-actions bot added the Clients Clients within the Core repository such as High level Rest client and low level client label Sep 9, 2024
@dblock
Copy link
Member

dblock commented Sep 11, 2024

@Anastasiia186 Want to try and turn this into a failing YAML REST test?

@Anastasiia186
Copy link
Author

@dblock we rechecked the second field and found some duplicates...we removed them and now it works fine
thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Clients Clients within the Core repository such as High level Rest client and low level client untriaged
Projects
None yet
Development

No branches or pull requests

2 participants