ElasticSearch 2.x存在过滤器的嵌套字段不起作用 [英] ElasticSearch 2.x exists filter for nested field doesn't work

查看:194
本文介绍了ElasticSearch 2.x存在过滤器的嵌套字段不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下映射

{
  "properties": {
    "restaurant_name": {"type": "string"},
    "menu": {
      "type": "nested",
      "properties": {
        "name": {"type": "string"}
      }
    }
  }
}

我试图过滤所有那些具有可选菜单字段的文档

I am trying to filter all those documents which have optional "menu" field exists

GET /restaurnats/_search
{
  "filter": {
    "query": {
      "bool": {
        "must": [
          {"exists" : { "field" : "menu" }}
        ]
      }
    }
  }
}

但是,当我尝试使用相同的查询来过滤那些具有restaurant_name的文档时,可以正常工作。那么为什么嵌套字段检查不起作用?如何使其工作?

But, when I try the same query to filter those documents which have "restaurant_name", then it works fine. So why nested field check doesn't work? How to get it work?

推荐答案

您需要使用嵌套查询:

{
  "filter": {
    "query": {
      "nested": {
        "path": "menu",
        "query": {
          "bool": {
            "must": [
              {
                "exists": {
                  "field": "menu"
                }
              }
            ]
          }
        }
      }
    }
  }
}

这篇关于ElasticSearch 2.x存在过滤器的嵌套字段不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆