Jonathan Ilambo
Jonathan Ilambo

Reputation: 329

How to query lucene for empty fields?

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

Upvotes: 23

Views: 37736

Answers (3)

dcorking
dcorking

Reputation: 1206

-_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

Upvotes: 9

riofly
riofly

Reputation: 1765

*:* -MY_FIELD_NAME:[* TO "zzzzzzzzzz"]

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

Upvotes: 7

Mikos
Mikos

Reputation: 8553

*:*  -MY_FIELD_NAME:[* TO *] 

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

Upvotes: 24

Related Questions