gpt4 book ai didi

elasticsearch - Elasticsearch排序不适用于嵌套字段

转载 作者:行者123 更新时间:2023-12-02 22:19:32 25 4
gpt4 key购买 nike

Elasticsearch排序不适用于嵌套字段。它显示升序和降序混合值。像40、30、50一样。它没有以这样的升序显示:30、40、50

查询:

"sort": [
{
"sellerInfoES.offerPrice": {
"order": "asc",
"ignore_unmapped": true,
"missing": "_last"
}
}
]

最佳答案

很难对嵌套字段进行排序,问题是您可以拥有多个嵌套文档,因此您必须决定选择哪个文档。一种方法是在嵌套文档中具有某个字段的最小值,然后对该值进行排序。您可以使用模式属性来执行此操作。您还需要 nested_pa​​th 属性。

应该是这样的:

   "sort" : [
{
"sellerInfoES.offerPrice" : {
"mode" : "avg",
"order" : "asc",
"nested_path" : "sellerInfoES"
}
}
]

更多信息可以在elasticsearch引用中找到:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#_nested_sorting_example

关于elasticsearch - Elasticsearch排序不适用于嵌套字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38360158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com