42

Given the following query:

(field:value1 OR field:value2 OR field:value3 OR ... OR field:value50)

Can this be broken down into something less verbose? Basically I have hundreds of category IDs, and I need to search for items under large groups of category IDs (20-50 at a time). In MySQL, I'd just use field IN(value1, value2, value3) rather than (field = value1 OR field = value2 etc...).

Is there a simpler way for Solr/Lucene?

Michael Moussa
  • 4,207
  • 5
  • 35
  • 53

2 Answers2

100

Use

field:(value1 value2 value3)

or if your default operator is AND then use

field:(value1 OR value2 OR value3)
martsraits
  • 2,915
  • 3
  • 27
  • 25
  • 2
    Any idea where this is explained in the documentation? – Angry Dan Feb 01 '19 at 13:14
  • While this approach works, it's not accurate. At least not in elastic. If you have any other field (in my case `_id`) with the same value, it will find those too. ie: `/_search?q=(clientId:3966 OR 42952)` brings those 2 clients and another one with _id=42952 – Nicolas Mariano Obregon Oct 24 '19 at 20:54
  • @NicolasMarianoObregon I'm not sure if this syntax should work in Elastic or not but you have made a typo when writing your query. `clientId:` should be outside of the parentheses. – martsraits Oct 28 '19 at 13:56
  • Any tips on using this for rank instead of filtering on Solr? – rjurney Apr 22 '20 at 16:44
1

The accepted answer didn't work for me, but the following format did: +(field:value1 OR field:value2 OR field:value3)

Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35
artin2
  • 136
  • 1
  • 5