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 Michael Joyner <mi...@newsrx.com> on 2016/11/21 20:42:31 UTC
How to get "max(date)" from a facet field? (Solr 6.3)
Help,
(Solr 6.3)
Trying to do a "sub-facet" using the new json faceting API, but can't
seem to figure out how to get the "max" date in the subfacet?
I've tried a couple of different ways:
== query ==
json.facet={
code_s:{
limit:-1,
type:terms,field:code_s,facet:{
issuedate_tdt:"max(issuedate_tdt)"
}
}
}
== partial response ==
facets":{
"count":1310359,
"code_s":{
"buckets":[{
"val":"5W",
"count":255437,
"issuedate_tdt":1.4794452E12},
{
"val":"LS",
"count":201407,
"issuedate_tdt":1.479186E12},
-- the date values seem to come back out as longs converted to
float/double which are then truncated and put into scientific notation? --
== query that barfs with fatal exception ==
json.facet={
code_s:{
limit:-1,
type:terms,
field:code_s,
facet:{
issuedate_tdt:{
type:terms,
field:issuedate_tdt,
sort:{val:desc},
limit:1
}
}
}
}
== barfed response ==
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException"],
"msg":"org.apache.solr.client.solrj.SolrServerException: No live
SolrServers available to handle this
request:[http://solr-0001:8983/solr/newsletters_shard1_replica0,
http://solr-0002:8983/solr/newsletters_shard1_replica1,
http://solr-0003:8983/solr/newsletters_shard2_replica0]",
"trace":"org.apache.solr.common.SolrException:
org.apache.solr.client.solrj.SolrServerException: No live SolrServers
available to handle this
request:[http://solr-0001:8983/solr/newsletters_shard1_replica0,
http://solr-0002:8983/solr/newsletters_shard1_replica1,
http://solr-0003:8983/solr/newsletters_shard2_replica0]\n\tat
...<snip>...
org.apache.solr.client.solrj.impl.LBHttpSolrClient.doRequest(LBHttpSolrClient.java:435)\n\tat
org.apache.solr.client.solrj.impl.LBHttpSolrClient.request(LBHttpSolrClient.java:387)\n\t...
9 more\n",
"code":500}
== query with null pointer barfed response ==
json.facet={
code_s:{
limit:-1,
type:terms,
field:code_s,
facet:{
issuedate_tdt:{
type:terms,
field:issuedate_tdt,
sort:{issuedate_tdt:desc},
limit:1
}
}
}
}
== response with NPE ==
"metadata":[
"error-class","org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException",
"root-error-class","org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException"],
"msg":"Error from server at
http://solr-0003:8983/solr/newsletters_shard2_replica0:
java.lang.NullPointerException\n",
"trace":"org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException:
Error from server at
http://solr-0003:8983/solr/newsletters_shard2_replica0:
java.lang.NullPointerException\n\n\tat
org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:593)\n\tat
org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:262)\n\tat
org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:251)\n\tat
org.apache.solr.client.solrj.SolrClient.request(SolrClient.java:1219)\n\tat
org.apache.solr.handler.component.HttpShardHandler.lambda$submit$0(HttpShardHandler.java:195)\n\tat
java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)\n\tat
java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat
org.apache.solr.common.util.ExecutorUtil$MDCAwareThreadPoolExecutor.lambda$execute$0(ExecutorUtil.java:229)\n\tat
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat
java.lang.Thread.run(Thread.java:745)\n",
"code":500}
Any thoughts on how I can accomplish getting the max date per code where
each code has many dates?
Re: How to get "max(date)" from a facet field? (Solr 6.3)
Posted by Yonik Seeley <ys...@gmail.com>.
On Mon, Nov 21, 2016 at 3:42 PM, Michael Joyner <mi...@newsrx.com> wrote:
> Help,
>
> (Solr 6.3)
>
> Trying to do a "sub-facet" using the new json faceting API, but can't seem
> to figure out how to get the "max" date in the subfacet?
>
> I've tried a couple of different ways:
>
> == query ==
>
> json.facet={
> code_s:{
> limit:-1,
> type:terms,field:code_s,facet:{
> issuedate_tdt:"max(issuedate_tdt)"
> }
> }
> }
>
> == partial response ==
>
> facets":{
> "count":1310359,
> "code_s":{
> "buckets":[{
> "val":"5W",
> "count":255437,
> "issuedate_tdt":1.4794452E12},
> {
> "val":"LS",
> "count":201407,
> "issuedate_tdt":1.479186E12},
>
> -- the date values seem to come back out as longs converted to float/double
> which are then truncated and put into scientific notation? --
Hmmm, yeah... min/max are currently only implemented in terms of
function queries (so you can do stuff like max(add(field1,field2)))
The downside is that by default function queries use float/double, so
we need to add support for other types.
As a temporary workaround, the ms() function subtracts two dates and
gives the result in milliseconds, and may work better for losing less
information.
min(ms(NOW, issuedate_tdt))
-Yonik
Re: How to get "max(date)" from a facet field? (Solr 6.3)
Posted by Michael Joyner <mi...@newsrx.com>.
I think I figured out a very hacky "work around" - does this look like
it will work consistently?
json.facet={
code_s:{
limit:-1,
type:terms,
field:code_s,
facet:{
issuedate_tdt:{
type:terms,
field:issuedate_tdt,
sort:{idate:desc},
limit:1,
/** convert date to a number for sorting, as the date
is being faceted against itself, it should have
only one possible facet value */
facet:{
idate:"max(issuedate_tdt)"
}
}
}
}
}
On 11/21/2016 03:42 PM, Michael Joyner wrote:
> Help,
>
> (Solr 6.3)
>
> Trying to do a "sub-facet" using the new json faceting API, but can't
> seem to figure out how to get the "max" date in the subfacet?
>
> I've tried a couple of different ways:
>