Sahil Sharma
Sahil Sharma

Reputation: 4247

Elastic search: How extract total count from elastic multi search query response IMultiSearchResponse

I have elastic multi-search query that returns me 3 list of documents.

The response in sense looks like:

{
   "responses": [
      {
         ...
         "hits": {
            "total": 0,
            "max_score": null,
            "hits": []
         }
      },
      {
         ...
         "hits": {
            "total": 0,
            "max_score": null,
            "hits": []
         }
      },
      {
         ...
         "hits": {
            "total": 0,
            "max_score": null,
            "hits": []
         }
      }
   ]
}

I get the 3 list of documents in c# through "results.GetResponses()".

But i don't know how can i get the total of each list? i.e. total count?

Upvotes: 0

Views: 680

Answers (1)

Martijn Laarman
Martijn Laarman

Reputation: 13536

You can sum all the responses total properties:

response.GetResponses<object>().Sum(r=>r.HitsMetaData.Total);

Upvotes: 1

Related Questions