Hi,
I have a "not_analyzed" field as part of a nested document in my schema. A sample document is given below
"_source": {
"identifier": 123,
.
.
"nested_doc_name_xyz":[
{
"not_analyzed_field_name_xyz": [
"ABCD",
"1234",
""
]
}
]
}
To search for documents where not_analyzed_field_name_xyz does not exist and is not empty, the following is the query chunk I am using.
{
"bool": {
"filter": {
"bool": {
"must_not": {
"nested": {
"path": "nested_doc_name_xyz",
"query": {
"bool": {
"must": {
"exists": {
"field": "nested_doc_name_xyz.not_analyzed_field_name_xyz"
}
},
"must_not": {
"term": {
"nested_doc_name_xyz.not_analyzed_field_name_xyz": ""
}
}
}
}
}
}
}
}
}
}
Since the sample document I provided earlier, has an empty string as part of the whole value,
"not_analyzed_field_name_xyz": [
"ABCD",
"1234",
""
]
the search query given above is not returning the document with identifier 123.
Ideally, I want to filter out documents which
- do not have "nested_doc_name_xyz.not_analyzed_field_name_xyz" this field
and - those which have value for this field as ("nested_doc_name_xyz.not_analyzed_field_name_xyz": [""] or "nested_doc_name_xyz.not_analyzed_field_name_xyz":"")
Please let me know if you need any more details.