I want to calculate per IP access count of each product in one day.
There are three parameters in one index(nginx-access-log):
- timestamp
- clientip
- product_id
I know date_histogram can refer to https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html .
And count can refer to https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html#_precision_control.
But I have no idea how to combine the aggs to construct the script.
Update:
I use below script to search
GET log-nginx_access*/_search
{
"aggs": {
"by_day": {
"date_histogram": {
"field": "timestamp",
"interval": "1d",
"time_zone": "Asia/Shanghai",
"min_doc_count": 1
},
"aggs": {
"by_product": {
"terms": {
"field": "uri_args.product_id",
"size": 100
}
},
"aggs": {
"by_ip": {
"terms": {
"field": "clientip"
}
}
}
}
}
}
}
got error:
{
"error": {
"root_cause": [
{
"type": "unknown_named_object_exception",
"reason": "Unknown BaseAggregationBuilder [by_ip]",
"line": 18,
"col": 20
}
],
"type": "unknown_named_object_exception",
"reason": "Unknown BaseAggregationBuilder [by_ip]",
"line": 18,
"col": 20
},
"status": 400
}