How can I search on a list of values using Solr/Lucene?
Asked Answered
Z

2

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?

Zeal answered 10/4, 2010 at 13:48 Comment(1)
#2534315Senn
L
101

Use

field:(value1 value2 value3)

or if your default operator is AND then use

field:(value1 OR value2 OR value3)
Limerick answered 10/4, 2010 at 20:32 Comment(4)
Any idea where this is explained in the documentation?Cyclothymia
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=42952Assistant
@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.Limerick
Any tips on using this for rank instead of filtering on Solr?Escargot
L
1

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

Lumbard answered 29/12, 2020 at 1:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.