繁体   English   中英

列表中的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()

它返回空结果,我在做什么错? 我正在使用来自这里的建议: Elasticsearch对字段的匹配列表

我是Elasticsearch的新手,还是对我们在哪里使用查询vs过滤器感到困惑。

我为此使用了应参数:

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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM