0

我正在尝试使用 ElasticSearch 实现搜索系统。我的问题在于对象的位置首先,搜索到的对象可以有不同类型的位置:

  • 国家
  • 国家+州
  • 国家+州+地区

这是一个例子:

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

解释起来有点复杂,但原理是。

所以我创建了以下查询 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":""}}
                      ]
                }}
            ]
        }}]
  } 

但它不起作用,我真的不知道我做错了什么。我阅读了此站点上的文档:

http://www.elasticsearch.org/guide/reference/query-dsl/bool-query/

我尝试了所有似乎对我的问题有用但没有成功的方法有人可以帮助我找出问题所在吗?

谢谢F。

4

1 回答 1

1

我通过不同地索引数据位来做到这一点。

对于每个文档,我在每个文档的位置字段中索引多个值,即:

country
country/state
country/state/district

这样,如果我想在某个国家/地区找到所有东西,我会搜索 location:country,如果我想在某个州找到所有东西,我会搜索 location:country/state

这具有非常适合嵌套刻面的副作用。

于 2013-09-04T14:41:29.837 回答