Pass raw search object to `SearchAsync` Elastic.Clients.Elasticsearch 8.1.1 .NET

I am trying to implement an API, which allows users to dynamically query an Elasticsearch index. The API should therefore act like a "proxy" between the user and Elasticsearch (the API performs additional operations along the query execution itself).
Currently, I have following query, which allows users to pass a query object and an index to the API:

var response = await _elasticsearchClient
    .SearchAsync<object>(s => s
        .Index(Indices.Parse(index))
        .Query(q => q.RawJson(JsonSerializer.Serialize(query))));

This works fine and behaves as expected. However, I would like to allow the user to specify additional arguments (e.g. aggregations) as well. Is there a way to pass a search object like the following as an argument to the SearchAsync method (like it is possible for the query method)?

{
  "size": ...,
  "query": {...},
  "aggs": {...}
}

To be more precise, I want to ask if something like the following exists:

var response = await _elasticsearchClient
    .SearchAsync<object>(index, search); // search is the JSON object above

I know that I could directly call the Elasticsearch REST API, but I would prefer to stick with the .NET client. So my actual question is: Is there a way to implement the desired functionality with the .NET client? If not, is there a specific reason for not implementing such a feature or will it be part of a future release? Thanks in advance for your help!

1 Like

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