Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中从Elasticsearch访问索引值_Python_Json_Dictionary_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Python,Json,Dictionary,elasticsearch" /> elasticsearch,Python,Json,Dictionary,elasticsearch" />

如何在python中从Elasticsearch访问索引值

如何在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

我将3个json对象从一个数组转储到一个
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}}}