I have a nested field called 'category':
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"name": {
"type": "keyword",
"null_value": "NULL"
},
"categories": {
"type": "nested",
"properties": {
"handle": {
"type": "keyword",
"null_value": "NULL"
},
"name": {
"type": "keyword",
"null_value": "NULL",
"fields": {
"text": {
"type": "text",
"norms": false
}
}
}
}
}
}
}
}
}
Data:
PUT my_index/my_type/_bulk?refresh
{"index":{"_id":1}}
{"name":null,"categories":[{"handle":null,"name":"books"}]}
{"index":{"_id":2}}
{"name":[],"categories":[null]}
{"index":{"_id":3}}
{"name":"philip","categories":null}
{"index":{"_id":4}}
{"name":["philip"]}
{"index" : {"_id":5}}
{"name":[null]}
{"index": {"_id": 6}}
{"query":{"term":{"name":"NULL"}}}
Using the 5.X version, I want to get the NULL fields. Following works find:
GET my_index/_search
{
"query": {
"nested": {
"path": "categories",
"query": {
"term": {
"categories.handle": "NULL"
}
}
}
}
}
But how can I check if a whole nested object is null. The following query does not work:
GET my_index/_search
{
"query": {
"nested": {
"path": "categories",
"query": {
"term": {
"categories": "NULL"
}
}
}
}
}
How can I make a query that gives me ids 2 and 3 for null categories as result?