I have a requirement where i need to to fetch all the users using elastic search for the landing page using pagination where in topmost/first record should be from current logged in user.
I am able to get the paginated response for all the users using match all query but i am not able to get the current user record as top most record in paginated response.
is it possible to achieve this using elastic search query, my elastic search version is 7.6.0
here is my code
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder builder = QueryBuilders.boolQuery();
long totalHits;
builder.must(QueryBuilders.matchAllQuery());
builder.must(QueryBuilders.existsQuery(book.squadMemberMongoId.keyword)); // squad member must be present
sourceBuilder.from(from);
sourceBuilder.size(size);
sourceBuilder.trackTotalHits(true);
sourceBuilder.trackTotalHitsUpTo();
sourceBuilder.sort((SortBuilders.fieldSort("book.eaLastName.keyword").order(SortOrder.ASC)));
sourceBuilder.query(builder);
searchRequest.source(sourceBuilder);
// client is instance of RestHighLevelClient
response=client.search(searchRequest, RequestOptions.DEFAULT);
SearchHit[] hits = searchResponse.getHits().getHits();
is there any way where i can make above query to return current logged in user / specific record in top of the response list (current logged user can be identified by squadMemberMongoId field in data)
Sample Data:
{
"submissionId": "232323237",
"revision": 2,
"author": {
"country": "xyz",
"email": "john.doe@informa.com",
"name": "john doe"
},
"book": {
"eaLastName" : "xyzea"
"squad": "John",
"squadMemberMongoId": 12345678
}
....
}
submissionId is the index key here
expected response:
If i have multiple different submissions with different submission ids and different squadMemberMongoId under book , when i make a query i want record with specific squadMemberMongoId to be on top of the response then followed by other records with different id's, entire response set has to be paginated