python3 更新和删除 elasticsearch 及其删除es索引

from elasticsearch import Elasticsearch

es_client = Elasticsearch(["localhost:9200"])

// 多个条件限制的删除
delete_options ={"query":{
                         "bool":{
                         "must":[{"term":{"alert_level":"critical"}},
                         {"range":{
                         "write_date":{
                         "gte":"2018-11-11",
                        "lte":"now"
                        }
                                                      }
                                                      }
                                                    ]
                                                }
                                                }
                                                }

// 根据id删除
delete_by_id = {"query":{"match":{"_id":"_Yon72YBncOSVgrNpmU6"}}}
// 删除所有
delete_by_all = {"query":{"match_all":{}}}
result = es_client.delete_by_query(index="index_name", body=delete_by_id, doc_type="vulnerability")
print(result)
# 更新
es_client.update(index="sapiens_ids_compare", doc_type="vulnerability", id="id号", body={"doc": {"is_linked": 0}})

es_client.indices.flush()

# 删除索引
es_client.indices.delete('log_index')

 

你可能感兴趣的:(python后端,Elasticsearch)