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 Gintautas Sulskus <gi...@gmail.com> on 2016/11/14 18:29:13 UTC

Filtering a field when some of the documents don't have the value

Hi,

I have an index with two fields "name" and "population". Some of the
documents have the "population" field empty.

I would like to search for a value X in field "name" with the following
condition:
1. if the field is empty - return results for
name:X
2. else set the minimum value for the "population" field to 10:
 name:X AND population: [10 TO *]
The population field should not influence the score.

Could you please help me out with the query construction?
I have tried conditional statements with exists(), but it seems it does not
suit the case.

Thanks,
Gin

Re: Filtering a field when some of the documents don't have the value

Posted by Gintautas Sulskus <gi...@gmail.com>.
Thanks Erick, it works exactly as required!

Gintas

On Mon, Nov 14, 2016 at 7:02 PM, Erick Erickson <er...@gmail.com>
wrote:

> You want something like:
> name:x&fq=population:[10 TO *] OR (*:* -population:*:*)
>
> Best,
> Erick
>
> On Mon, Nov 14, 2016 at 10:29 AM, Gintautas Sulskus
> <gi...@gmail.com> wrote:
> > Hi,
> >
> > I have an index with two fields "name" and "population". Some of the
> > documents have the "population" field empty.
> >
> > I would like to search for a value X in field "name" with the following
> > condition:
> > 1. if the field is empty - return results for
> > name:X
> > 2. else set the minimum value for the "population" field to 10:
> >  name:X AND population: [10 TO *]
> > The population field should not influence the score.
> >
> > Could you please help me out with the query construction?
> > I have tried conditional statements with exists(), but it seems it does
> not
> > suit the case.
> >
> > Thanks,
> > Gin
>

Re: Filtering a field when some of the documents don't have the value

Posted by Erick Erickson <er...@gmail.com>.
You want something like:
name:x&fq=population:[10 TO *] OR (*:* -population:*:*)

Best,
Erick

On Mon, Nov 14, 2016 at 10:29 AM, Gintautas Sulskus
<gi...@gmail.com> wrote:
> Hi,
>
> I have an index with two fields "name" and "population". Some of the
> documents have the "population" field empty.
>
> I would like to search for a value X in field "name" with the following
> condition:
> 1. if the field is empty - return results for
> name:X
> 2. else set the minimum value for the "population" field to 10:
>  name:X AND population: [10 TO *]
> The population field should not influence the score.
>
> Could you please help me out with the query construction?
> I have tried conditional statements with exists(), but it seems it does not
> suit the case.
>
> Thanks,
> Gin