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

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

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

{
  "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

  "sort": {
    "keyword_field_name": "asc"
  }

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

{
  "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?

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

No. I have no any changes.

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

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

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