Skip to content

Instantly share code, notes, and snippets.

@tofbabs
Forked from dadoonet/deletebyquery.sh
Created May 28, 2018 09:04
Show Gist options
  • Save tofbabs/6b64a0aa4e730a60d98de1780c4febfc to your computer and use it in GitHub Desktop.
Save tofbabs/6b64a0aa4e730a60d98de1780c4febfc to your computer and use it in GitHub Desktop.
Delete By Query usage
echo "clean index"
curl -XDELETE 'http://localhost:9200/twitter?pretty' ; echo
echo "PUT Tweet"
curl -XPUT 'http://localhost:9200/twitter/tweet/1?ttl=1h&pretty' -d '
{
"created_at": "Mon May 13 19:59:27 +0000 2013"
}
' ; echo
# Refresh docs
echo "Refresh index"
curl -XPOST 'http://localhost:9200/twitter/_refresh?pretty' ; echo
echo "Search"
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty' -d '
{ "query" : {
"filtered": {
"query": {"match_all": {}},
"filter": {"range": {
"created_at": {
"lt": "now-1h"
}
}}
}
}
}' ; echo
echo "Delete by same query"
curl -XDELETE 'http://localhost:9200/twitter/tweet/_query?pretty' -d '
{
"filtered": {
"query": {"match_all": {}},
"filter": {"range": {
"created_at": {
"lt": "now-1h"
}
}}
}
}' ; echo
# Refresh docs
echo "Refresh index"
curl -XPOST 'http://localhost:9200/twitter/_refresh?pretty' ; echo
echo "Search"
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty' -d '
{ "query" : {
"filtered": {
"query": {"match_all": {}},
"filter": {"range": {
"created_at": {
"lt": "now-1h"
}
}}
}
}
}' ; echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment