Use the package manager pip to install elasticsearch.
$ pip install elasticsearch
Connection and authentication of elastic cloud with python client
While connecting to Elastic cloud with python Elasticsearch client,cloud_id parameter is used which can be found within the'Manage Deployment'page after a cluster has been created and api_key which also can be created while cluster creation.
from elasticsearch import Elasticsearch
client = Elasticsearch(cloud_id="CLOUD_ID",api_key="API_KEY")
client.options().indices.create(index='index_ name', ignore=400)
LIST OF ALL INDEXES WILL BE GENERATED.
result = client.indices.get_alias(index="*")
for Name in result:
print(Name)
data = {"username":"XYZ","address":"MP"}
result = client.index(index='energy06',body=data)
print("RECORD : {}".format(result))
query={"query" : {
"match_all" : {}
}}
result = client.search(index="index_name", body=query, size=1000)
print(result)
Below query will delete a specific document or item from a particular index on the basis of _id.
client.delete(index="index_name", id="id")
In order to delete a particular index the below query is used.
client.indices.delete(index='index_name')
For the complete Elasticsearch documentation visit elastic.co