我有以下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}, }
如何按站点详细信息的数量排序?
tnx!
从问题的示例来看,它看起来像是单个文档,但是单个json文档不可能在同一级别具有相同名称的多个字段。
因此,假设每个product字段代表一个不同的顶级文档
product
{ "size": 10, "from": 0, "query": { "match_all": {} }, "sort" : { "_script" : { "script": "doc['sitedetails'].values.size()", "order": "desc", "type" : "number" } } }