# Size parameter ignored in nested knn search

**URL:** <https://discuss.elastic.co/t/size-parameter-ignored-in-nested-knn-search/350285>\
**Category:** Elasticsearch\
**Tags:** vector-search\
**Created:** [January 3, 2024, 8:18am UTC](https://discuss.elastic.co/t/size-parameter-ignored-in-nested-knn-search/350285 "2024-01-03T08:18:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jasper\_Simon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasper_simon/32/130349_2.png) [@Jasper\_Simon](https://discuss.elastic.co/u/Jasper_Simon)\
**Post date:** [January 3, 2024, 8:18am UTC](https://discuss.elastic.co/t/size-parameter-ignored-in-nested-knn-search/350285/1 "2024-01-03T08:18:55Z")

</div>

I noticed the quote below in the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html#nested-knn-search), about the limitation to retrieve only the best match vector regardless of the `"size"` parameter in the `inner_hits` section of the search request.

> `inner_hits` for kNN will only ever return a single hit, the nearest passage vector. Setting `"size"` to any value greater than `1` will have no effect on the results.

Currently we're doing a hybrid search, and are interested in the parent documents for the "classic" search part, and in the individual nested documents when doing knn search. The `"size"` parameter is ignored in the knn search regardless of whether using hybrid search or not, so the example is a simple knn search.

Is there a specific reason for this behaviour and/or will it be addressed in a future release?  
It there a possibility to work around this limitation?

Using version `8.11.1`

Example document:

```json
{
  "title": "First searchable document",
  "paragraphs": [
    {
      "text": "Block of text",
      "vector": [0.1, 0.2]
    },
    {
      "text": "A second block of text",
      "vector": [0.1, 0.3]
    },
    {
      "text": "A third block of text",
      "vector": [0.2, 0.3]
    }
  ]
}

```

Corresponding mapping:

```json
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      },
      "paragraphs": {
        "type": "nested",
        "properties": {
          "text": {
            "type": "text"
          },
          "vector": {
            "type": "dense_vector",
            "dims": 2,
            "index": true,
            "similarity": "dot_product"
          }
        }
      }
    }
  }
}

```

Example request to be complete:

```json
{
  "fields": ["paragraphs.text"],
  "_source": false,
  "knn": {
    "field": "paragraphs.vector",
    "query_vector": [0.1234232, 0.1456789],
    "num_candidates": 100,
    "k": 10,
    "inner_hits": {
      "name": "someName",
      "size": 10,
      "_source": ["paragraphs.text"],
      "fields": ["paragraphs.text"]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![BenTrent](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bentrent/32/33915_2.png) [@BenTrent](https://discuss.elastic.co/u/BenTrent)\
**Post date:** [January 3, 2024, 11:44am UTC](https://discuss.elastic.co/t/size-parameter-ignored-in-nested-knn-search/350285/2 "2024-01-03T11:44:24Z")

</div>

@Jasper_Simon that is indeed a current limitation. You can track the feature progress here: [[Feature Request] Support inner\_hits.size \> 1 for nested dense vector fields · Issue #102950 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/102950)

---

<div class="post-metadata">

**Author:** ![Jasper\_Simon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasper_simon/32/130349_2.png) [@Jasper\_Simon](https://discuss.elastic.co/u/Jasper_Simon)\
**Post date:** [January 23, 2024, 12:34pm UTC](https://discuss.elastic.co/t/size-parameter-ignored-in-nested-knn-search/350285/3 "2024-01-23T12:34:34Z")

</div>

@BenTrent I see that the feature request has been merged - awesome, thank you for that!  
In which release version should I expect this to start working?

---

<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:** [February 20, 2024, 12:34pm UTC](https://discuss.elastic.co/t/size-parameter-ignored-in-nested-knn-search/350285/4 "2024-02-20T12:34:51Z")

</div>

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