[英]How to delete documents from multiple indices using particular field name in elasticsearch python?
这是示例文档。
{
"_index": "mqtt-index-2018.01.23",
"_type": "iot_data",
"_id": "AWEjA7LNRU4cTUO-Lyj4",
"_score": null,
"_source": {
"message": "{\"datastream_name\": \"roshni\", \"value\": 12,
\"context\": {\"latitude\": 0, \"elevation\": 0, \"longitude\": 0},
\"device_id\": 31}",
"@version": "1",
"@timestamp": "2018-01-23T12:34:59.687Z",
"host": "iot-elk",
"topic": "telemetry/f2a55827ef554475a41c3c96369957f0/roshni",
"datastream_name": "roshni",
"value": 12,
"context": {
"latitude": 0,
"elevation": 0,
"longitude": 0
},
"device_id": 31,
"tstamp": "2018-01-23T12:34:59.687Z"
},
"fields": {
"tstamp": [
1516710899687
],
"@timestamp": [
1516710899687
]
},
"sort": [
1516710899687
]
}
我想使用device_id字段删除文档。 如何使用API调用或使用python客户端删除它? 我已经尝试使用Document _id和特定索引,但我想通过使用device_id字段或其他字段删除它。
使用以下DELETE API调用从elasticsearch中的多个索引中删除文档。
curl -XDELETE 'http://localhost:9200/mqtt-index-*/logs/_query' -d '{
"query" : {
"match" : {"device_id": 31}
}
}' -i
没有示例代码的简短回答:
if data["parsed_message"]["device_id"] not in list_of_forbidden_ids):
在使用原始API方面,我相信这正是您所寻求的 。
根据您使用的python库,它在python中实际上更容易。 我使用elasticesearch-dsl-py
,在那里构建查询对象。 您可以在这些查询对象上调用delete 。
关于跨越多个索引,ElasticSearch确实支持这一点,使用通配符*
或使用逗号分隔索引。
您还可以删除具有匹配的多个字段的文档。
curl -XDELETE 'http://localhost:9200/mqtt-index-*/logs/_query' -d '{
"query" : {
"bool": {
"must":[
{"match" : {"device_id":31}},
{"match": {"datastream_name": "test"}}
]
}
}' -i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.