|
@@ -75,8 +75,8 @@ For instance the following document:
|
|
|
[source,js]
|
|
|
--------------------------------------------------
|
|
|
{
|
|
|
- "keyword": ["foo", "bar"],
|
|
|
- "number": [23, 65, 76]
|
|
|
+ "keyword": ["foo", "bar"],
|
|
|
+ "number": [23, 65, 76]
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
// NOTCONSOLE
|
|
@@ -117,16 +117,16 @@ Example:
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "product": { "terms" : { "field": "product" } } }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "product": { "terms": { "field": "product" } } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -136,25 +136,25 @@ Like the `terms` aggregation it is also possible to use a script to create the v
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- {
|
|
|
- "product": {
|
|
|
- "terms" : {
|
|
|
- "script" : {
|
|
|
- "source": "doc['product'].value",
|
|
|
- "lang": "painless"
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ]
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ {
|
|
|
+ "product": {
|
|
|
+ "terms": {
|
|
|
+ "script": {
|
|
|
+ "source": "doc['product'].value",
|
|
|
+ "lang": "painless"
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -172,16 +172,16 @@ Example:
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "histo": { "histogram" : { "field": "price", "interval": 5 } } }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "histo": { "histogram": { "field": "price", "interval": 5 } } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -191,26 +191,26 @@ The values are built from a numeric field or a script that return numerical valu
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- {
|
|
|
- "histo": {
|
|
|
- "histogram" : {
|
|
|
- "interval": 5,
|
|
|
- "script" : {
|
|
|
- "source": "doc['price'].value",
|
|
|
- "lang": "painless"
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ]
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ {
|
|
|
+ "histo": {
|
|
|
+ "histogram": {
|
|
|
+ "interval": 5,
|
|
|
+ "script": {
|
|
|
+ "source": "doc['price'].value",
|
|
|
+ "lang": "painless"
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -224,16 +224,16 @@ is specified by date/time expression:
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "date": { "date_histogram" : { "field": "timestamp", "calendar_interval": "1d" } } }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d" } } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -254,24 +254,24 @@ the format specified with the format parameter:
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- {
|
|
|
- "date": {
|
|
|
- "date_histogram" : {
|
|
|
- "field": "timestamp",
|
|
|
- "calendar_interval": "1d",
|
|
|
- "format": "yyyy-MM-dd" <1>
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ]
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ {
|
|
|
+ "date": {
|
|
|
+ "date_histogram": {
|
|
|
+ "field": "timestamp",
|
|
|
+ "calendar_interval": "1d",
|
|
|
+ "format": "yyyy-MM-dd" <1>
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -367,16 +367,16 @@ to the user-specified precision.
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "tile": { "geotile_grid" : { "field": "location", "precision": 8 } } }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "tile": { "geotile_grid": { "field": "location", "precision": 8 } } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -400,27 +400,27 @@ precision tiling.
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- {
|
|
|
- "tile": {
|
|
|
- "geotile_grid" : {
|
|
|
- "field" : "location",
|
|
|
- "precision" : 22,
|
|
|
- "bounds": {
|
|
|
- "top_left" : "52.4, 4.9",
|
|
|
- "bottom_right" : "52.3, 5.0"
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ]
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ {
|
|
|
+ "tile": {
|
|
|
+ "geotile_grid": {
|
|
|
+ "field": "location",
|
|
|
+ "precision": 22,
|
|
|
+ "bounds": {
|
|
|
+ "top_left": "52.4, 4.9",
|
|
|
+ "bottom_right": "52.3, 5.0"
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -434,17 +434,17 @@ For example:
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d" } } },
|
|
|
- { "product": { "terms": {"field": "product" } } }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d" } } },
|
|
|
+ { "product": { "terms": { "field": "product" } } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -457,18 +457,18 @@ in the composite buckets.
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "shop": { "terms": {"field": "shop" } } },
|
|
|
- { "product": { "terms": { "field": "product" } } },
|
|
|
- { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d" } } }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "shop": { "terms": { "field": "shop" } } },
|
|
|
+ { "product": { "terms": { "field": "product" } } },
|
|
|
+ { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d" } } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -487,17 +487,17 @@ For example:
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } },
|
|
|
- { "product": { "terms": {"field": "product", "order": "asc" } } }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } },
|
|
|
+ { "product": { "terms": { "field": "product", "order": "asc" } } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -514,16 +514,16 @@ It is possible to include them in the response by setting `missing_bucket` to
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "product_name": { "terms" : { "field": "product", "missing_bucket": true } } }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "product_name": { "terms": { "field": "product", "missing_bucket": true } } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -554,18 +554,18 @@ For example:
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "size": 2,
|
|
|
- "sources" : [
|
|
|
- { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d" } } },
|
|
|
- { "product": { "terms": {"field": "product" } } }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "size": 2,
|
|
|
+ "sources": [
|
|
|
+ { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d" } } },
|
|
|
+ { "product": { "terms": { "field": "product" } } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
// TEST[s/_search/_search\?filter_path=aggregations/]
|
|
@@ -575,31 +575,31 @@ GET /_search
|
|
|
[source,console-result]
|
|
|
--------------------------------------------------
|
|
|
{
|
|
|
- ...
|
|
|
- "aggregations": {
|
|
|
- "my_buckets": {
|
|
|
- "after_key": {
|
|
|
- "date": 1494288000000,
|
|
|
- "product": "mad max"
|
|
|
- },
|
|
|
- "buckets": [
|
|
|
- {
|
|
|
- "key": {
|
|
|
- "date": 1494201600000,
|
|
|
- "product": "rocky"
|
|
|
- },
|
|
|
- "doc_count": 1
|
|
|
- },
|
|
|
- {
|
|
|
- "key": {
|
|
|
- "date": 1494288000000,
|
|
|
- "product": "mad max"
|
|
|
- },
|
|
|
- "doc_count": 2
|
|
|
- }
|
|
|
- ]
|
|
|
+ ...
|
|
|
+ "aggregations": {
|
|
|
+ "my_buckets": {
|
|
|
+ "after_key": {
|
|
|
+ "date": 1494288000000,
|
|
|
+ "product": "mad max"
|
|
|
+ },
|
|
|
+ "buckets": [
|
|
|
+ {
|
|
|
+ "key": {
|
|
|
+ "date": 1494201600000,
|
|
|
+ "product": "rocky"
|
|
|
+ },
|
|
|
+ "doc_count": 1
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "key": {
|
|
|
+ "date": 1494288000000,
|
|
|
+ "product": "mad max"
|
|
|
+ },
|
|
|
+ "doc_count": 2
|
|
|
}
|
|
|
+ ]
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
// TESTRESPONSE[s/\.\.\.//]
|
|
@@ -612,19 +612,19 @@ For example, this request uses the `after_key` value provided in the previous re
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "size": 2,
|
|
|
- "sources" : [
|
|
|
- { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } },
|
|
|
- { "product": { "terms": {"field": "product", "order": "asc" } } }
|
|
|
- ],
|
|
|
- "after": { "date": 1494288000000, "product": "mad max" } <1>
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "size": 2,
|
|
|
+ "sources": [
|
|
|
+ { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } },
|
|
|
+ { "product": { "terms": { "field": "product", "order": "asc" } } }
|
|
|
+ ],
|
|
|
+ "after": { "date": 1494288000000, "product": "mad max" } <1>
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -644,23 +644,23 @@ For instance the following index sort:
|
|
|
--------------------------------------------------
|
|
|
PUT twitter
|
|
|
{
|
|
|
- "settings" : {
|
|
|
- "index" : {
|
|
|
- "sort.field" : ["username", "timestamp"], <1>
|
|
|
- "sort.order" : ["asc", "desc"] <2>
|
|
|
- }
|
|
|
- },
|
|
|
- "mappings": {
|
|
|
- "properties": {
|
|
|
- "username": {
|
|
|
- "type": "keyword",
|
|
|
- "doc_values": true
|
|
|
- },
|
|
|
- "timestamp": {
|
|
|
- "type": "date"
|
|
|
- }
|
|
|
- }
|
|
|
+ "settings": {
|
|
|
+ "index": {
|
|
|
+ "sort.field": [ "username", "timestamp" ], <1>
|
|
|
+ "sort.order": [ "asc", "desc" ] <2>
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "mappings": {
|
|
|
+ "properties": {
|
|
|
+ "username": {
|
|
|
+ "type": "keyword",
|
|
|
+ "doc_values": true
|
|
|
+ },
|
|
|
+ "timestamp": {
|
|
|
+ "type": "date"
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -673,16 +673,16 @@ PUT twitter
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "user_name": { "terms" : { "field": "user_name" } } } <1>
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "user_name": { "terms": { "field": "user_name" } } } <1>
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -692,17 +692,17 @@ GET /_search
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "user_name": { "terms" : { "field": "user_name" } } }, <1>
|
|
|
- { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } } <2>
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "user_name": { "terms": { "field": "user_name" } } }, <1>
|
|
|
+ { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } } <2>
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -717,18 +717,18 @@ and it would be costly to compute this number on every page:
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "track_total_hits": false,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "user_name": { "terms" : { "field": "user_name" } } },
|
|
|
- { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "track_total_hits": false,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "user_name": { "terms": { "field": "user_name" } } },
|
|
|
+ { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
|
|
@@ -756,22 +756,22 @@ per composite bucket:
|
|
|
--------------------------------------------------
|
|
|
GET /_search
|
|
|
{
|
|
|
- "size": 0,
|
|
|
- "aggs" : {
|
|
|
- "my_buckets": {
|
|
|
- "composite" : {
|
|
|
- "sources" : [
|
|
|
- { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } },
|
|
|
- { "product": { "terms": {"field": "product" } } }
|
|
|
- ]
|
|
|
- },
|
|
|
- "aggregations": {
|
|
|
- "the_avg": {
|
|
|
- "avg": { "field": "price" }
|
|
|
- }
|
|
|
- }
|
|
|
+ "size": 0,
|
|
|
+ "aggs": {
|
|
|
+ "my_buckets": {
|
|
|
+ "composite": {
|
|
|
+ "sources": [
|
|
|
+ { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d", "order": "desc" } } },
|
|
|
+ { "product": { "terms": { "field": "product" } } }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "aggregations": {
|
|
|
+ "the_avg": {
|
|
|
+ "avg": { "field": "price" }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
// TEST[s/_search/_search\?filter_path=aggregations/]
|
|
@@ -781,57 +781,57 @@ GET /_search
|
|
|
[source,console-result]
|
|
|
--------------------------------------------------
|
|
|
{
|
|
|
- ...
|
|
|
- "aggregations": {
|
|
|
- "my_buckets": {
|
|
|
- "after_key": {
|
|
|
- "date": 1494201600000,
|
|
|
- "product": "rocky"
|
|
|
- },
|
|
|
- "buckets": [
|
|
|
- {
|
|
|
- "key": {
|
|
|
- "date": 1494460800000,
|
|
|
- "product": "apocalypse now"
|
|
|
- },
|
|
|
- "doc_count": 1,
|
|
|
- "the_avg": {
|
|
|
- "value": 10.0
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- "key": {
|
|
|
- "date": 1494374400000,
|
|
|
- "product": "mad max"
|
|
|
- },
|
|
|
- "doc_count": 1,
|
|
|
- "the_avg": {
|
|
|
- "value": 27.0
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- "key": {
|
|
|
- "date": 1494288000000,
|
|
|
- "product" : "mad max"
|
|
|
- },
|
|
|
- "doc_count": 2,
|
|
|
- "the_avg": {
|
|
|
- "value": 22.5
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- "key": {
|
|
|
- "date": 1494201600000,
|
|
|
- "product": "rocky"
|
|
|
- },
|
|
|
- "doc_count": 1,
|
|
|
- "the_avg": {
|
|
|
- "value": 10.0
|
|
|
- }
|
|
|
- }
|
|
|
- ]
|
|
|
+ ...
|
|
|
+ "aggregations": {
|
|
|
+ "my_buckets": {
|
|
|
+ "after_key": {
|
|
|
+ "date": 1494201600000,
|
|
|
+ "product": "rocky"
|
|
|
+ },
|
|
|
+ "buckets": [
|
|
|
+ {
|
|
|
+ "key": {
|
|
|
+ "date": 1494460800000,
|
|
|
+ "product": "apocalypse now"
|
|
|
+ },
|
|
|
+ "doc_count": 1,
|
|
|
+ "the_avg": {
|
|
|
+ "value": 10.0
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "key": {
|
|
|
+ "date": 1494374400000,
|
|
|
+ "product": "mad max"
|
|
|
+ },
|
|
|
+ "doc_count": 1,
|
|
|
+ "the_avg": {
|
|
|
+ "value": 27.0
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "key": {
|
|
|
+ "date": 1494288000000,
|
|
|
+ "product": "mad max"
|
|
|
+ },
|
|
|
+ "doc_count": 2,
|
|
|
+ "the_avg": {
|
|
|
+ "value": 22.5
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "key": {
|
|
|
+ "date": 1494201600000,
|
|
|
+ "product": "rocky"
|
|
|
+ },
|
|
|
+ "doc_count": 1,
|
|
|
+ "the_avg": {
|
|
|
+ "value": 10.0
|
|
|
+ }
|
|
|
}
|
|
|
+ ]
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
// TESTRESPONSE[s/\.\.\.//]
|