# Search\_after with sort on nested fields

**URL:** <https://forum.opensearch.org/t/search-after-with-sort-on-nested-fields/17547>\
**Category:** OpenSearch\
**Tags:** discuss, troubleshoot\
**Created:** [January 23, 2024, 11:13am UTC](https://forum.opensearch.org/t/search-after-with-sort-on-nested-fields/17547 "2024-01-23T11:13:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pejaneczek](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/pejaneczek/32/6871_2.png) [@pejaneczek](https://forum.opensearch.org/u/pejaneczek)\
**Post date:** [January 23, 2024, 11:13am UTC](https://forum.opensearch.org/t/search-after-with-sort-on-nested-fields/17547/1 "2024-01-23T11:13:13Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
Opensearch 2.9

**Describe the issue** :  
I’ve encountered an issue with _search\_after_ functionality used with _sort_ on nested field.

I have around 40k documents and I want to retrieve them using [search\_after](https://opensearch.org/docs/latest/search-plugins/searching-data/paginate/#the-search_after-parameter)

I expect that I will eventually have 30k records at the end (after all search\_after queries), example search\_after query:

```auto
{
  "query: { some query here },
  "search_after": [
    123,
    "some_id"
  ],
  "sort": [
    {
      "AAA.bbb": {
        "order": "asc",
        "unmapped_type": "long",
        "nested": {
          "path": "AAA"
        }
      }
    },
    {
      "_id": {
        "order": "asc"
      }
    }
  ]
}

```

as a result I have ~11k results.

but for the same query but different sort params (not on nested field) I have proper expected results (30k), example query:

```auto
      "search_after": [
        "some_name",
        "some_id"
      ],
      "sort": [
        {
          "name": {
            "order": "desc",
            "unmapped_type": "long"
          }
        },
        {
          "_id": {
            "order": "asc"
          }
        }
      ]

```

Has anyone had a similar issue or have an idea what could be the problem?

Thanks in advance !  
Pawel
