Including/Excluding empty

In the beer sample bucket how I do query to include or exclude the JSON element website that are not empty? {"website":""}

This may or may not work today, but let me outline how we would expect it to work…

  1. You should index the field with the keyword analyzer. This analyzer will index the contents of the field exactly, without any further transformations.

  2. You would then do a term search on that field with the term “”. The empty string should be a valid term. This probably only works with an explicit term query and when using the query string. The reason is that the query string syntax probably cannot recognize a zero-length term in its grammar.

Reasons why it may not work today. The keyword analyzer should index a single token with term length 0, but I’m not sure I’ve ever tested this case, so its possible it doesn’t work as expected.

Its also important to note that this will only work to find fields with the content empty. It will not work to find fields with null or fields that are missing entirely from the JSON document. To implement these we’d need the exists/missing query operators which we currently don’t have.


Thanks for the quick reply.

I was trying
+type:brewery -website:""

and thought the the empty string was not being parsed or skipped.

I was also thinking how it would handle {"website":null} as some people use null to mean empty too.

to implement these we’d need the exists/missing query operators

Thats a good call.