如果某个嵌套字段的值大于1,则获取整个Elasticsearch文档

时间:2018-07-23 10:21:53

标签: elasticsearch nested

我需要获取某个特定文件(嵌套文件)具有多个值的所有文档。 例如:

PUT /example/example
{
  "user": "bla",
  "passwords": [
    {
      "password": "bla1",
      "host": "something"
    }
  ]
}
PUT /example/example
{
  "user": "bla2",
  "passwords": [
    {
      "password": "bla2",
      "host": "something"
    },
    {
      "password": "bla3",
      "host": "something2"
    }
  ]
}

查询将仅返回第二个文档作为结果

我尝试了此查询

GET /example/example/_search
   {
  "size": 100,
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        },
        {
          "script": {
            "script": "doc['passwords'].values.flatten().length > 1"
          }
        }
      ]
    }
  }
}

但是当我查询时似乎不知道该字段的密码。 它返回:

"caused_by": {
            "type": "illegal_argument_exception",
            "reason": "No field found for [passwords] in mapping with types [example]"
          }

有没有一种方法可以计算嵌套对象并根据此值进行过滤?

0 个答案:

没有答案