Elasticsearch with a Python client
We can interact with Elasticsearch via its HTTP RESTful API using a Python library. For instance, in the following example, we will use the requests
library to perform a GET
operation to retrieve information from the Elasticsearch host. For example, we know that HTTP GET
for the following URL endpoint can retrieve the current indices starting with kibana
:
(venv) $ curl http://192.168.2.200:9200/_cat/indices/kibana*
green open kibana_sample_data_ecommerce Pg5I-1d8SIu-LbpUtn67mA 1 0 4675 0 5mb 5mb
green open kibana_sample_data_logs 3Z2JMdk2T5OPEXnke9l5YQ 1 0 14074 0 11.2mb 11.2mb
green open kibana_sample_data_flights sjIzh4FeQT2icLmXXhkDvA 1 0 13059 0 6.2mb 6.2mb
We can use the requests
library to make a similar function in a Python script, Chapter12_1.py
:
#!/usr/bin/env python3
import requests
def current_indices_list(es_host, index_prefix):
current_indices = []
http_header = {'content...