如何在python中从Elasticsearch访问索引值
我将3个json对象从一个数组转储到一个如何在python中从Elasticsearch访问索引值,python,json,dictionary,
elasticsearch,Python,Json,Dictionary,
elasticsearch,我将3个json对象从一个数组转储到一个localhostElasticsearch索引“amazon” 当我访问localhost中的索引时,它显示了这个输出 {"amazon":{"aliases":{},"mappings":{"product-title":{"properties":{"images":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"price":{"type":"t
localhost
Elasticsearch索引“amazon”
当我访问localhost
中的索引时,它显示了这个输出
{"amazon":{"aliases":{},"mappings":{"product-title":{"properties":{"images":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"price":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"title":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}},"settings":{"index":{"creation_date":"1538923579981","number_of_shards":"5","number_of_replicas":"1","uuid":"SQ83_ecZSn6x9mDsGj9KLQ","version":{"created":"6040299"},"provided_name":"amazon"}}}}
我想从python代码中访问“title”
、“price”
和“images”
的值。我该怎么做呢?您的输出(我们称之为d
)是一本字典。您可以提取嵌套字典结构的分支并查询其键:
properties = d['amazon']['mappings']['product-title']['properties']
title = properties['title']
price = properties['price']
images = properties['images']
print(title, price, images, sep='\n')
{'type': 'text', 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}}
{'type': 'text', 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}}
{'type': 'text', 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}}