Skip to content

Instantly share code, notes, and snippets.

Created June 29, 2016 17:50
Show Gist options
  • Save anonymous/7032b8bac261873814281c0d144ad0df to your computer and use it in GitHub Desktop.
Save anonymous/7032b8bac261873814281c0d144ad0df to your computer and use it in GitHub Desktop.
#!/bin/sh
# Create an index with a single nested field "foo"
curl -XPOST localhost:9200/testmissing -d '{
"settings": {
"number_of_shards": 1
},
"mappings": {
"test1": {
"properties": {
"foo": {
"type": "nested",
"dynamic": "false",
"properties": {
"k": {
"type": "string"
},
"v": {
"type": "string"
}
}
}
}
}
}
}'
# Add a single document with a "foo"
curl -XPUT -d '{"foo": {"k": "k1", "v": "v1"}}' localhost:9200/testmissing/test1/doc1
# Search and do a Missing aggregation on foo
curl -XPOST -d '{"aggs": {"foomissing": {"missing": {"field": "foo"} } } }' localhost:9200/testmissing/_search?pretty
# Output:
# {
# "took" : 1,
# "timed_out" : false,
# "_shards" : {
# "total" : 1,
# "successful" : 1,
# "failed" : 0
# },
# "hits" : {
# "total" : 1,
# "max_score" : 1.0,
# "hits" : [ {
# "_index" : "testmissing",
# "_type" : "test1",
# "_id" : "doc1",
# "_score" : 1.0,
# "_source" : {
# "foo" : {
# "k" : "k1",
# "v" : "v1"
# }
# }
# } ]
# },
# "aggregations" : {
# "foomissing" : {
# "doc_count" : 1
# }
# }
# }
# Why does foomissing=1 when foo is clearly present?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment