# Too long search with sort inside query after migrate es6.8 to es7.16

**URL:** <https://discuss.elastic.co/t/too-long-search-with-sort-inside-query-after-migrate-es6-8-to-es7-16/301157>\
**Category:** Elasticsearch\
**Created:** [March 31, 2022, 5:33am UTC](https://discuss.elastic.co/t/too-long-search-with-sort-inside-query-after-migrate-es6-8-to-es7-16/301157 "2022-03-31T05:33:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![111338](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111338/32/68432_2.png) [@111338](https://discuss.elastic.co/u/111338)\
**Post date:** [March 31, 2022, 5:33am UTC](https://discuss.elastic.co/t/too-long-search-with-sort-inside-query-after-migrate-es6-8-to-es7-16/301157/1 "2022-03-31T05:33:01Z")

</div>

Several years we live with es68 and it works fine. But now we want to migrate to es716 and we got problem with queries which contains `sort` option inside. For example, we have simple query which returns only one record

```auto
GET /someindex/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "is_category": false
          }
        },
        {
          "term": {
            "parents": 100500
          }
        },
        {
          "term": {
            "category_id": 100600
          }
        }
      ]
    }
  },
  "size": 1,
  "_source": [
    "id", "name", "parents"
  ]
}

```

in result i got my only one document (it only one exists in es) with `took=5ms`

```auto
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 10,
    "successful" : 10,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "someindex",
        "_type" : "somedoctype",
        "_id" : "100700",
        "_score" : null,
        "_source" : {
          "id": 100700,
          "name": "document name",
          "parents": [100400, 100500]
        }
      }
    ]
  }
}

```

But if add sort option to query

```auto
  "sort": {
    "keyword_field_name": "asc"
  }

```

i got result, but took-time increase to 70-1000ms

```auto
{
  "took" : 98,
  "timed_out" : false,
  "_shards" : {
    "total" : 10,
    "successful" : 10,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "someindex",
        "_type" : "somedoctype",
        "_id" : "100700",
        "_score" : null,
        "_source" : {
          "id": 100700,
          "name": "document name",
          "parents": [100400, 100500]
        },
        "sort" : [
          "name for sorting"
        ]
      }
    ]
  }
}

```

I see increase execution time for **EACH** query with sorting inside.  
Help me please, how i can to fix it?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 31, 2022, 11:53am UTC](https://discuss.elastic.co/t/too-long-search-with-sort-inside-query-after-migrate-es6-8-to-es7-16/301157/2 "2022-03-31T11:53:21Z")

</div>

First obvious question: Have there been any **other** changes except the upgrade? Different mapping? Has the data been reindexed or the old index used? Same hardware? Same number of shards?

You can take a look at the profile API and its Kibana counterpart to maybe check for the runtimes and where time is spent. See [Profile queries and aggregations | Kibana Guide [8.1] | Elastic](https://www.elastic.co/guide/en/kibana/8.1/xpack-profiler.html)

---

<div class="post-metadata">

**Author:** ![111338](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111338/32/68432_2.png) [@111338](https://discuss.elastic.co/u/111338)\
**Post date:** [April 1, 2022, 8:53am UTC](https://discuss.elastic.co/t/too-long-search-with-sort-inside-query-after-migrate-es6-8-to-es7-16/301157/3 "2022-04-01T08:53:27Z")

</div>

No. I have no any changes.

1. Upgrade version
2. Create same index/mapping
3. Put same documents like in old version

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 4, 2022, 9:52am UTC](https://discuss.elastic.co/t/too-long-search-with-sort-inside-query-after-migrate-es6-8-to-es7-16/301157/4 "2022-04-04T09:52:54Z")

</div>

Then please share profile outputs as mentioned above, as well as hot threads when the searches are running.

---

<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:** [May 2, 2022, 9:53am UTC](https://discuss.elastic.co/t/too-long-search-with-sort-inside-query-after-migrate-es6-8-to-es7-16/301157/5 "2022-05-02T09:53:09Z")

</div>

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