Satish
Satish

Reputation: 1943

Search documents in lucene that do not contain a field

I need to search only documents that do not contain a particular field.

I tried this, doesn't work:

BooleanQuery constrainedQuery = new BooleanQuery();
constrainedQuery.add(query, BooleanClause.Occur.MUST);
constrainedQuery.add(new TermQuery(new Term("fieldName")), BooleanClause.Occur.MUST_NOT);

Not sure if I can use QueryWrapperFilter for this either. My current alternative is to search for everything and ignore the documents that contain the field in the hits. Looking for a better way, thank you.

Upvotes: 1

Views: 253

Answers (1)

A. Coady
A. Coady

Reputation: 57438

FieldValueFilter, with the negate flag.

Upvotes: 2

Related Questions