How to query lucene for empty fields?
Asked Answered
D

3

23

I want in 2nd part of my query to have a list of result for while data not null. I find how do it in solr but not in lucene. Anyone have a idea Thanks

String :

( field_one:search AND field_two:3000) OR (field_three:search AND field_two:3000 AND NOT NULL field_one )

Query:

+field_one:search +field_two:3000 +field_three:search +field_two:3000 -field_one:null

Dialectologist answered 9/8, 2012 at 14:42 Comment(1)
Possible duplicate of Lucene not null query?Palua
Z
24
*:*  -MY_FIELD_NAME:[* TO *] 

The above should do it, note the * : * for Lucene.

Zabrine answered 9/8, 2012 at 19:12 Comment(2)
I try your proposal but that does not work. Given that the attribute that I would want whether it is not null is not indexed when no value was supplied, the request does not manage to handle it, I suppose.Dialectologist
well for the above to work, the field needs to exist (it only differentiates between NULL and Non NULL (cf. empty string)Zabrine
P
8

-_exists_:field_one works for me in ElasticSearch 6.0

reference: https://www.elastic.co/guide/en/elasticsearch/reference/6.0/query-dsl-query-string-query.html#_field_names

Palua answered 29/1, 2019 at 9:42 Comment(1)
That's not answering the original question, but Google led me here for the exact problem you are solving. Have my upvote!Joyajoyan
A
7
*:* -MY_FIELD_NAME:[* TO "zzzzzzzzzz"]

You can add more "z" chars to ensure to include any value of the field.

Amphicoelous answered 13/5, 2014 at 9:26 Comment(1)
Unfortunately, "zzzzzzzzzzz" does not take into account non-alphanumeric characters.Eriha

© 2022 - 2024 — McMap. All rights reserved.