# Better way of displaying KNN results in Kibana?

**URL:** <https://discuss.elastic.co/t/better-way-of-displaying-knn-results-in-kibana/317104>\
**Category:** Kibana\
**Created:** [October 20, 2022, 11:51am UTC](https://discuss.elastic.co/t/better-way-of-displaying-knn-results-in-kibana/317104 "2022-10-20T11:51:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![freddyh](https://avatars.discourse-cdn.com/v4/letter/f/bc79bd/32.png) [@freddyh](https://discuss.elastic.co/u/freddyh)\
**Post date:** [October 20, 2022, 11:51am UTC](https://discuss.elastic.co/t/better-way-of-displaying-knn-results-in-kibana/317104/1 "2022-10-20T11:51:51Z")

</div>

I'm using the approximate kNN feature to index a vector for searching. With the previous exact kNN method I was able to craft a URL string for the script\_score query, but I haven't been able to replicate that with the approximate kNN approach, I assume because it uses a top-level `knn` key instead of putting it under the `query` key.

The approach I've come up with, which does work, but isn't particularly nice is to manually create a saved search, with `attributes.kibanaSavedObjectMeta.searchSourceJSON` set to the quote-escaped JSON string I'd be sending to elastic. This appears to not work when opened, but inspecting the request reveals Kibana is adding on the default query of

```json
"query": {
    "bool": {
      "must": [],
      "filter": [],
      "should": [],
      "must_not": []
    }
}

```

Running the whole query through the search profiler reveals the kNN search _is_ being performed, but its results are being merged with the above query which returns everything in the index.

I've managed to solve this by adding a query myself which is guaranteed to return 0 results (the `_id` field must not exist), which then causes only the kNN results to be returned.

I then tried to reverse this back into the RISON-encoded URL: (other props removed for space)

```auto
/app/discover#/?_a=(index:'8270ea28-dedb-4353-8fbf-bc83b0310a8a',query:(language:lucene,knn:(field:embedding,k:10,num_candidates:1000,query_vector:!(vector,here)),query:(bool:(must_not:!((exists:(field:_id)))))))

```

but the rnn property is completely ignored and it just performs the query. Is there any other way of doing this without having to create a saved search each time?

---

<div class="post-metadata">

**Author:** ![jughosta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jughosta/32/107160_2.png) [@jughosta](https://discuss.elastic.co/u/jughosta)\
**Post date:** [October 31, 2022, 9:58am UTC](https://discuss.elastic.co/t/better-way-of-displaying-knn-results-in-kibana/317104/2 "2022-10-31T09:58:06Z")

</div>

Hi @freddyh !  
There is no support for it yet. Could you please create a Github issue? Thanks!

> **[Issues · elastic/kibana](https://github.com/elastic/kibana/issues)**
>
> Your window into the Elastic Stack. Contribute to elastic/kibana development by creating an account on GitHub.

---

<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:** [November 26, 2022, 4:37pm UTC](https://discuss.elastic.co/t/better-way-of-displaying-knn-results-in-kibana/317104/3 "2022-11-26T16:37:56Z")

</div>



---

<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 24, 2022, 4:38pm UTC](https://discuss.elastic.co/t/better-way-of-displaying-knn-results-in-kibana/317104/4 "2022-12-24T16:38:32Z")

</div>

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