嵌套集上的Elasticsearch过滤器

时间:2017-03-09 10:24:35

标签: elasticsearch

我无法弄清楚如何过滤嵌套集。我的索引中有这个:

PUT /testing

PUT /testing/_mapping/product
{
   "product": {
      "properties": {
         "features": { "type": "nested" }
      }
   }
}

POST /testing/product
{
   "productid": 123,
   "features": [
      {
         "name": "Weight",
         "nameslug": "weight",
         "value": "10",
         "valueslug": "10-kg"
      },
      {
         "name": "Weight",
         "nameslug": "weight",
         "value": "12",
         "valueslug": "12-kg"
      }
   ]
}

我需要对value进行过滤,但我从网址获取valueslug。到目前为止,我有以下代码:

POST _search
{
   "query": {
      "bool": {
         "filter": [
            {
               "nested": {
                  "path": "features",
                  "query": {
                     "bool": {
                        "filter": [
                           {
                              "range": {
                                 "features.value": { "gte": ???  }
                              }
                           }
                        ]
                     }
                  }
               }
            }
         ]
      }
   }
}

困难的部分是将valueslug解析为实际value。我已经使用doc_value查看了脚本查询,但问题在于它是在当前嵌套文档中执行的。通过执行两个查询是可能的,但我试图避免这种情况(如果可能的话)。

我觉得解决方案在于文档的结构方式,但我不知道如何构建这个文档...

我希望有人能指出我正确的方向。

提前致谢!

0 个答案:

没有答案