...
Code Block |
---|
|
curl 'http://localhost:9200/{index_name}/_search?pretty' -d '
{
"query": {
"range" : {
"modified_at" : {
"lte" : "2018-02-13T18:01:44"
}
}
},
"size": 1
}' |
Delete documents by query
In case you see some wrong document in the index and you want to delete them, e.g. document belong to the same source with id "123456789abcdef", then you can delete them by using query:
Code Block |
---|
|
curl -XPOST 'http://localhost:9200/{index_name}/_delete_by_query' -d '
{
"query": {
"term" : {
"assoc:subscriptions" : "123456789abcdef"
}
}
}' |
Note 1: Before delete by a query you always have to make sure that the query return only documents you want to delete by searching for that query and review some results:
Code Block |
---|
|
curl 'http://localhost:9200/{index_name}/_search?pretty' -d '
{
"query": {
"term" : {
"assoc:subscriptions" : "123456789abcdef"
}
}
}' |
Note 2: After deleting by query, the index size on disk is not reduced because a document is not deleted from a segment, just marked as deleted. So if you want to free disk space after deleting, then execute this command:
Code Block |
---|
|
curl -XPOST 'http://localhost:9200/{index_name}/_forcemerge?only_expunge_deletes=true' |
Troubleshooting
Shards are UNASSIGNED
...
Code Block |
---|
|
# save thisthe query in json format, e.g to /tmp/es_request.json
# make request to ES using the thisas input file:
curl 'http://localhost:9200/{index_name}/_search?pretty' -d @/tmp/es_request.json |
...