I try to use elasticsearch knn_search 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
var response = await _client.SearchAsync<ImageSearchDocument>(
s => s
.Knn(k => k
.QueryVector(embedding_vector)
.Field(_EmbeddingVectorStr)
.k(searchTotal)
.NumCandidates(numCandidate)
)
.Index(FullImageSearchIndexName)
);
ES Error
{"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.