根据嵌套文档按多个值排序

时间:2018-11-13 10:32:09

标签: elasticsearch kibana

我正在尝试将排序机制从应用程序转移到elasticseach,但没有结果。我要做的就是按嵌套商品价格和可用数量对返回的文档进行弹性排序。 就像sql类型的命令一样简单

order by Quantity desc, Price asc

这里缩短了在Kibana中的Elasticsearch回报

"_index": "product_index",
"_id": "1",        
"_source": {                       
    "id": 1
    },
    "sort": [          
          5.9
        ],
        "inner_hits": {
          "variants": {
            "hits": {
              "total": 2,
              "hits": [
                {
                  "_nested": {
                    "field": "variants",
                    "offset": 2
                  },
                  "_score": 0,
                  "_source": {                    
                    "offer_state": 3,
                    "stock_quantity": 2,                    
                    "gross_price": 5.9,                                     
                  }
                },
                {
                  "_nested": {
                    "field": "variants",
                    "offset": 1
                  },
                  "_score": 0,
                  "_source": {                    
                    "offer_state": 3,
                    "stock_quantity": 5,                    
                    "gross_price": 21.9,                    
                  }
                }
              ]
            }
          }
        }

并将排序查询传递给了弹性

"sort": [
    {
      "variants.gross_price": {
        "order": "asc",
        "nested_filter": {
          "bool": {
            "filter": [
              {
                "term": {
                  "variants.offer_state": {
                    "value": 3
                  }
                }
              },
              {
                "range": {
                  "variants.gross_price": {
                    "gt": "0"
                  }
                }
              }              
            ]
          }
        },
        "nested_path": "variants"
      }
    }
  ]

如何包括基于嵌套文档的级联排序?我的预期结果是返回的“ sort”:[]中的21.9。

0 个答案:

没有答案