1

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?

Shweta Valunj
  • 148
  • 1
  • 11

2 Answers2

1

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.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • what if it is a set of string? For example, `setOfStringsField1:{"string1ishere","string2ishere","string2"}` `setOfStringsField2:{"string1is","string2is","string2"}` and I want to search for `string and here` so I should get only setOfStringsField1 as output? – Shweta Valunj Oct 11 '18 at 13:22
  • That's slightly different and [makes it a bit easier](https://stackoverflow.com/questions/25038080/how-can-i-tell-solr-to-return-the-hit-search-terms-per-document/25038386#25038386), but it's still more straight forward to index them as separate documents in that case. – MatsLindh Oct 11 '18 at 13:25
  • Thanks for the reply. I have one more doubt can we search in solr without AND operator to find string that contains two words? – Shweta Valunj Oct 11 '18 at 13:40
  • You can use `q.op=AND` to tell Solr that all terms are required, then use `defType=edismax` to use the extended dismax query parser, which is made for more typical user input (such as just typing `string here` instead. – MatsLindh Oct 11 '18 at 13:44
  • thanks for your help! Instead of the new document I created a customized field to do it. – Shweta Valunj Oct 15 '18 at 07:28
0

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.

Vishw Patel
  • 529
  • 2
  • 9