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 RAUNAK AGRAWAL <ag...@gmail.com> on 2018/01/04 15:02:06 UTC

Json Facet Query Stripping Field Name with Hyphen

Hi Guys,

I am facing issue where I am trying to follow the JSON facet API. I have
data in my collection and field names are like "week_0", "week_-1" which
means current week and previous week respectively.

When I am querying for week_0 summation using the following query I am able
to get the result.

http://localhost:8983/solr/collection1/query?q=*:*&json.facet={week_0_sum:'sum(week_0)'}&rows=0


But when I am trying to do the same for any field "week_-*", it is break.

For example when I am trying:
http://localhost:8983/solr/collection1/query?q=*:*&json.facet={week_-91_sum:%27sum(week_-91)%27}&rows=0


I am getting the exception as* "msg": "undefined field: \"week_\"''*


That means solr is stripping field name after hyphen (-). Is there
workaround to fix this. I tried adding escape character (\) but it is of no
help.

With escape:
http://localhost:8983/solr/collection1/query?q=*:*&json.facet={week_-91_sum:%27sum(week_\-91)%27}&rows=0


Please help me regarding this.

Thanks

Re: Json Facet Query Stripping Field Name with Hyphen

Posted by RAUNAK AGRAWAL <ag...@gmail.com>.
Hi Erick/Yonik,

Thank you guys. I am going to rename the fields.

On Thu, Jan 4, 2018 at 10:04 PM, Yonik Seeley <ys...@gmail.com> wrote:

> The JSON Facet API uses the function query parser for something like
> sum(week_-91) so you'll probably have problems with any function that
> uses these fields as well.
> As Erick says, you're better off renaming the fields.  There is a
> workaround for wonky field names via the "field" function:
> sum(field(week_-91))
>
> -Yonik
>
>
> On Thu, Jan 4, 2018 at 10:02 AM, RAUNAK AGRAWAL
> <ag...@gmail.com> wrote:
> > Hi Guys,
> >
> > I am facing issue where I am trying to follow the JSON facet API. I have
> > data in my collection and field names are like "week_0", "week_-1" which
> > means current week and previous week respectively.
> >
> > When I am querying for week_0 summation using the following query I am
> able
> > to get the result.
> >
> > http://localhost:8983/solr/collection1/query?q=*:*&json.
> facet={week_0_sum:'sum(week_0)'}&rows=0
> >
> >
> > But when I am trying to do the same for any field "week_-*", it is break.
> >
> > For example when I am trying:
> > http://localhost:8983/solr/collection1/query?q=*:*&json.
> facet={week_-91_sum:%27sum(week_-91)%27}&rows=0
> >
> >
> > I am getting the exception as* "msg": "undefined field: \"week_\"''*
> >
> >
> > That means solr is stripping field name after hyphen (-). Is there
> > workaround to fix this. I tried adding escape character (\) but it is of
> no
> > help.
> >
> > With escape:
> > http://localhost:8983/solr/collection1/query?q=*:*&json.
> facet={week_-91_sum:%27sum(week_\-91)%27}&rows=0
> >
> >
> > Please help me regarding this.
> >
> > Thanks
>

Re: Json Facet Query Stripping Field Name with Hyphen

Posted by Yonik Seeley <ys...@gmail.com>.
The JSON Facet API uses the function query parser for something like
sum(week_-91) so you'll probably have problems with any function that
uses these fields as well.
As Erick says, you're better off renaming the fields.  There is a
workaround for wonky field names via the "field" function:
sum(field(week_-91))

-Yonik


On Thu, Jan 4, 2018 at 10:02 AM, RAUNAK AGRAWAL
<ag...@gmail.com> wrote:
> Hi Guys,
>
> I am facing issue where I am trying to follow the JSON facet API. I have
> data in my collection and field names are like "week_0", "week_-1" which
> means current week and previous week respectively.
>
> When I am querying for week_0 summation using the following query I am able
> to get the result.
>
> http://localhost:8983/solr/collection1/query?q=*:*&json.facet={week_0_sum:'sum(week_0)'}&rows=0
>
>
> But when I am trying to do the same for any field "week_-*", it is break.
>
> For example when I am trying:
> http://localhost:8983/solr/collection1/query?q=*:*&json.facet={week_-91_sum:%27sum(week_-91)%27}&rows=0
>
>
> I am getting the exception as* "msg": "undefined field: \"week_\"''*
>
>
> That means solr is stripping field name after hyphen (-). Is there
> workaround to fix this. I tried adding escape character (\) but it is of no
> help.
>
> With escape:
> http://localhost:8983/solr/collection1/query?q=*:*&json.facet={week_-91_sum:%27sum(week_\-91)%27}&rows=0
>
>
> Please help me regarding this.
>
> Thanks

Re: Json Facet Query Stripping Field Name with Hyphen

Posted by Erick Erickson <er...@gmail.com>.
From the ref guide:

"Field names should consist of alphanumeric or underscore characters
only and not start with a digit."

While field naming isn't strictly enforced, having field names like
week_-1 is also not guaranteed to be supported. You should change your
field name.

I raised SOLR-11819 for one place I see in the ref guide where a
hyphen is used, if you see any others please add the location to the
JIRA (SOLR-11819).

Best,
Erick

On Thu, Jan 4, 2018 at 7:02 AM, RAUNAK AGRAWAL <ag...@gmail.com> wrote:
> Hi Guys,
>
> I am facing issue where I am trying to follow the JSON facet API. I have
> data in my collection and field names are like "week_0", "week_-1" which
> means current week and previous week respectively.
>
> When I am querying for week_0 summation using the following query I am able
> to get the result.
>
> http://localhost:8983/solr/collection1/query?q=*:*&json.facet={week_0_sum:'sum(week_0)'}&rows=0
>
>
> But when I am trying to do the same for any field "week_-*", it is break.
>
> For example when I am trying:
> http://localhost:8983/solr/collection1/query?q=*:*&json.facet={week_-91_sum:%27sum(week_-91)%27}&rows=0
>
>
> I am getting the exception as* "msg": "undefined field: \"week_\"''*
>
>
> That means solr is stripping field name after hyphen (-). Is there
> workaround to fix this. I tried adding escape character (\) but it is of no
> help.
>
> With escape:
> http://localhost:8983/solr/collection1/query?q=*:*&json.facet={week_-91_sum:%27sum(week_\-91)%27}&rows=0
>
>
> Please help me regarding this.
>
> Thanks