python3 更新和删除

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Areigninhell/article/details/83996185
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}})

猜你喜欢

转载自blog.csdn.net/Areigninhell/article/details/83996185