Skip to content

Instantly share code, notes, and snippets.

@bmichalski
Last active September 28, 2015 18:44
Show Gist options
  • Save bmichalski/cda72240d44ca55ad50c to your computer and use it in GitHub Desktop.
Save bmichalski/cda72240d44ca55ad50c to your computer and use it in GitHub Desktop.
ElasticSearch test expression script with aggregation and sub aggregations
{
"color": "black",
"testVal": 25,
"testQuantity": 5
}
{
"mappings" : {
"test" : {
"properties" : {
"color": { "type" : "string", "index" : "not_analyzed" },
"testVal" : { "type" : "long", "index" : "not_analyzed" },
"testQuantity" : { "type" : "long", "index" : "not_analyzed" }
}
}
}
}
{
"aggs": {
"testColor": {
"terms": {
"field": "color"
},
"aggs": {
"testAgg": {
"sum": {
"lang": "expression",
"script": "doc['testVal'].value * doc['testQuantity'].value"
}
}
}
}
}
}
mapping:
http://localhost:9200/test/test/ PUT
create_entries:
http://localhost:9200/test/test/ POST
query:
http://localhost:9200/test/test/_search?search_type=count POST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment