Skip to content

[FEATURE] Support knn_search endpoint #7054

@TonyWang666

Description

@TonyWang666

Elastic.Clients.Elasticsearch version:
8.0.1
Elasticsearch version:
8.3.2
.NET runtime version:
6.0.11
Operating system version:
macOS Catalina Version 10.15.7
Description of the problem including expected versus actual behavior:
The latest version(8.0.1) of dotnet client doesn't have knn_search method like what official page shows.
When I use search with Knn in the body, it return 400 with following 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}

Steps to reproduce:

  1. download NuGet Package Elastic.Clients.Elasticsearch with latest version 8.0.1
  2. Connect to Elasticsearch Database with Uri and BasicAuthentication Info(AccountName&Password)
  3. Try to get response with SearchAsync endpoint with following C# code:
var response = await _client.SearchAsync<ImageSearchDocument>(
            s => s
                .Knn(k => k
                    .QueryVector(embedding_vector)
                    .Field(_EmbeddingVectorStr)
                    .k(searchTotal)
                    .NumCandidates(numCandidate)
                 )
                .Index(FullImageSearchIndexName)
        );

Expected behavior
What I expect is the response of knn_search result like what I got from Postman with same requestBody, uri, and accountInfo:
{ "took": 5, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 20, "relation": "eq" }, "max_score": 0.052058797, "hits": [ { "_index": "XXXXXXXX", "_id": "0", "_score": 0.052058797, "_source": { ...... } } } }
Provide ConnectionSettings (if relevant):

Provide DebugInformation (if relevant):

Invalid Elasticsearch response built from a unsuccessful (400) low level call on POST: /st1_brand_safety-full_image_search-1-index/_search?_source_excludes=embedding_vector
 - [1] BadResponse: Node: https://XXXXXXXXXXXXXX.com/ Took: 00:00:02.3115470
# OriginalException: Elastic.Transport.TransportException: Request failed to execute. Call: Status code 400 from: POST /st1_brand_safety-full_image_search-1-index/_search?_source_excludes=embedding_vector. ServerError: Type: parsing_exception Reason: "Unknown key for a START_OBJECT in [knn]."
# Audit trail of this API call:
#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0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]}}
# Response:

{"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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    8.xRelates to a 8.x client version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions