Skip to content

Instantly share code, notes, and snippets.

@dakrone
Created July 19, 2013 03:23
Show Gist options
  • Select an option

  • Save dakrone/6034875 to your computer and use it in GitHub Desktop.

Select an option

Save dakrone/6034875 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
curl -s -XDELETE localhost:9200/missing-test
curl -s -XPOST localhost:9200/missing-test -d'
{
"mappings": {
"doc": {
"_source": {
"enabled": true
},
"properties": {
"id": {
"index": "not_analyzed",
"type": "string"
},
"myfield": {
"type": "string"
}
}
}
},
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
}
}'
curl -s -XPUT "localhost:9200/missing-test/doc/1" -d'{ "id": "1" }'
curl -s -XPUT "localhost:9200/missing-test/doc/2" -d'{ "id": "2", "myfield": "foo" }'
curl -s -XPOST 'localhost:9200/missing-test/_refresh'
echo
echo "Regular filter for null_value=true, existence=false"
curl 'localhost:9200/missing-test/doc/_search?pretty' -d'
{
"query": {
"match_all": {}
},
"filter": {
"missing": {
"field": "myfield",
"existence": false,
"null_value": true
}
}
}'
echo
echo "Filtered query with filter for null_value=true, existence=false"
curl 'localhost:9200/missing-test/doc/_search?pretty' -d'
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"missing": {
"field": "myfield",
"existence": false,
"null_value": true
}
}
}
}
}'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment