ElasticSearch — Convert your index data into Pandas DataFrame

Sonal Patni
Sep 2, 2018 · 1 min read

If you work with Pandas and use elasticsearch, chances are you may have a requirement to convert your index data into a Pandas Dataframe.

This article explains how you can do that in 5 lines of code.

Before you begin, you need to have the following libraries installed in your environment.

#code you will need to write:

from elasticsearch import Elasticsearch
from pandasticsearch import Select

# Connection to ElasticSearch
es = Elasticsearch([‘http://localhost:9200'],timeout=600)

# Retrieving all documents in index (no query given)
documents = es.search(index=’myindex’,body={})

# Convert the result to Pandas Dataframe
pandas_df = Select.from_dict(documents).to_pandas()

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade