0

I have three fields say F1, F2, F3. I want to find all the documents which have all three fields values as null. Can I achieve this by using BooleanQuery? If I use MUST_NOT clause for all three fields then It will not return the documents which have one of these fields as non null value.

I'm talking about implementing something like this

BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new TermQuery(new Term(F1,"")), BooleanClause.Occur.MUST_NOT);
booleanQuery.add(new TermQuery(new Term(F2,"")), BooleanClause.Occur.MUST_NOT);
booleanQuery.add(new TermQuery(new Term(F3,"")), BooleanClause.Occur.MUST_NOT);

This surely is not going to work.How can i achieve this ? any help would be helpful.

Apr444
  • 53
  • 1
  • 9

1 Answers1

0

Not sure how your index looks like but you wanna achieve this right?

you wanna have a query which is searching with this fields and this fields have to be empty

BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new TermQuery(new Term(F1,"")), BooleanClause.Occur.MUST);
booleanQuery.add(new TermQuery(new Term(F2,"")), BooleanClause.Occur.MUST);
booleanQuery.add(new TermQuery(new Term(F3,"")), BooleanClause.Occur.MUST);

This boolean query is searching for a empty terms (second param of term is "") in this field, for each field it has to be a must.

dom
  • 732
  • 7
  • 19