[英]How are the documents ordered in Elasticsearch if the sort value for two documents is same?
我正在使用產品數據,這里: 鏈接
使用最大模式按關鍵字字段標簽排序的搜索查詢如下。
GET product/_doc/_search
{
"size":100,"from":20,"_source":["tags", "name"],
"query": {
"match_all": {}
},
"sort": [
{"tags":{
"order":"desc",
"mode":"max"
}}
]
}
一些文檔具有相同的排序值。 我在某處讀到,如果排序值相同,則按內部文檔ID(_id)排列。 但是,情況似乎並非如此。 請參見下面的屏幕截圖:
第一個_id:961,然后是_id:972 (精細)。 但是,接着出現_id:114 。 我不明白它是如何隨機的。
幫助將不勝感激。
如您所見,它是隨機的。 為了克服這個問題,當第一個字段的排序值相同時,您可以添加另一個字段進行排序。 當您要使用_id
,查詢將如下所示:
{
"size": 100,
"from": 20,
"_source": [
"tags",
"name"
],
"query": {
"match_all": {}
},
"sort": [
{
"tags": {
"order": "desc",
"mode": "max"
}
},
{
"_id": "asc"
}
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.