在我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
查询。
有没有办法使用嵌套对象的简单查询?
此答案可能有所帮助:http://stackoverflow.com/questions/35353952/is-it-possible-to-search-nested-objects-in-elasticsearch-with-the-lucene-query-s/35354869# 35354869 – Val
谢谢,@Val,虽然我不打算使用Lucene查询语法,但我发现[answer](https://github.com/elastic/elasticsearch/issues/11322)与您指出的答案链接在:_“嵌套字段需要使用嵌套查询/过滤器进行查询,因为多个文档可以匹配,并且您需要能够指定这些多个分数应该如何减少到单个分数。”# –