I need to show a catalog containing only the latest version of each app, sorted by app title

Dear Community,

Please help me out. I have an app catalogue page running with ES query. Each app has a semantic version and title in multiple language, and the app title can be different per version, then finally, I need to show a catalog containing only the latest version of each apps sorted by the app title of requested language.

So here is my sample data:

PUT trial_index/_doc/1
{   
    "version": "1.2.10",                    
    "major_version": 1.0,
    "minor_version": 2.0,                                        
    "patch_version": 10.0,
    "default_language": "english",                    
    "language_data": {
        "french": {                            
            "app_title": "app_1_title_revised_in_french"
        },                        
        "english": {                            
            "app_title": "app_1_title_revised"
        },                        
        "spanish": {                          
            "app_title": "app_1_title_revised_in_spanish"
        }
    },                    
    "unique_app_id": "app_no_1"
}

PUT trial_index/_doc/2
{   
    "version": "1.2.3",                    
    "major_version": 1.0,
    "minor_version": 2.0,                                        
    "patch_version": 3.0,
    "default_language": "english",                    
    "language_data": {
        "french": {                            
            "app_title": "app_1_title_in_french"                            
        },                        
        "english": {                            
            "app_title": "app_1_title"
        },                        
        "spanish": {                          
            "app_title": "app_1_title_in_spanish"
        }
    },                    
    "unique_app_id": "app_no_1"
}

You can see the version 1.2.3 and 1.2.10 have all different title. I need to show the latest version 1.2.10 in the catalogue, however, my closest sorting effort below generates a bucket per title, so it returns each version as if they are two different apps. How do I fix this?

GET trial_index/_search
{
    "from": 0,
    "size": 0,
    "aggregations": {
        "my_pager": {
            "composite": {
                "size": 100,
                "sources": [
                    {
                        "sort_by_title": {
                            "terms": {
                                "script": {
                                    "source": "def source = params['_source'];\nif (source['language_data'].containsKey(params.requestedCode)) {\n\treturn source['language_data'][params.requestedCode]['app_title']\n} else {\n\treturn source['language_data'][doc['default_language.keyword'].value]['app_title']\n}",
                                    "lang": "painless",
                                    "params": {
                                        "requestedCode": "french"
                                    }
                                },
                                "missing_bucket": true,
                                "order": "asc"
                            }
                        }
                    },
                    {
                        "page_key": {
                            "terms": {
                                "field": "unique_app_id.keyword",
                                "missing_bucket": false,
                                "order": "asc"
                            }
                        }
                    }
                ]
            },
            "aggregations": {
                "application": {
                    "terms": {
                        "field": "unique_app_id.keyword",
                        "size": 10,
                        "min_doc_count": 1,
                        "shard_min_doc_count": 0,
                        "show_term_doc_count_error": false,
                        "order": [
                            {
                                "_count": "desc"
                            },
                            {
                                "_key": "asc"
                            }
                        ]
                    },
                    "aggregations": {
                        "latest_version": {
                            "top_hits": {
                                "from": 0,
                                "size": 1,
                                "version": false,
                                "seq_no_primary_term": false,
                                "explain": false,
                                "_source": {
                                    "includes": [
                                        "unique_app_id",
                                        "version"
                                    ],
                                    "excludes": []
                                },
                                "script_fields": {
                                    "default_language": {
                                        "script": {
                                            "source": "[params['_source']['language_data'].containsKey(params.requestedCode) ? (params['_source']['language_data'][params.requestedCode]['app_title']) : (params['_source']['language_data'][doc['default_language.keyword'].value]['app_title'])]",
                                            "lang": "painless",
                                            "params": {
                                                "requestedCode": "french"
                                            }
                                        },
                                        "ignore_failure": false
                                    }
                                },
                                "sort": [
                                    {
                                        "major_version": {
                                            "order": "desc"
                                        }
                                    },
                                    {
                                        "minor_version": {
                                            "order": "desc"
                                        }
                                    },
                                    {
                                        "patch_version": {
                                            "order": "desc"
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }
    }
}

Please kindly help

Anyone? Please let me know if there is anything to improve my question.