pull elasticsearch index into python df code example
Example 1: get data from elasticsearch to jupyter
from datetime import datetime
from elasticsearch import Elasticsearch
from pandas import DataFrame, Series
import pandas as pd
import matplotlib.pyplot as plt
es = Elasticsearch(host="192.168.121.252")
res = es.search(index="_all", doc_type='logs', body={"query": {"match_all": {}}}, size=2, fields=('path','@timestamp'))
Example 2: make pandas dataframe from elasticsearch
# Create a basic ES client
client = Elasticsearch(['url'])
# Search
search = Search(using=client)
results = search.execute()
search_dict = results.hits.hits
results_df = pd.DataFrame(search_dict)