Search using filter query on multivalued fields

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Search using filter query on multivalued fields

Srinivas Kashyap-2
Hi,

I have indexed data as shown below using DIH:

"INGREDIENT_NAME": [
          "EGG",
          "CANOLA OIL",
          "SALT"
        ],
"INGREDIENT_NO": [
          "550",
          "297",
          "314"
        ],
"COMPOSITION PERCENTAGE": [
          20,
          60,
          40
        ],

Similar to this, many other records are also indexed. These are multi-valued fields.

I have a requirement to search all the records which has ingredient name salt and it's composition percentage is more than 20.

How do I write a filter query for this?

P.S: I should only fetch records, whose Salt Composition percentage is more than 20 and not other percentages.

Thanks and Regards,
Srinivas Kashyap
________________________________
DISCLAIMER:
E-mails and attachments from Bamboo Rose, LLC are confidential.
If you are not the intended recipient, please notify the sender immediately by replying to the e-mail, and then delete it without making copies or using it in any way.
No representation is made that this email or any attachments are free of viruses. Virus scanning is recommended and is the responsibility of the recipient.
Reply | Threaded
Open this post in threaded view
|

Re: Search using filter query on multivalued fields

Erick Erickson
There is no way to do this with the setup you describe. That is, there’s no way to say “only use the third element of a multiValued field”.

What I’d do is index (perhaps in a separate field) with payloads, so you have input like SALT|20, then use some of the payload functionality to make this happen. See: https://lucidworks.com/2017/09/14/solr-payloads/

There are some other strategies that are simpler, one could index (again, perhaps in a separate field) SALT_20. Then you can form filter queries like “fq=ingredient:[SALT_20 TO *]. That’s not very flexible and you have to normalize (i.e. 1% couldn’t be SALT_1), so “it depends”.

The point is that you have to index cleverly to do what you want.

Best,
Erick

> On May 3, 2019, at 6:26 AM, Srinivas Kashyap <[hidden email]> wrote:
>
> Hi,
>
> I have indexed data as shown below using DIH:
>
> "INGREDIENT_NAME": [
>          "EGG",
>          "CANOLA OIL",
>          "SALT"
>        ],
> "INGREDIENT_NO": [
>          "550",
>          "297",
>          "314"
>        ],
> "COMPOSITION PERCENTAGE": [
>          20,
>          60,
>          40
>        ],
>
> Similar to this, many other records are also indexed. These are multi-valued fields.
>
> I have a requirement to search all the records which has ingredient name salt and it's composition percentage is more than 20.
>
> How do I write a filter query for this?
>
> P.S: I should only fetch records, whose Salt Composition percentage is more than 20 and not other percentages.
>
> Thanks and Regards,
> Srinivas Kashyap
> ________________________________
> DISCLAIMER:
> E-mails and attachments from Bamboo Rose, LLC are confidential.
> If you are not the intended recipient, please notify the sender immediately by replying to the e-mail, and then delete it without making copies or using it in any way.
> No representation is made that this email or any attachments are free of viruses. Virus scanning is recommended and is the responsibility of the recipient.

Reply | Threaded
Open this post in threaded view
|

Re: Search using filter query on multivalued fields

David Hastings
another option is to index dynamically, so you would index in this case, or
this is what i would do:
INGREDIENT_SALT_i:40
INGREDIENT_EGG_i:20
etc

and query
INGREDIENT_SALT_i:[20 TO *]
or an arbitrary max value, since these are percentages

INGREDIENT_SALT_i:[20 TO 100]


On Fri, May 3, 2019 at 12:01 PM Erick Erickson <[hidden email]>
wrote:

> There is no way to do this with the setup you describe. That is, there’s
> no way to say “only use the third element of a multiValued field”.
>
> What I’d do is index (perhaps in a separate field) with payloads, so you
> have input like SALT|20, then use some of the payload functionality to make
> this happen. See: https://lucidworks.com/2017/09/14/solr-payloads/
>
> There are some other strategies that are simpler, one could index (again,
> perhaps in a separate field) SALT_20. Then you can form filter queries like
> “fq=ingredient:[SALT_20 TO *]. That’s not very flexible and you have to
> normalize (i.e. 1% couldn’t be SALT_1), so “it depends”.
>
> The point is that you have to index cleverly to do what you want.
>
> Best,
> Erick
>
> > On May 3, 2019, at 6:26 AM, Srinivas Kashyap <[hidden email]>
> wrote:
> >
> > Hi,
> >
> > I have indexed data as shown below using DIH:
> >
> > "INGREDIENT_NAME": [
> >          "EGG",
> >          "CANOLA OIL",
> >          "SALT"
> >        ],
> > "INGREDIENT_NO": [
> >          "550",
> >          "297",
> >          "314"
> >        ],
> > "COMPOSITION PERCENTAGE": [
> >          20,
> >          60,
> >          40
> >        ],
> >
> > Similar to this, many other records are also indexed. These are
> multi-valued fields.
> >
> > I have a requirement to search all the records which has ingredient name
> salt and it's composition percentage is more than 20.
> >
> > How do I write a filter query for this?
> >
> > P.S: I should only fetch records, whose Salt Composition percentage is
> more than 20 and not other percentages.
> >
> > Thanks and Regards,
> > Srinivas Kashyap
> > ________________________________
> > DISCLAIMER:
> > E-mails and attachments from Bamboo Rose, LLC are confidential.
> > If you are not the intended recipient, please notify the sender
> immediately by replying to the e-mail, and then delete it without making
> copies or using it in any way.
> > No representation is made that this email or any attachments are free of
> viruses. Virus scanning is recommended and is the responsibility of the
> recipient.
>
>