[英]Python ElasticSearch DSL Truncating Results
我正在嘗試在python中使用elasticsearch dsl庫,但是我似乎正在得到某種截斷的結果/元數據,而不是文檔/響應對象。 消毒的查詢如下:
from elasticsearch_dsl import Search, Q, F
from elasticsearch_dsl.query import MultiMatch
from elasticsearch import Elasticsearch
import requests
import json
client = Elasticsearch("")
s = Search().using(client).query("match", id="1")
response = s.execute()
test_response = response.json()
出現此錯誤:
AttributeError: 'Response' object has no attribute 'json'
我希望使用更新的DSL來使事情不再那么冗長。 有沒有人遇到這樣的事情或有任何提示。 非常感激!
execute()
的結果已經是已解析的JSON(結構與HTTP API的響應相同):
print(response.hits.total)
您還可以按以下方式遍歷結果( 文檔 ):
for h in response:
print(h.title, h.body)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.