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

**URL:** <https://discuss.elastic.co/t/pass-raw-search-object-to-searchasync-elastic-clients-elasticsearch-8-1-1-net/334311>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [May 25, 2023, 11:10am UTC](https://discuss.elastic.co/t/pass-raw-search-object-to-searchasync-elastic-clients-elasticsearch-8-1-1-net/334311 "2023-05-25T11:10:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![felix-stnr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felix-stnr/32/120218_2.png) [@felix-stnr](https://discuss.elastic.co/u/felix-stnr)\
**Post date:** [May 25, 2023, 11:10am UTC](https://discuss.elastic.co/t/pass-raw-search-object-to-searchasync-elastic-clients-elasticsearch-8-1-1-net/334311/1 "2023-05-25T11:10:55Z")

</div>

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:

```auto
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)?

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

```

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

```auto
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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 22, 2023, 11:11am UTC](https://discuss.elastic.co/t/pass-raw-search-object-to-searchasync-elastic-clients-elasticsearch-8-1-1-net/334311/2 "2023-06-22T11:11:30Z")

</div>

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