[英]Query elastic search with many levels of “bool query”
I am trying to implement a search system with ElasticSearch. 我正在尝试使用ElasticSearch实现搜索系统。 My problem lies in the location of objects First, the searched objects can have different type of location: 我的问题在于对象的位置首先,搜索到的对象可以具有不同的位置类型:
Here is an example: 这是一个例子:
Country = A
State = B
District = C
Currently I get all the objects that have the location :
Country = A and State = B and District = C
I want also find objects which have the location:
only Country = A
and
only Country = A and State = B
It's a bit complicated to explain but the principle is. 解释有点复杂,但原理是这样。
So I created the following query ElasticSearch : 所以我创建了以下查询ElasticSearch:
"query" : {
[{"bool":{
"should":[
{"bool":{
"must":[
{"match":{"country":"-223"}},
{"match":{"state":"-3760"}},
{"match":{"district":"-8245"}}
]
}},
{"bool":{
"must":[
{"match":{"country":"-223"}},
{"match":{"state":"-3760"}},
{"match":{"district":""}}
]
}},
{"bool":{
"must":[
{"match":{"country":"-223"}},
{"match":{"state":""}},
{"match":{"district":""}}
]
}}
]
}}]
}
But it does not work, I do not really know what I've done wrong. 但这是行不通的,我真的不知道自己做错了什么。 I read the documentation on this site: 我阅读了此站点上的文档:
http://www.elasticsearch.org/guide/reference/query-dsl/bool-query/ http://www.elasticsearch.org/guide/reference/query-dsl/bool-query/
And I try all that seemed useful for my problem but without success Is someone can help me find what's wrong? 并且我尝试了所有对我的问题有用但没有成功的方法是否有人可以帮助我找出问题所在?
Thank you F. 谢谢你F.
I do this by indexing the data bit bit differently. 我通过以不同的方式索引数据位来实现此目的。
For every document I index multiple values in the location field for each document namely: 对于每个文档,我在每个文档的位置字段中索引多个值,即:
country
country/state
country/state/district
That way if I want to find everything in a certain country i search for location:country and if I want everything in a certain state I search for location:country/state 这样,如果我想在某个国家/地区中查找所有内容,我会搜索location:country;如果我想在某个州/地区中查找所有事物,我会搜索location:country / state
This has the side effect of being REALLY nice for nested faceting. 这具有非常好的嵌套面方面的副作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.