I have multiple solr documents in the following form
{ requests : [23], timestamp : [1562146437780] }
i have to get sum of requests in intervals of timestamp.
I tried using facets but couldn't figure out how to use on two fields
i did try this. but was giving me count of documents in the timestamp interval.
query.addNumericRangeFacet(TIMESTAMP, startTime, endTime, gap);
Thanks in advance
You can implement this by using the JSON facet API for range facets. These will allow you to give a sub facet that works with the domain (i.e. the documents in the bucket) from the facet above.
You start by creating a range facet:
RangeFacetMap rangeFacet = new RangeFacetMap(TIMESTAMP, startTime, endTime, gap);
Then you add a sub facet that invokes a sum:
rangeFacet.withStatSubFacet("requests_sum", "sum(requests)")
You send this request to Solr by using:
final JsonQueryRequest request = new JsonQueryRequest()
.setQuery("*:*")
.withFacet("timestamps", rangeFacet);
QueryResponse queryResponse = request.process(solrClient, COLLECTION_NAME);
I don't have an instance or documents to test with right now, but this is built from the information under Nester Facet Example in the reference guide.
Can i use SolrQuery and make this same request?
Getting exception org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at localhost:8983/solr/Requests: can not use FieldCache on multivalued field: requests
Yes, you're going to have to make that field singlevalued. Are you using it in a multivalued fashion? Doesn't seem like that from your post above.
it will be a multivalued field
Index the sum of the field's values to a single field, then use that for summing up the requests.