# Dotnet Client(\`Elastic.Clients.Elasticsearch\`) doesn't support knn\_search

**URL:** <https://discuss.elastic.co/t/dotnet-client-elastic-clients-elasticsearch-doesnt-support-knn-search/319795>\
**Category:** Elasticsearch\
**Tags:** language-clients, vector-search\
**Created:** [November 25, 2022, 7:34am UTC](https://discuss.elastic.co/t/dotnet-client-elastic-clients-elasticsearch-doesnt-support-knn-search/319795 "2022-11-25T07:34:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jiaxiang\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jiaxiang_wang/32/114051_2.png) [@Jiaxiang\_Wang](https://discuss.elastic.co/u/Jiaxiang_Wang)\
**Post date:** [November 25, 2022, 7:34am UTC](https://discuss.elastic.co/t/dotnet-client-elastic-clients-elasticsearch-doesnt-support-knn-search/319795/1 "2022-11-25T07:34:03Z")

</div>

I try to use elasticsearch [knn\_search](https://www.elastic.co/guide/en/elasticsearch/reference/master/knn-search.html) feature in dotnet.  
However, I don't think last stable version of es dotnet client `Elastic.Clients.Elasticsearch`(version 8.0.1) support knn\_search.

I try to use Knn feature like code below but only got error below:

#### Sending Request in C# with ES Client 8.0.1

```auto
        var response = await _client.SearchAsync<ImageSearchDocument>(
            s => s
                .Knn(k => k
                    .QueryVector(embedding_vector)
                    .Field(_EmbeddingVectorStr)
                    .k(searchTotal)
                    .NumCandidates(numCandidate)
                 )
                .Index(FullImageSearchIndexName)
        );

```

#### ES Error

```auto
{"error":{"root_cause":[{"type":"parsing_exception","reason":"Unknown key for a START_OBJECT in [knn].","line":1,"col":8}],"type":"parsing_exception","reason":"Unknown key for a START_OBJECT in [knn].","line":1,"col":8},"status":400}

```

The reason above is because the url is using `_search` instead of `_knn_search`. I tried to run the same request on the postman and it works fine after I revise the url to `_knn_search`.

Am I doing something wrong on the syntax? If not, hopefully we can add `knn_search` to dotnet client so that we don't have to write custom dotnet client.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 25, 2022, 8:16am UTC](https://discuss.elastic.co/t/dotnet-client-elastic-clients-elasticsearch-doesnt-support-knn-search/319795/2 "2022-11-25T08:16:51Z")

</div>

If you are using the latest version of Elasticsearcg, it [based on the docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.5/knn-search.html) looks like knn search uses the \_search endpoint. Earlier it seems `_knn_search` was required.

---

<div class="post-metadata">

**Author:** ![stevejgordon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevejgordon/32/80912_2.png) [@stevejgordon](https://discuss.elastic.co/u/stevejgordon)\
**Post date:** [November 29, 2022, 4:56pm UTC](https://discuss.elastic.co/t/dotnet-client-elastic-clients-elasticsearch-doesnt-support-knn-search/319795/3 "2022-11-29T16:56:16Z")

</div>

Hi, @Jiaxiang_Wang.

As the knn\_search endpoint is deprecated, we don't generate methods for calling that in the 8.0 client. This looks like it may be a bug. Can you open [an issue](https://github.com/elastic/elasticsearch-net/issues/new/choose) for this? If you can capture the `DebugInformation` to access and share the serialized request, we can work out if this is an issue in the spec, code-gen or elsewhere.

---

<div class="post-metadata">

**Author:** ![Jiaxiang\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jiaxiang_wang/32/114051_2.png) [@Jiaxiang\_Wang](https://discuss.elastic.co/u/Jiaxiang_Wang)\
**Post date:** [November 30, 2022, 3:29pm UTC](https://discuss.elastic.co/t/dotnet-client-elastic-clients-elasticsearch-doesnt-support-knn-search/319795/4 "2022-11-30T15:29:32Z")

</div>

Hi Steve. I truly appreciate your response to this issue. I just created an issue based on information I have and looking forward to hearing from you. [Dotnet Client(`Elastic.Clients.Elasticsearch`) 8.0.1 doesn’t support knn\_search · Issue #7054 · elastic/elasticsearch-net · GitHub](https://github.com/elastic/elasticsearch-net/issues/7054)

---

<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:** [December 28, 2022, 3:30pm UTC](https://discuss.elastic.co/t/dotnet-client-elastic-clients-elasticsearch-doesnt-support-knn-search/319795/5 "2022-12-28T15:30:22Z")

</div>

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