代码如下
from elasticsearch import Elasticsearch
es = Elasticsearch()
#es.indices.delete(index='my-index', ignore=400)
es.indices.create(index='my-index', ignore=400)
for e in test:
es.index(index="my-index", body=e, id=e['id'])
我需要先检查index exists
是否在创建索引之前。如果存在,那么如果没有索引,我的传入日志必须追加,我需要先创建它
最佳答案
由于您没有使用特定的映射或设置创建索引,因此您可以放弃该步骤而仅对数据进行索引,索引将自动创建。
这样就足够了:
from elasticsearch import Elasticsearch
es = Elasticsearch()
for e in test:
es.index(index="my-index", body=e, id=e['id'])
关于python - 如何在 Elasticsearch 中创建之前检查索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63390677/