I have the following query that I am trying to use to delete data from an ElasticSearch index.
{
"filter": {
"and": [
{
"range": {
"Time": {
"from": "20120101T000000",
"to": "20120331T000000"
}
}
},
{
"term": {
"Source": 1
}
}
]
}
}
I have tried to delete documents based on this query. This query returns results fine when I run it against the index. But when I try to run a delete command against the index, nothing happens.
I am not sure if I am constructiing the query wrong or what else.
You're using only a filter while the delete by query API probably needs a query. You can convert your filter to a query using a filtered query like this:
{
"filtered" : {
"query" : {
"match_all" : {}
},
"filter": {
"and": [
{
"range": {
"Time": {
"from": "20120101T000000",
"to": "20120331T000000"
}
}
},
{
"term": {
"Source": 1
}
}
]
}
}
}
Otherwise you could convert your filter to a query using a bool query with two must clauses, so that you don't need a filtered query anymore. Anyway, I guess the filter approach is better since filters are faster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With