[英]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.