在elasticsearch中,是否可以对嵌套对象使用常规查询?

时间:2017-04-20 20:03:35

标签: elasticsearch

在我的弹性搜索索引中,我有一个文件,其属性是一个嵌套对象,如下所示:

{
  "my_index": {
    "mappings": {
      "my_type": {
        "properties": {
          "nested_prop": {
            "type": "nested",
            "properties": {
              "subprop1": {
                "type": "boolean"
              },
              "subprop2": {
                "type": "keyword"
              }
            }
          }
        }
      }
    }
  }
}

我现在可以使用嵌套查询搜索对象,如下所示:

{
    "query": {
        "nested": {
            "path": "nested_prop",
            "query": {
                "bool": {
                    "must": [{
                        "term": {
                            "nested_prop.subprop1": "true"
                        }
                    }, {
                        "term": {
                            "nested_prop.subprop2": "SOME_KEY"
                        }
                    }]
                }
            }
        }
    }
}

到目前为止一切顺利。我使用来自查询字符串的非常通用的机制来构建我的elasticsearch查询。因此,我希望能够仍然使用"常规"来查询文档。 (非嵌套)查询如下:

{
    "query": {
        "term": {
            "nested_prop.subprop1": "true"
        }
    }
}

但是,除非我将其包装到nested查询中,否则我只会使用这种查询获得空结果。

有没有办法对嵌套对象使用简单查询?

1 个答案:

答案 0 :(得分:0)

query_stringhttps://github.com/elastic/elasticsearch/issues/16551目前无法实现(ES 5.3.1)。

对于其他查询,无论您对嵌套字段执行什么操作,都需要nested查询才能使用它。

相关问题