我正在查詢 ES 以獲取某個特定時間戳內的檔案串列。現在我遇到了一個場景,我們有多個版本的單個 documentId。默認情況下,ES 向我回傳了該單個 documentId 的所有版本。我的要求是只獲得所有檔案的最后一個版本。
此外,我還想讓所有 ES 回應按索引時間戳欄位(稱為 streamingSegmentStartTime)的升序排序
我當前的查詢如下所示: ?
{"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"}}]}
uj5u.com熱心網友回復:
嘗試使用 collapse 引數根據欄位值折疊搜索結果 https://www.elastic.co/guide/en/elasticsearch/reference/8.1/collapse-search-results.html#collapse-search-results
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/446599.html
