I would like to run a query to see how many documents have an empty object stored as their value. For example it would return a document like:
"hits": [
{
"_source": {
"otherfield": "abc",
"somefield": {}
}
}
]
But not either no field / the field with an undefined value, or the field with an object containing attributes:
"hits": [
{
"_source": {
"otherfield": "abc",
// <-- note no "somefield"
}
},
{
"_source": {
"otherfield": "abc",
"somefield": { "field1": "value1" }
}
}
]
But the query I have will also return documents where the field is an object with attributes such as "somefield": { "field1": "value1" }
GET /documents/_search
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "somefield.field1"
}
},
]
"should": [
{
"exists": {
"field": "somefield"
}
}
],
"minimum_should_match": 2
}
}
}
Using Elasticsearch 5.4