Skip to content

Instantly share code, notes, and snippets.

@ejain
Created May 3, 2013 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejain/5507570 to your computer and use it in GitHub Desktop.
Save ejain/5507570 to your computer and use it in GitHub Desktop.
Example request and (correct) response when using a script terms facet in elasticsearch 0.20.6 (+ lang-javascript 1.2.0).
{
"query" : {
"match_all" : { }
},
"facets" : {
"lt322cf7ts" : {
"terms" : {
"size" : 31,
"script" : "t=doc['timestamp'].date;t.addMillis(-28800000);v=t.getHourOfDay();v",
"lang" : "js"
}
}
}
}
--
{
"took" : 261,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ {
"_index" : "4oerq1pia8",
"_type" : "event",
"_id" : "ci7842krt3",
"_score" : 1.0, "_source" : {"timestamp":"2012-11-30T15:00:00.000-08:00","@id":"ci7842krt3"}
}, {
"_index" : "4oerq1pia8",
"_type" : "event",
"_id" : "ls41ppd5us",
"_score" : 1.0, "_source" : {"timestamp":"2012-12-11T15:00:00.000Z","@id":"ls41ppd5us"}
}, {
"_index" : "4oerq1pia8",
"_type" : "event",
"_id" : "plc3s8h4rq",
"_score" : 1.0, "_source" : {"timestamp":"2012-12-02T15:00:00.000-08:00","@id":"plc3s8h4rq"}
} ]
},
"facets" : {
"lt322cf7ts" : {
"_type" : "terms",
"missing" : 0,
"total" : 3,
"other" : 0,
"terms" : [ {
"term" : "15",
"count" : 2
}, {
"term" : "7",
"count" : 1
} ]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment