I'm trying to build a query allowing me to make multiple aggregations on a single query. Here's the request I'm sending :
{
"size": 1,
"aggs": {
"firmNames": {
"terms": {
"field": "firm_name",
"size": 100000000
},
"aggs": {
"domains": {
"terms": {
"field": "domain",
"size": 100000000
},
"aggs": {
"logDates": {
"terms": {
"field": "log_date",
"size": 10000000
},
"aggs": {
"traffics": {
"sum": {
"field": "traffic"
}
},
"script_fields": {
"scripted_metric": {
"script": {
"lang": "painless",
"inline": "HashSet set = new HashSet; set.add(doc['file_name']); return set;"
}
}
}
}
}
}
}
}
}
}}
However, I'm getting the following error when executing this query :
{
"error" : {`enter code here`
"root_cause" : [
{
"type" : "parsing_exception",
"reason" : "Unknown key for a START_OBJECT in [script_fields]: [script].",
"line" : 15,
"col" : 23
}
],
"type" : "parsing_exception",
"reason" : "Unknown key for a START_OBJECT in [script_fields]: [script].",
"line" : 15,
"col" : 23
},
"status" : 400
}
I've been trying to change this query in many forms to make it works but I always end up with this error.
The script_fields
section is not at the right place, it should be located at the top level:
{
"size": 1,
"aggs": {
"firmNames": {
"terms": {
"field": "firm_name",
"size": 100000000
},
"aggs": {
"domains": {
"terms": {
"field": "domain",
"size": 100000000
},
"aggs": {
"logDates": {
"terms": {
"field": "log_date",
"size": 10000000
},
"aggs": {
"traffics": {
"sum": {
"field": "traffic"
}
}
}
}
}
}
}
}
},
"script_fields": {
"scripted_metric": {
"script": {
"lang": "painless",
"inline": "HashSet set = new HashSet(); set.add(doc.file_name.value); return set;"
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.