Skip to content

Instantly share code, notes, and snippets.

@duydo
Created December 3, 2014 10:52
Show Gist options
  • Save duydo/844d35d740833fb816a1 to your computer and use it in GitHub Desktop.
Save duydo/844d35d740833fb816a1 to your computer and use it in GitHub Desktop.
elasticsearch aggs top_hits
curl -XGET "http://ext-es2.ssh.sentifi.com:9200/analytic/relevant_document/_search" -d'
{
"size": 0,
"query": {
"range": {
"date": {
"from": "now-1h"
}
}
},
"aggs": {
"0": {
"filter": {
"bool": {
"must": [
{
"exists": {
"field": "tag"
}
},
{
"script": {
"script": "doc[\"tag\"].values.length > 1"
}
}
]
}
},
"aggs": {
"1": {
"terms": {
"size": 0,
"lang": "groovy",
"script": "doc[\"tag\"].values.join(\"-\")"
},
"aggs": {
"2": {
"top_hits": {
"sort": [
{
"date": {
"order": "desc"
}
}
],
"size": 5,
"_source": {
"include": [
"text"
]
}
}
}
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment