elasticsearch - Connection to a cluster - elastic - elastic search - elasticsearch tutorial - elasticsearch docker



Connection to a cluster

In this example, we create an empty index (we index no documents in it) by defining its mapping. First, we create an ElasticSearch instance and we then define the mapping of our choice. Next, we check if the index exists and if not, we create it by specifying the index and body parameters that contain the index name and the body of the mapping, respectively.

from elasticsearch import Elasticsearch

# create an ElasticSearch instance
es = Elasticsearch()
# name the index
index_name = "my_index"
# define the mapping
mapping = {
    "mappings": {
        "my_type": {
                "properties": {
                    "foo": {'type': 'text'},
                    "bar": {'type': 'keyword'}
                }
            }
        }
    }
    
# create an empty index with the defined mapping - no documents added
if not es.indices.exists(index_name):
    res = es.indices.create(
        index=index_name,
        body=mapping
    )
    # check the response of the request
    print(res)
    # check the result of the mapping on the index
    print(es.indices.get_mapping(index_name))
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

This elasticsearch tutorial provides fllowing articles and keypoints on hosted elasticsearch , elasticsearch monitoring , elasticsearch service , aws elastic search , elk elasticsearch , amazon elasticsearch , azure elasticsearch , aws elasticsearch , elastic , elastic search , elasticsearch logstash kibana , elasticsearch security , elasticsearch pricing , elasticsearch alternatives , elasticsearch hadoop , elasticsearch documentation , elasticsearch kibana , elastic co , elasticsearch , elasticsearch download , logstash elasticsearch , what is elasticsearch , elasticsearch vs mongodb , elasticsearch architecture , elasticsearch database , install elasticsearch , elasticsearch mongodb , elasticsearch document , elasticsearch marvel , elasticsearch shield , elasticsearch sense , elasticsearch analyzer , elasticsearch getting started , elasticsearch bulk , elasticsearch 5 , elasticsearch gui , elasticsearch tutorial

Related Searches to Connection to a cluster