NEST result loses aggregates

This is my query

{
   "query":{
      "match_all":{

      }
   },
   "size":20,
   "aggs":{
      "CompanyName.raw":{
         "terms":{
            "field":"CompanyName.raw",
            "size":20,
            "order":{
               "_count":"desc"
            }
         }
      }
   }
}

When I send it directly to ElasticSearch the result contains an array aggregations['CompanyName.raw']['buckets'].
However, when I issue the same request with NEST this array is empty.

                using (MemoryStream ms = new MemoryStream())
                {
                    Client.RequestResponseSerializer.Serialize<ISearchResponse<ProductPurchasing>>(r, ms);
                    ms.Position = 0;
                    using (StreamReader sr = new StreamReader(ms))
                    {
                        string responseJson = sr.ReadToEnd();
                    }
                }

Where has this gone? Surely this is a severe bug?

Can you show the response JSON?

Responses are not guaranteed to be re-serializable back to a MemoryStream or byte array. If you want to have both the response bytes and an instance of a response type to work with, you can either

  1. Set .DisableDirectStreaming() either on ConnectionSettings to globally apply, or on an individual request, to buffer the request/response bytes on the response instance, in the . ApiCall.RequestBodyBytes or .ApiCall.ResponseBodyBytes, respectively.

or

  1. Use the low level client to make the request, and return a StringResponse or BytesResponse. Then deserialize this response to a SearchResponse<ProductPurchasing>. If you use the low level client exposed on NEST through the .LowLevel property, you can pass a high level request like SearchRequest<ProductPurchasing> to the low level client using PostData.Serializable(request)

Thank you.
Using the low level client has got me what I need.

(We run a multi-tenant sytem so I'm intercepting queries written by ReactiveSearch to add various restrictions and exclude other clients' data such as prices. Using NEST to handle the queies ought to be easier than manipulating raw JSON and NDJSON.)

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.