Python 列表中的 Elasticsearch DSL 查询值
Python Elasticsearch DSL query value from a list
我正在使用 Python 的 Elasticsearch DSL 包:
http://elasticsearch-dsl.readthedocs.org/en/latest/search_dsl.html
我的示例 elasticsearch 条目如下所示:
{
"_index" : "users",
"_type" : "player",
"_id" : "1",
"_version" : 5,
"found" : true,
"_source":{"doc": {"weight": 92, "height": 184, "gender": "male", "firstname": "John", "lastname": "Smith", "age": 31, "country": "France"}}
我正在尝试获取 [France, Australia]
列表中 firstname = "John*"
个国家/地区的所有条目。这是我的代码:
firstname = 'John'
s = Search(index='users').using(elasticsearch)
must = [
{'match': {'doc.firstname': {'query': firstname + '*', 'boost': 2}}},
{'terms': {'doc.country': [u'France', u'Australia']}}]
s = s.query(Q('bool', must=must))
response = s.execute()
它returns 空结果,我做错了什么?我正在使用这里的建议:
Elasticsearch match list against field
我是 Elasticsearch 的新手,对于我们在哪里使用查询和过滤器仍然有点困惑。
我为此使用了 should 参数:
firstname = 'John'
s = Search(index='users').using(elasticsearch)
must = [
{'match': {'doc.firstname': {'query': firstname + '*', 'boost': 2}}}]
should = []
for country in countries:
should.append({'match': {'doc.country': country}})
s = s.query(Q('bool', must=must, should=should, minimum_should_match=1))
response = s.execute()
我正在使用 Python 的 Elasticsearch DSL 包: http://elasticsearch-dsl.readthedocs.org/en/latest/search_dsl.html
我的示例 elasticsearch 条目如下所示:
{
"_index" : "users",
"_type" : "player",
"_id" : "1",
"_version" : 5,
"found" : true,
"_source":{"doc": {"weight": 92, "height": 184, "gender": "male", "firstname": "John", "lastname": "Smith", "age": 31, "country": "France"}}
我正在尝试获取 [France, Australia]
列表中 firstname = "John*"
个国家/地区的所有条目。这是我的代码:
firstname = 'John'
s = Search(index='users').using(elasticsearch)
must = [
{'match': {'doc.firstname': {'query': firstname + '*', 'boost': 2}}},
{'terms': {'doc.country': [u'France', u'Australia']}}]
s = s.query(Q('bool', must=must))
response = s.execute()
它returns 空结果,我做错了什么?我正在使用这里的建议: Elasticsearch match list against field
我是 Elasticsearch 的新手,对于我们在哪里使用查询和过滤器仍然有点困惑。
我为此使用了 should 参数:
firstname = 'John'
s = Search(index='users').using(elasticsearch)
must = [
{'match': {'doc.firstname': {'query': firstname + '*', 'boost': 2}}}]
should = []
for country in countries:
should.append({'match': {'doc.country': country}})
s = s.query(Q('bool', must=must, should=should, minimum_should_match=1))
response = s.execute()