0

What is the difference between the following two Solr queries, and which should be used when searching for null/non-null values?

fieldName:[* TO *]

fieldName:['' TO *]

Matt
  • 902
  • 7
  • 20

1 Answers1

1

They're practically the same. Use the first one as it's clearer about intent ([* TO *] is a common Solr pattern for referring to "everything that has a value).

The second one expresses the same, it just says "give me everything from the empty token to anything" instead of "give me anything". In effect they should return the same result.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • Could you then explain why, when using `[* TO *]` for my query, *everything* returns whereas using `['' TO *]` for my query, *nothing* returns? – Matt Feb 06 '20 at 13:30
  • `field:[* TO *]` should not return any documents without a value in that field (if that's your whole query in `q`). It's hard to say why `['' TO ..]` doesn't return anything - is it an textual field? How are you using it in your query? Are you doing negative queries? – MatsLindh Feb 06 '20 at 13:59
  • It's just a single field I'm querying for as an `fq`. Yes it is a textual field. The whole query is: `/select?q=*:*&fq=fieldName:[* TO *]&rows=0` – Matt Feb 06 '20 at 14:05
  • Add examples of what being returned to your question = `&rows=0` should indicate nothing being returned at all, so it's hard to say what you're seeing that you shouldn't. – MatsLindh Feb 06 '20 at 14:34
  • Right, but I'm referring to `numFound` in the response. That's where I'm seeing different results. for `[* TO *]` I'm seeing all results, for `['' TO *]` I'm seeing zero results. – Matt Feb 06 '20 at 14:40
  • It's hard to say if those results are correct or wrong when you're not looking at the content of the fields. Since you're saying `[* TO *]` returns all results, I assume you mean that it also returns results that shouldn't be included? The behaviour of `['' TO *]` might have changed in a Solr version if it's supposed to work (which I assumed from your question). I've only seen `[* TO *]` used myself. – MatsLindh Feb 06 '20 at 17:17