Shweta Valunj
Shweta Valunj

Reputation: 158

How to search multiple words in one field on solr?

I have a field in solr of type list of texts.

field1:{"key1:val1,key2:val2,key3:val3", "key1:val1,key2:val2"}

I want to form a query such that when I search for key1:val1 and key3:val3 I get the result who has both the strings i.e key1:val1 and key3:val3.

How shall I form the query?

Upvotes: 1

Views: 2254

Answers (2)

MatsLindh
MatsLindh

Reputation: 52792

If these are values in a multivalued field, you can't - directly. You'll have to use something like highlighting to tell you where Solr matched it.

There is no way to tell Solr "I only want the value that matched inside this set of values".

If this is a necessary way to query your index, index the values as separate documents instead in a separate collection. In that case you'd have to documents instead, one with field1:"key1:val1,key2:val2,key3:val3" and one with key1:val1,key2:val2.

Upvotes: 1

Vishw Patel
Vishw Patel

Reputation: 549

You can use AND with fq.

Like:

fq=key1:val1 AND key3:val3

With this filter query you will get only records where key1 = val1 AND key3 = val3.

Upvotes: 0

Related Questions