2017-04-20 65 views
0

在我elasticsearch指数我有这是一个嵌套的对象,像这样的属性文件:在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" 
         } 
        }] 
       } 
      } 
     } 
    } 
} 

到目前为止太好了。我使用querystring中的一个非常普遍的机制构建我的elasticsearch查询。所以,我希望能够用“常规”(非嵌套)查询还是查询文件,像这样:

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

不过,我只得到空的结果与类型的查询,除非我包它变成nested查询。

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

+0

此答案可能有所帮助:http://stackoverflow.com/questions/35353952/is-it-possible-to-search-nested-objects-in-elasticsearch-with-the-lucene-query-s/35354869# 35354869 – Val

+0

谢谢,@Val,虽然我不打算使用Lucene查询语法,但我发现[answer](https://github.com/elastic/elasticsearch/issues/11322)与您指出的答案链接在:_“嵌套字段需要使用嵌套查询/过滤器进行查询,因为多个文档可以匹配,并且您需要能够指定这些多个分数应该如何减少到单个分数。”# –

回答

0

这是不可能的(ES 5.3.1)与query_stringhttps://github.com/elastic/elasticsearch/issues/16551

对于其他查询,无论您如何处理嵌套字段,都需要使用nested查询来使用它。

+0

因此,使用'query_string'嵌套对象(链接的问题是关于什么)对于像普通的'term'查询(我所问的)其他查询是必需的? –

+0

我很困惑。你提到'query_string' ...不管你用嵌套字段做什么,你都需要一个嵌套的查询来使用它。 –

+0

我提到'query_string'?你发布的链接是关于'query_string' :)谢谢反正。更多信息在我对这个问题的评论。 –

相关问题