小编Tin*_* A.的帖子

如何使用 python 的 elasticsearch DSL 访问响应对象

我有以下代码:

s = Search(using=Elasticsearch('http://user:passwd@ipaddress'), index="myindex")
q = Q("multi_match", query='some query', fields=['_all'])
s = s.query(q)

response = s.execute()
print('Total %d hits found.' % response.hits.total)
for hit in response:
    print(hit.title)
Run Code Online (Sandbox Code Playgroud)

我收到错误:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/elasticsearch_dsl/utils.py", line 102, in __getattr__
return _wrap(self._d_[attr_name])
KeyError: 'title'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "FindImage.py", line 89, in <module>
main(args.image_file)
File "FindImage.py", line 82, in main
query_db([1], [2])
File "FindImage.py", line 77, in query_db
print(hit.title) …
Run Code Online (Sandbox Code Playgroud)

python elasticsearch elasticsearch-dsl

2
推荐指数
1
解决办法
5081
查看次数

标签 统计

elasticsearch ×1

elasticsearch-dsl ×1

python ×1