以下是准确的还是应该是其他内容?
我得到了预期的结果,只是检查这是否是访问单个(嵌套)字段的最有效方法。
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, Q
import json
client = Elasticsearch('my_server')
policy_number = 'POLICY1234'
s = Search(using=client, index = "my_index").query("term",policyNumber=policy_number.lower())
es_response = s.execute()
for hits in es_response:
print hits['policyNumber']
print hits.party[0]['fullName']
print hits.party[0].partyAddress[0]['address1']
print hits.party[0].partyAddress[0]['city']
print hits.party[0].phoneList[0]['phoneNumber']
您不需要execute
手动调用,也不必使用[]
按名称访问字段,您只需使用属性访问即可:
for hit in s:
print hit.policyNumber
print hit.party[0].fullName
print hit.party[0].partyAddress[0].address1
print hit.party[0].partyAddress[0].city
print hit.party[0].phoneList[0].phoneNumber
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句