I have a C# API that uses the Elastic NEST SDK. My version of Elastic is v8.4 It takes an Elastic search query as a JSON request.
im trying to create the NEST request object SearchRequest<T>
using this JSON request and the index name.
This is my helper method that tries to deserialize the JSON request to a QueryContainer
however it always returns in a null QueryContainer
resulting in a search with no query.
public static SearchRequest<T> GetSearchRequestFromJson<T>(string json, string indexName) where T : class
{
var request = new SearchRequest<T>(indexName);
request.Query = JsonConvert.DeserializeObject<QueryContainer>(json);
return request;
}
looking at other examples they are manually mapping the JSON request, but the request is dynamic so I want to avoid if possible any manual object instantiation based on the JSON request
what is the best practise for this? do I need to refactor and use the low level client to support JSON requests?