-1

I'm querying ES to get me list of documents within some specific timestamp. Now I encountered a scenario where we had multiple versions of single documentId. By default ES returned me all the versions of that single documentId. My requirement is to get only one last version of all the docs.

Also I wanted to get all the ES response sorted in Ascending order of one the indexed timestamp field(called as streamingSegmentStartTime)

my current query looks like following : 


{"size":25,"query":{"bool":{"must":[{"terms":{"streamingSegmentId":["00002933-be25-3b9c-9970-472b41aa53cc"],"boost":1.0}},{"range":{"streamingSegmentStartTime":{"from":1644480000000,"to":1647476658447,"include_lower":true,"include_upper":false,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}},"_source":{"includes":["errorCount","benefitId","streamingSegmentStopTime", "fanoutPublishTimestamp", "search.version"],"excludes":[]},"sort":[{"streamingSegmentStartTime":{"order":"asc"}}, {"_timestamp": {"order": "desc"}}]}
priyadhingra19
  • 333
  • 4
  • 15

1 Answers1

1

try to use the collapse parameter to collapse search results based on field values https://www.elastic.co/guide/en/elasticsearch/reference/8.1/collapse-search-results.html#collapse-search-results

caster
  • 156
  • 4
  • I also wanted to use search_after to add pagination support for my ES query. I'm using AWS Elastic Search service which is using 7.10 version of ES and I found collapse can be used with search_after only from ES 8.1 version onwards. Please let me know if you have any other suggestion on this – priyadhingra19 Mar 21 '22 at 02:43