1

I dumped 3 json objects from an array to a localhost Elasticsearch index "amazon".

When I accessed the index in localhost, it shows me this output

{"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"}}}}

I want to access the values of "title", "price" and "images" from my python code. How can I do that?

1 Answer 1

1

Your output (let's call it d) is a dictionary. You can extract a branch of the nested dictionary structure and query its keys:

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}}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.