Must_not exists Query not Working Correctly


(Kevin M.) #1

I am running the following query against the count end point trying to get a count of all of the documents where the hq field is either missing or empty and I am getting a count of zero back even though I know there are lots of records where there is no value for hq:

{
"query": {
"bool": {
"must_not": {
"exists": {
"field": hq
}
}
}
}
}

In my index it appears that the hq field is present whether or not the field is actually populated and I see stuff like this :
......,
"hq": "",
......., etc

I thought that the must_not exists type of query would find documents where the field was outright missing OR empty, is that not the case? How can I get this query to work correctly? Do I need to reindex and treat the hq field differently? Right now it is just a string. Any help would be appreciated. Thanks.

Kevin


(Xavier Facq) #2

Doc says :

Exists Query
Returns documents that have at least one non-null value in the original field:
An empty string is a non-null value.

So I'll say that you have to set "null" as value or default value in your mapping.


(Kevin M.) #3

Ok, got it. Thanks for the clarification and suggestion.

Kevin


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.