You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Darin Amos <da...@gmail.com> on 2014/12/11 17:48:21 UTC
Help with a Join Query
Hello,
I am trying to execute a join query that I am not 100% sure how to execute. Lets say I have a bunch of parent and child documents and every one of my child documents has a single value field “color”.
If I want to search all parents that have a “red” child, tis is very easy:
{!join from=parent to=id}color:red
However, if I want to return only parents that have both a red AND a blue item it gets tricky.
This query would return parents that have red OR blue
{!join from=parent to=id}color:red OR color:blue
And this query would return nothing since no child had both colors.
{!join from=parent to=id}color:red AND color:blue
Any suggestions? My thinking is I might require some kind of custom query.
Thanks!
Darin
RE: Help with a Join Query
Posted by "EXTERNAL Taminidi Ravi (ETI, Automotive-Service-Solutions)" <ex...@us.bosch.com>.
May be you can try using AND condition in the single join something like
q={!join from=parent to=id}(Id:xxx AND (Color:red OR Color:Blue)), I don't think this will give bigger performance issue.
Thanks
Ravi
-----Original Message-----
From: Darin Amos [mailto:darincs@gmail.com]
Sent: Thursday, December 11, 2014 1:23 PM
To: solr-user@lucene.apache.org
Subject: Re: Help with a Join Query
Thanks,
That looks like a viable option, I could do something like the following:
q={!join from=parent to=id}<my main search term query> &fq={!join from=parent to=id}color:red &fq={!join from=parent to=id}color:blue
With all these joins happening like this, what kind of performance concern is this? I would guess this would start to cause a lot of work.
Thanks
Darin
> On Dec 11, 2014, at 1:04 PM, Kydryavtsev Andrey <we...@yandex.ru> wrote:
>
> How about something like
>
> ({!join from=parent to=id}color:red) AND ({!join from=parent to=id}color:blue) ?
>
> 11.12.2014, 19:48, "Darin Amos" <da...@gmail.com>:
>> Hello,
>>
>> I am trying to execute a join query that I am not 100% sure how to execute. Lets say I have a bunch of parent and child documents and every one of my child documents has a single value field “color”.
>>
>> If I want to search all parents that have a “red” child, tis is very easy:
>>
>> {!join from=parent to=id}color:red
>>
>> However, if I want to return only parents that have both a red AND a blue item it gets tricky.
>>
>> This query would return parents that have red OR blue {!join
>> from=parent to=id}color:red OR color:blue
>>
>> And this query would return nothing since no child had both colors.
>> {!join from=parent to=id}color:red AND color:blue
>>
>> Any suggestions? My thinking is I might require some kind of custom query.
>>
>> Thanks!
>>
>> Darin
Re: Help with a Join Query
Posted by Kydryavtsev Andrey <we...@yandex.ru>.
According to may experience, "query time join" has relatively poor performance. If you can cache this joins effectively (not so many unique color values in requests, cache doesn't invalidate) - it's ok. If not, it may be interesting to try "block join" instead - http://blog.griddynamics.com/2013/09/solr-block-join-support.html
11.12.2014, 21:40, "Kydryavtsev Andrey" <we...@yandex.ru>:
> 11.12.2014, 21:24, "Darin Amos" <da...@gmail.com>:
>> Thanks,
>>
>> That looks like a viable option, I could do something like the following:
>>
>> q={!join from=parent to=id}<my main search term query>
>> &fq={!join from=parent to=id}color:red
>> &fq={!join from=parent to=id}color:blue
>>
>> With all these joins happening like this, what kind of performance concern is this? I would guess this would start to cause a lot of work.
>>
>> Thanks
>>
>> Darin
>>> On Dec 11, 2014, at 1:04 PM, Kydryavtsev Andrey <we...@yandex.ru> wrote:
>>>
>>> How about something like
>>>
>>> ({!join from=parent to=id}color:red) AND ({!join from=parent to=id}color:blue) ?
>>>
>>> 11.12.2014, 19:48, "Darin Amos" <da...@gmail.com>:
>>>> Hello,
>>>>
>>>> I am trying to execute a join query that I am not 100% sure how to execute. Lets say I have a bunch of parent and child documents and every one of my child documents has a single value field “color”.
>>>>
>>>> If I want to search all parents that have a “red” child, tis is very easy:
>>>>
>>>> {!join from=parent to=id}color:red
>>>>
>>>> However, if I want to return only parents that have both a red AND a blue item it gets tricky.
>>>>
>>>> This query would return parents that have red OR blue
>>>> {!join from=parent to=id}color:red OR color:blue
>>>>
>>>> And this query would return nothing since no child had both colors.
>>>> {!join from=parent to=id}color:red AND color:blue
>>>>
>>>> Any suggestions? My thinking is I might require some kind of custom query.
>>>>
>>>> Thanks!
>>>>
>>>> Darin
Re: Help with a Join Query
Posted by Kydryavtsev Andrey <we...@yandex.ru>.
11.12.2014, 21:24, "Darin Amos" <da...@gmail.com>:
> Thanks,
>
> That looks like a viable option, I could do something like the following:
>
> q={!join from=parent to=id}<my main search term query>
> &fq={!join from=parent to=id}color:red
> &fq={!join from=parent to=id}color:blue
>
> With all these joins happening like this, what kind of performance concern is this? I would guess this would start to cause a lot of work.
>
> Thanks
>
> Darin
>> On Dec 11, 2014, at 1:04 PM, Kydryavtsev Andrey <we...@yandex.ru> wrote:
>>
>> How about something like
>>
>> ({!join from=parent to=id}color:red) AND ({!join from=parent to=id}color:blue) ?
>>
>> 11.12.2014, 19:48, "Darin Amos" <da...@gmail.com>:
>>> Hello,
>>>
>>> I am trying to execute a join query that I am not 100% sure how to execute. Lets say I have a bunch of parent and child documents and every one of my child documents has a single value field “color”.
>>>
>>> If I want to search all parents that have a “red” child, tis is very easy:
>>>
>>> {!join from=parent to=id}color:red
>>>
>>> However, if I want to return only parents that have both a red AND a blue item it gets tricky.
>>>
>>> This query would return parents that have red OR blue
>>> {!join from=parent to=id}color:red OR color:blue
>>>
>>> And this query would return nothing since no child had both colors.
>>> {!join from=parent to=id}color:red AND color:blue
>>>
>>> Any suggestions? My thinking is I might require some kind of custom query.
>>>
>>> Thanks!
>>>
>>> Darin
Re: Help with a Join Query
Posted by Darin Amos <da...@gmail.com>.
Thanks,
That looks like a viable option, I could do something like the following:
q={!join from=parent to=id}<my main search term query>
&fq={!join from=parent to=id}color:red
&fq={!join from=parent to=id}color:blue
With all these joins happening like this, what kind of performance concern is this? I would guess this would start to cause a lot of work.
Thanks
Darin
> On Dec 11, 2014, at 1:04 PM, Kydryavtsev Andrey <we...@yandex.ru> wrote:
>
> How about something like
>
> ({!join from=parent to=id}color:red) AND ({!join from=parent to=id}color:blue) ?
>
> 11.12.2014, 19:48, "Darin Amos" <da...@gmail.com>:
>> Hello,
>>
>> I am trying to execute a join query that I am not 100% sure how to execute. Lets say I have a bunch of parent and child documents and every one of my child documents has a single value field “color”.
>>
>> If I want to search all parents that have a “red” child, tis is very easy:
>>
>> {!join from=parent to=id}color:red
>>
>> However, if I want to return only parents that have both a red AND a blue item it gets tricky.
>>
>> This query would return parents that have red OR blue
>> {!join from=parent to=id}color:red OR color:blue
>>
>> And this query would return nothing since no child had both colors.
>> {!join from=parent to=id}color:red AND color:blue
>>
>> Any suggestions? My thinking is I might require some kind of custom query.
>>
>> Thanks!
>>
>> Darin
Re: Help with a Join Query
Posted by Kydryavtsev Andrey <we...@yandex.ru>.
How about something like
({!join from=parent to=id}color:red) AND ({!join from=parent to=id}color:blue) ?
11.12.2014, 19:48, "Darin Amos" <da...@gmail.com>:
> Hello,
>
> I am trying to execute a join query that I am not 100% sure how to execute. Lets say I have a bunch of parent and child documents and every one of my child documents has a single value field “color”.
>
> If I want to search all parents that have a “red” child, tis is very easy:
>
> {!join from=parent to=id}color:red
>
> However, if I want to return only parents that have both a red AND a blue item it gets tricky.
>
> This query would return parents that have red OR blue
> {!join from=parent to=id}color:red OR color:blue
>
> And this query would return nothing since no child had both colors.
> {!join from=parent to=id}color:red AND color:blue
>
> Any suggestions? My thinking is I might require some kind of custom query.
>
> Thanks!
>
> Darin