Skip to content

Unable to perform knn query [knn] unknown field [k #8124

Closed
@alkampfergit

Description

@alkampfergit

Elastic.Clients.Elasticsearch version:

Elasticsearch version:
8.13.0
.NET runtime version:
.NET 8
Operating system version:
Windows 11
Description of the problem including expected versus actual behavior:
I've created a knn query with the following syntax

        var knnOuterQuery = new QueryDescriptor<object>().Knn(knn => knn
            .Filter(query)
            .Field("vector")
            .NumCandidates(limit * 2)
            .QueryVector(coll));

Then I got an error: ServerError: Type: x_content_parse_exception Reason: "[9:7] [knn] unknown field [k]"

Looking for generated query it contains a k value that it is not supported: this is the request where you can see a k : 0 that is not correct. If I remove that parameter and try to execute the query everything seems to work just fine.

{
  "from": 0,
  "query": {
    "knn": {
      "field": "vector",
      "filter": {
        "match_all": {}
      },
      "k": 0,
      "num_candidates": 10,
      "query_vector": [
        -0.0546875,
        -0.53125,
        0.453125,
        -0.484375
      ]
    }
  },
  "size": 5
}

Indeed the driver has that parameter in the request, but seems not to be understood by the server. I'm constructing the query from a QueryDescriptor() object.

image

Am I doing something wrong or the driver indeed add a wrong "k" argument to the query?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions