Python/Python Programming

[ Python ] elastcisearch index 생성, 삭제, 조회

Pydole 2023. 4. 14. 13:27

 

 

Python ElasticSearch

 

from elasticsearch import Elasticsearch

es = Elasticsearch('http://127.0.0.1:9200')
ix = ix_name        # string

 

 

 

 

Search All Index 

 

for index in es.indices.get('*'):
    print(index)

 

 

 

Create Index 

 

# 3 shards, 1 replicas

body={"settings" : {"index" : {"number_of_shards" : 3,"number_of_replicas" : 1 }}}
res = es.indices.create(index=ix, body=mapping)
print(res)

-----------------------------------------------------------------------------------
True or False

 

 

 

Index Exists

 

res = es.indices.exists(index=ix)
print(res)

-------------------------------------------------
True or False

 

 

 

Delete Index 

 

res = es.indices.delete(index=ix, ,ignore=[400, 404])
print(res)

-------------------------------------------------
True or False