0

I cannot get how to query my index for all the documents not having the optional field named "adm4".

Any suggestion?

Max
  • 2,508
  • 3
  • 26
  • 44

1 Answers1

1

Kludgy: Make sure the adm4 field is indexed and give it a default value in your schema.xml file. Then querying for that default value will return all documents that didn't get a "real" value for adm4 at index time. For example, if adm4 is an integer and 0 is not a meaningful value...

<field name="adm4" type="int" default="0" indexed="true" stored="true"/>

Much Better: Add -adm4:[* TO *] to your query per SolrQuerySyntax docs. I found this after my first answer, but I'm editing rather than replacing or your comment wouldn't make sense. :)

EDIT: After more testing (Solr 4.3), it seems the range is unneeded and -adm4:* yields the same result.

Patrick Lee
  • 1,990
  • 1
  • 19
  • 24
  • it sounds more like a workaround then an actual solution. Is there actually not a way to do it in case a default value is not desired? – Max Dec 31 '15 at 18:54
  • Very true. I did some more research and found a pure query option. Answer is edited to include this option. – Patrick Lee Dec 31 '15 at 19:27
  • I've tested this with numeric and string fields and it works in both cases. Just be sure the word `TO` in the range is all-caps. – Patrick Lee Dec 31 '15 at 19:39