I just learned Elastic, and I want to write some code that analyses the user requests API in different time dimensions.
- How many times does the user request in one day?
- How many times does the user request in one week?
- How many times does the user request in one month?
- How many times does the user request in one year?
The code has shown below:
POST my-index/_count
{
"query": {
"bool": {
"filter": [
{
"terms": {
"user_id.keyword": ["USER_ID"]
}
},
{
"wildcard": {
"uri.keyword": "/api-path*"
}
},
{
"range": {
"@timestamp": {
"gte": "now-1y/y",
"lte": "now/d"
}
}
}
]
}
}
}
But I should send the code to elastic four times in different @timestamp parameter(now-1d/d, now-1w/w, now-1m/m, now-1y/y). That will cost a lot of networks and computing resources.
Have any method that puts them in one request?