SOLR: solrQuery.addDateRangeFacet(): Can't add gap %2B1DAY to value for field:
Asked Answered
L

1

8

I am trying to query data (using solr) and get Counts for a Day granularity.

I am having a problem with the below piece of code:

    solrQuery.addDateRangeFacet("startTimeISO", date1.toDate(), date2.toDate(), "%2B1DAY");

    solrQuery.setQuery(queryString);

    QueryResponse response = null;
    try {
        response = solrClient.getSolrServer(getCollectionName(Constants.WebPeerAnomaliesModelTuple()._1())).query(solrQuery);
    } catch (Exception exp) {
        LOGGER.error("Failed to get facet results: ", exp);
    }

The error I am getting here is:

"Can't add gap %2B1DAY to value Fri Nov 14 06:37:30 PST 2014 for field: startTimeISO"

Can somebody help me here what is the issue?

I am not sure why "%2B1DAY" would fail. I am getting the correct result when I do the same from the browser. If I query the below from url, it works: /select?facet=true&facet.date=startTimeISO&facet.date.start=NOW/DAY-30DAYS&facet.date.end=NOW/DAY%2B1DAY&facet.date.gap=%2B1DAY

Apologies if I am asking a trivial question. I am still trying to debug this. Any pointers will be helpful. Thanks.

UPDATE: SOLUTION:

I was able to debug this and find out why I am getting this error.

In my Java code, instead of "%2B1DAY", I should have added "+1Day". Querying through browser worked because + is %2B (url encoding) Sorry for the silly question. Hope it helps someone. :)

Linebacker answered 20/12, 2014 at 8:4 Comment(2)
Could you please add your solution as an answer? I came to this page several times and (my fault) didn't read it because it was unanswered. However, it is super helpful!Springfield
@JohnPavek doneLinebacker
L
4

Adding my solution as answer: As one commenter mentioned, there is a chance people miss the update I have provided on the question.

SOLUTION:

I was able to debug this and find out why I am getting this error.

In my Java code, instead of "%2B1DAY", I should have added "+1Day". Querying through browser worked because + is %2B (url encoding) Sorry for the silly question. Hope it helps someone. :)

Linebacker answered 7/5, 2018 at 21:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.