0

i'm looking to add a feature to an existing query. Basically, I run a query that returns say 1000 documents. Those documents all have the same structure, only the values of certain fields vary. What i'd like, is to not only get the full list as a result, but also count how many results have a field X with the value Y, how many results have the same field X with the value Z etc...

Basically get all the results + 4 or 5 "counts" that would act like the SQL "group by", in a way. The point of this is to allow full text search over all the clients in our database (without filtering), while showing how many of those are active clients, past clients, active prospects etc...

Any way to do this without running additional / separate queries ?

EDIT WITH ANSWER :

Aggregations is the way to go. Here's how I did it, it's so straightforward that I expected much harder work !

{
"query": {
    "term": {
        "_type":"client"
    }
},
"aggregations" : {
    "agg1" : {
        "terms" : {
            "field" : "listType.typeRef.keyword"
        }
    }
}

}

Note that it's even in a list of terms and not a single field, that's just how easy it was !

1 Answer 1

1

I believe what you are looking for is the aggregation query.

The documentation should be clear enough, but if you struggle please give us your ES query and we will help you from there.

Sign up to request clarification or add additional context in comments.

1 Comment

Indeed it was pretty straightforward once I got around the first pages of text. I'll update my initial question to help out people who might encounter trouble in the future. Thanks !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.