0

I have following structure of databse in solr

<doc>
<int name="bookid">123</int>
<str name="bookname">java</str>
<arr name="provider">
    <str>JMD</str>
     <str>BBH</str>
     <str>RBH</str>
</arr>
<arr name="price">
     <int>120</int>
     <int>125</int>
     <int>100</int>
</arr>
</doc>

............... more doc like that. i want filter like where provider is JMD and price is 100. what solr query use for this.

Ichigo Kurosaki
  • 3,765
  • 8
  • 41
  • 56
Akhilesh
  • 57
  • 8

2 Answers2

0

Use filter (fq)

http://localhost:8983/solr/collection1/select?indent=on&q=*:*&wt=json&fq=provider:JMD&fq=price:100

replace host and collection name

Vinod
  • 1,965
  • 1
  • 9
  • 18
  • it also return doc in which provider JMD having price more than 100 price. like above doc in question. for my requirement above doc not be in resonse. above doc in response when query is like provider JMD and price 120. arrray correspondence is JMD = 120, BBH=125 , RBH=100. – Akhilesh Aug 19 '16 at 07:01
  • price field having multiple values 100, 125,120. so if you search for any one these price will show you entire document in result. that doc can be matched with any price value among three 100, 120, 125. or with price range. – Vinod Aug 19 '16 at 07:16
0

The easiest solution - as long as you're just looking for matches as you describe - is to merge both values into a single field for filtering:

<arr name="provider_price">
    <str>JMD__120</str>
    <str>BBH__125</str>
    <str>RBH__100</str>
</arr>

And then query with a filter query: fq=provider_price:JMD__100.

Another option, as long as the number of fields aren't too great (using DocValues would probably help if the number of fields is large) - this will also allow you to range searches properly (which you also can do with the previous approach, as long as you prefix values to a given length with 0 so they're in the same lexical sort order):

<arr name="JMD_price">
    <str>120</str>
</arr>
<arr name="BBH_price">
    <str>125</str>
</arr>
<arr name="RBH_price">
    <str>100</str>
</arr>

Querying: fq=JMD_price:100

The third option is to use a separate core for these queries:

<doc>
    <int name="bookid">123</int>
    <str name="bookname">java</str>
    <str name="provider">JMD</str>
    <int name="price">120</int>
</doc>
<doc>
    <int name="bookid">123</int>
    <str name="bookname">java</str>
    <str name="provider">BBH</str>
    <int name="price">125</int>
</doc>
<doc>
    <int name="bookid">123</int>
    <str name="bookname">java</str>
    <str name="provider">RBH</str>
    <int name="price">100</int>
</doc>

Query would then be fq=provider:JMD AND price:100.

The fourth option is to use parent/child documents, but this will complicate any queries made against the index.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • Hi MatsLindh your first two approches can not be implementable as when we required more than 100 or less than 100 price point than it fails. and third is not used as we required bookid is unique field for solr. ANY WAYS THANKS ALOTS – Akhilesh Aug 19 '16 at 10:22
  • For the third option, you'd have a separate core - bookid does not need to be unique in this core. For the two other options, I'm not sure why the first would give you issue regarding the number of price points, and for the second, I'd at least evaluate the memory usage before throwing it away. We've used it with about 2.5k different field names, and it worked - but ate quite a bit of memory. This was back in 1.4, before DocValues were available. If you're not sorting by the field, your experience will probably be even better. – MatsLindh Aug 19 '16 at 10:47