Skip to content

Instantly share code, notes, and snippets.

@yogesum
Created September 22, 2016 06:25
Show Gist options
  • Select an option

  • Save yogesum/1fdbe3514d2a3d5ec698208e7950d573 to your computer and use it in GitHub Desktop.

Select an option

Save yogesum/1fdbe3514d2a3d5ec698208e7950d573 to your computer and use it in GitHub Desktop.

Sample Data

[
  { id: 110140,
    last_visit: '2016-07-22T07:25:36Z',
    first_visit: '2016-06-23T04:01:54Z'},
  { id: 110427,
    last_visit: '2016-07-25T12:35:26Z',
    first_visit: '2016-06-23T04:02:02Z'},
  { id: 110449,
    first_visit: '2016-06-23T04:02:06Z'} ]

SOLR QUERY Get average span of time user was with us if last visit not defined take last visit timestamp as current time(NOW)

curl http://localhost:8983/solr/samples/query -d 'q=id:(110140 110427 110449)&rows=0&$last_visit_fix=def(last_visit, NOW)&
json.facet={
  awfspeed: {
    query: {
      q: 'first_visit:*',
      facet: {
        average: 'avg(div(ms($last_visit_fix, first_visit), 86400000))',
      }
    }
  }
}
'

RESULT INTO 91

But it should be 50

Facet query always taking $last_visit_fix value to Current Time

But i need to take it last_visit value if field exist else take Current Time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment