gpt4 book ai didi

Elasticsearch 按嵌套对象的数量排序

转载 作者:行者123 更新时间:2023-12-02 22:46:34 24 4
gpt4 key购买 nike

我有以下 ES 内容,基本上是一个包含网站嵌套报价的产品列表。

{
"product": {
"ean": "abc",
"features": {
"product_type": "DVD player"
},
"color": "Black",
"manufacturer": "Sony",
"sitedetails": [
{
"name": "amazon.com",
"sku": "zzz",
"url": "http://www.amazon.com/dp/zzz"
},
{
"name": "bestbuy.com",
"sku": "aaa",
"url": "http://www.bestbuy.com/aaa"
}
],
"category": "Portable DVD Players"
},
product: { etc etc},
product: { etc etc},
}

如何按站点详细信息的数量排序?

谢谢!

最佳答案

您可以使用 Painless 来完成,因此您不必启用动态脚本。

{
"sort": [{
"_script": {
"type": "number",
"script": "params._source?.product?.sitedetails?.length ?: 0",
"order": "desc"
}
}]
}

我还包括对空字段的处理。看 https://www.elastic.co/guide/en/elasticsearch/painless/master/_operators.html

https://github.com/elastic/elasticsearch/issues/20068

关于Elasticsearch 按嵌套对象的数量排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35897062/

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