I can't quite get my head around a specific search requirement I have, so I
hope someone can help.
My documents have a field "published" with a string value "yes" or "no"
(not boolean true/false, indexed data out of my control at present!). This
defines whether the document has been published or not, obviously. I have a
fairly large boolean query of a series of "must" sub-queries, of which one
is on this published field, ensuring that only those "yes" are returned.
However I've just realised that this field is optional in the document.
If it doesn't have a yes/no value, then the assumption is that the document
is published ("yes") and should be returned. So in essence I want to add a
must clause for this field only when it exists and has a value. Is this
even possible? Should I perhaps use a filter here?
You can work around your problem by using the exists and/or missing filter.
If the default for the published field is "yes, then you can use an Or
filter with one clause being a term filter for "yes" and the other a
missing filter.
I can't quite get my head around a specific search requirement I have, so
I hope someone can help.
My documents have a field "published" with a string value "yes" or "no"
(not boolean true/false, indexed data out of my control at present!). This
defines whether the document has been published or not, obviously. I have a
fairly large boolean query of a series of "must" sub-queries, of which one
is on this published field, ensuring that only those "yes" are returned.
However I've just realised that this field is optional in the document.
If it doesn't have a yes/no value, then the assumption is that the document
is published ("yes") and should be returned. So in essence I want to add a
must clause for this field only when it exists and has a value. Is this
even possible? Should I perhaps use a filter here?
Hi, I found this old posting but it is now relevant with the new Boolean Queries in es 2.x. I have a similar situation where I need to search for documents where a specific field may be missing, but if it is present, then it needs to have an specific value. My old query using OR (deprecated) looks like this:
Thanks @Camilo_Sierra but the "missing" query is also deprecated in es 2.2 (Deprecated in 2.2.0. Use exists query inside a must_not clause instead.) So, based on your example, I tried something like this:
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.