if exists in an fq

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

if exists in an fq

xdzgor1
Hi

I want to formulate an fq which filters on fields depending on what fields exist in each document.

For example:
if the document has a "field1" then use "field1:[1 TO 100]";
but if there is no "field1", then check if there is a "field2";
if there is a "field2" then use "field2:[1 TO 100];
but if there is no "field2", then use "field3:[1 TO 100].

Something like:
?q=*:*&fq=if(exists(field1),field1:[1 TO 100],if(exists(field2),field2:[1 TO 100], field3:[1 TO 100]))


But is this does not work.
Is it even possible?

Thanks,
Peter
Reply | Threaded
Open this post in threaded view
|

Re: if exists in an fq

Walter Underwood
How about doing that logic at index time? Make a new field, then copy into it with that logic using an update request processor.

wunder
Walter Underwood
[hidden email]
http://observer.wunderwood.org/  (my blog)


> On Sep 12, 2017, at 2:05 PM, Peter Kirk <[hidden email]> wrote:
>
> Hi
>
> I want to formulate an fq which filters on fields depending on what fields exist in each document.
>
> For example:
> if the document has a "field1" then use "field1:[1 TO 100]";
> but if there is no "field1", then check if there is a "field2";
> if there is a "field2" then use "field2:[1 TO 100];
> but if there is no "field2", then use "field3:[1 TO 100].
>
> Something like:
> ?q=*:*&fq=if(exists(field1),field1:[1 TO 100],if(exists(field2),field2:[1 TO 100], field3:[1 TO 100]))
>
>
> But is this does not work.
> Is it even possible?
>
> Thanks,
> Peter

Reply | Threaded
Open this post in threaded view
|

Re: if exists in an fq

Vincenzo D'Amore
Yes, would be easier and performances wise if you do this at index time.
In the other hand, if you can't, had you tried nested query parser?

https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-NestedQueryParser

Ciao,
Vincenzo

--
mobile: 3498513251
skype: free.dev

> On 13 Sep 2017, at 17:20, Walter Underwood <[hidden email]> wrote:
>
> How about doing that logic at index time? Make a new field, then copy into it with that logic using an update request processor.
>
> wunder
> Walter Underwood
> [hidden email]
> http://observer.wunderwood.org/  (my blog)
>
>
>> On Sep 12, 2017, at 2:05 PM, Peter Kirk <[hidden email]> wrote:
>>
>> Hi
>>
>> I want to formulate an fq which filters on fields depending on what fields exist in each document.
>>
>> For example:
>> if the document has a "field1" then use "field1:[1 TO 100]";
>> but if there is no "field1", then check if there is a "field2";
>> if there is a "field2" then use "field2:[1 TO 100];
>> but if there is no "field2", then use "field3:[1 TO 100].
>>
>> Something like:
>> ?q=*:*&fq=if(exists(field1),field1:[1 TO 100],if(exists(field2),field2:[1 TO 100], field3:[1 TO 100]))
>>
>>
>> But is this does not work.
>> Is it even possible?
>>
>> Thanks,
>> Peter
>