Answer the question
In order to leave comments, you need to log in
How to write an aggregation request correctly?
Hello.
The following documents are in the elastic:
{
{
"status_id" : 1,
"client_id" : 2,
"task_id" : 3
},
{
"status_id" : 2,
"client_id" : 2,
"task_id" : 3
},
{
"status_id" : 3,
"client_id" : 2,
"task_id" : 3
}
}
status_id
with the passed client_id
and task_id
. SELECT status_id, COUNT(*) AS count FROM table WHERE client_id = 2 AND task_id = 3 GROUP BY status_id;
Answer the question
In order to leave comments, you need to log in
Try to generate requests here: www.nlpcn.org:9999/web
You can greatly simplify and optimize, but in general, something like this:
{
"from": 0,
"size": 0,
"query": {
"bool": {
"must": {
"bool": {
"must": [
{
"match": {
"client_id": {
"query": 2,
"type": "phrase"
}
}
},
{
"match": {
"task_id": {
"query": 3,
"type": "phrase"
}
}
}
]
}
}
}
},
"_source": {
"includes": [
"status_id",
"COUNT"
],
"excludes": []
},
"fields": "status_id",
"aggregations": {
"status_id;": {
"terms": {
"field": "status_id;",
"size": 200
},
"aggregations": {
"count": {
"value_count": {
"field": "_index"
}
}
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question