Skip to content

Instantly share code, notes, and snippets.

@xeraa
Last active May 28, 2018 10:57
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 xeraa/39643754163a414b94e819161e18f208 to your computer and use it in GitHub Desktop.
Save xeraa/39643754163a414b94e819161e18f208 to your computer and use it in GitHub Desktop.
# Data
DELETE latest-connection
POST _bulk
{ "index" : { "_index" : "latest-connection", "_type" : "_doc"} }
{ "client": "10.10.10.10", "version": "1.3", "timestamp": "2018-05-01T12:10:30Z" }
{ "index" : { "_index" : "latest-connection", "_type" : "_doc"} }
{ "client": "20.20.20.20", "version": "1.5", "timestamp": "2018-05-01T12:10:30Z" }
{ "index" : { "_index" : "latest-connection", "_type" : "_doc"} }
{ "client": "10.10.10.10", "version": "1.4", "timestamp": "2018-05-02T12:10:30Z" }
{ "index" : { "_index" : "latest-connection", "_type" : "_doc"} }
{ "client": "10.10.10.10", "version": "1.4", "timestamp": "2018-05-03T12:10:30Z" }
{ "index" : { "_index" : "latest-connection", "_type" : "_doc"} }
{ "client": "30.30.30.30", "version": "1.0", "timestamp": "2018-05-03T10:10:30Z" }
{ "index" : { "_index" : "latest-connection", "_type" : "_doc"} }
{ "client": "30.30.30.30", "version": "1.3", "timestamp": "2018-05-03T12:10:30Z" }
{ "index" : { "_index" : "latest-connection", "_type" : "_doc"} }
{ "client": "20.20.20.20", "version": "1.5", "timestamp": "2018-05-04T12:10:30Z" }
{ "index" : { "_index" : "latest-connection", "_type" : "_doc"} }
{ "client": "20.20.20.20", "version": "1.6", "timestamp": "2018-05-04T12:11:30Z" }
# Simple
GET latest-connection/_search
{
"query": {
"match_all": { }
},
"collapse" : {
"field" : "client.keyword"
},
"sort": [{"timestamp": "desc"}]
}
# Slightly more advanced
GET latest-connection/_search
{
"query": {
"match_all": { }
},
"collapse" : {
"field" : "client.keyword",
"inner_hits": {
"name": "last_connection",
"size": 1,
"sort": [{"timestamp": "desc"}]
}
},
"sort": [{"client.keyword": "asc"}, {"timestamp": "desc"}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment