Sorting help with query

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "status": {
              "value": 1
            }
          }
        }
      ],
      "should": [
        {
          "wildcard": {
            "e_name": {
              "value": "*huh*"
            }
          }
        },
        {
          "wildcard": {
            "telphone": {
              "value": "*huh*"
            }
          }
        },
        {
          "wildcard": {
            "frog_id": {
              "value": "*huh*"
            }
          }
        },
        {
          "nested": {
            "path": "data",
            "query": {
              "bool": {
                "must": [
                  {
                    "term": {
                      "data.del_status": {
                        "value": 0
                      }
                    }
                  },
                  {
                    "wildcard": {
                      "data.cards_user_name": {
                        "value": "*huh*"
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      ],
      "minimum_should_match": 1
    }
  },
  "sort": [
    {"e_name.length": {"order": "asc"}},
    {"data.cards_user_name.length": {"order": "asc", "nested_path": "data"}},
    {"telphone.length": {"order": "asc"}},
    {"frog_id.length": {"order": "asc"}},
    {"data.cards_no": {"order": "asc", "nested_path": "data"}}
  ]
}
{
    "took": 34,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 3,
            "relation": "eq"
        },
        "max_score": null,
        "hits": [
            {
                "_index": "user_auth_user_info",
                "_type": "_doc",
                "_id": "84039655",
                "_score": null,
                "_source": {
                    "user_id": 84039655,
                    "e_name": "huh",
                    "head_img_url": "https://test-video.frogcool.com/public/cover/1_032721364e.webp",
                    "status": "1",
                    "frog_id": "8993787220",
                    "telphone": "13214789633"
                },
                "sort": [
                    3,
                    9223372036854775807,
                    11,
                    10,
                    9223372036854775807
                ]
            },
            {
                "_index": "user_auth_user_info",
                "_type": "_doc",
                "_id": "960",
                "_score": null,
                "_source": {
                    "user_id": 960,
                    "e_name": "sice96",
                    "head_img_url": "https://test-video.frogcool.com/public/cover/2023-02/AND_CROP_AVATAR_CROP_1606307138719_960.webp",
                    "status": "1",
                    "frog_id": "3245812054",
                    "telphone": "18618345768",
                    "data": [
                        {
                            "del_status": "0",
                            "cards_user_name": "tiktok",
                            "cards_no": 2
                        },
                        {
                            "del_status": "0",
                            "cards_user_name": "huh",
                            "cards_no": 3
                        },
                        {
                            "del_status": "0",
                            "cards_user_name": "YouTub",
                            "cards_no": 1
                        }
                    ]
                },
                "sort": [
                    6,
                    3,
                    11,
                    10,
                    1
                ]
            },
            {
                "_index": "user_auth_user_info",
                "_type": "_doc",
                "_id": "36424723",
                "_score": null,
                "_source": {
                    "user_id": 36424723,
                    "e_name": "huhshhs",
                    "head_img_url": "https://d44drdgk9m0.cloudfront.net/frog/userAvatar/4.png",
                    "status": "1",
                    "frog_id": "3060688347",
                    "telphone": ""
                },
                "sort": [
                    7,
                    9223372036854775807,
                    0,
                    10,
                    9223372036854775807
                ]
            }
        ]
    }
}

I have this query now I need help with the sorting. Instead of the e_name and cards_user_name I want to be able to merge them so which value contains the search string “huh” sort it on that value. Ie in the results it should not be sorted on sice96 but the huh value in the cards_user_name. How would I do this

I think you’d fix that by adding _score to the list of sort criteria. E.g.:

  "sort": [
    "_score",
    {"e_name.length": {"order": "asc"}},
    {"data.cards_user_name.length"...

That would put documents with higher score (e.g. matching huh before those that don’t).