Hi,
until now I was mostly just using kibana and i borrowed some queries from there, to fire some of them via curl.
So I am quite a Newbie about quering ES directly. So I need your help.
I have an index which has documents with following fields:
- userName
- sessionId
- processingTime
- serviceCall
Now I would like to query elasticsearch for following result:
(count of documents) / (count of unique userName).
(count of documents) / (count of unique sessionId)
I managed to query the following
GET /tux-prod-2017.08.30/_search
{
"size": 0,
"aggs": {
"uniqueUsers": {
"cardinality": {
"field": "userName.keyword"
}
},
"uniqueSessions": {
"cardinality": {
"field": "sessionId.keyword"
}
}
},
"query": {
"bool": {
"must": [
{
"query_string": {
"analyze_wildcard": true,
"query": "type.keyword: useractionlog"
}
},
{
"range": {
"@timestamp": {
"gte": "now-10m/m",
"lte": "now/m"
}
}
}
],
"must_not": []
}
}
}
As result i get the metrics which I need as Input for my calculation
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 18291,
"max_score": 0,
"hits": []
},
"aggregations": {
"uniqueUsers": {
"value": 644
},
"uniqueSessions": {
"value": 4929
}
}
}
So I could extract the uniqueUser.value, uniqueSessions.value and hits.total and calculate externally.
But is there a way to get it calculated inside ES?
Thanks, Andreas