Better to define color.not_null as a boolean field and always initialize as either true or false.

But, even without that you need write a pure negative query or clause as

   (*:* -term)

So:

   select?q=*:*&fq=((*:* -color:[* TO *]) OR color:blue)

and

   select?q=*:*&fq=((*:* -color.not_null:[* TO *]) OR color:blue)

-- Jack Krupansky

-----Original Message----- From: Van Tassell, Kristian
Sent: Tuesday, July 02, 2013 3:47 PM
To: solr-user@lucene.apache.org
Subject: How to query Solr for empty field or specific value

Hello,

I'm using Solr 4.2 and am trying to get a specific value (blue) or null field (no color) returned by my filter query. My results should yield 3 documents (If I execute the two separate filters in different queries, I get 2 hits for one query and 1 for the other).

I've tried this (blue or no color set):

select?q=*:*&fq=(-color:[* TO *] OR color:blue)

When that returned zero hits, I added a new field called "color.not_null" and am setting it only if a color is defined (thinking there was a problem with using the same field name).

select?q=*:*&fq=(-color.not_null:[* TO *] OR color:blue)

That too yielded zero results. Again, executing them separately does return hits (3).

Does anyone see what I might be doing wrong? Thanks in advance,
Kristian

Reply via email to