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
:
$ curl -X GET --insecure "https://elastic:[email protected]:9200/_cat/indices/kibana*"
green open kibana_sample_data_ecommerce QcLgMu7CTEKNjeJeBxaD3w 1 0 4675 0 4.2mb 4.2mb
green open kibana_sample_data_logs KPcJfMoSSaSs-kyqkuspKg 1 0 14074 0 8.1mb 8.1mb
green open kibana_sample_data_flights q8MkYKooT8C5CQzbMMNTpg 1 0 13059 0 5.8mb 5.8mb
We can use the requests
library to make a similar function in a Python script, Chapter13_1.py
:
#!/usr/bin/env python3
import requests
from requests.packages.urllib3.exceptions...