Search code examples
solrsolr4

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?


Solution

  • 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.