javaelasticsearchknn

Elasticsearch knn query required param k - Java client


I am trying to execute a KnnQuery (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-knn-query.html) in my java application

(So not the knn search: https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html#knn-similarity-search).

When you use knn in a query, you can't set parameter k since the size parameter is used

enter image description here

(https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-knn-query.html#:~:text=knn%20query%20doesn%E2%80%99t%20have%20a%20separate%20k%20parameter).

But, the Java client with version 8.13 requires the k parameter: (co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'KnnQuery.k'):

enter image description here

So my problem is kind of a deadlock. ElasticSearch doesn't support the k parameter when knn is used in a query, but the java client requires the k parameter.

So anyone else having this issue?


Solution

  • I've posted the same question on the elastic forum and I was told that it is a bug. Created an issue on Github.