Bug: fix(opensearch): Sort the global search results in descending order



When searching using global search, the results are not sorted. It would be better if they are sorted in newest to oldest order.
diff --git a/crates/analytics/src/opensearch.rs b/crates/analytics/src/opensearch.rs
index e74622a054a..f3dd5eea441 100644
--- a/crates/analytics/src/opensearch.rs
+++ b/crates/analytics/src/opensearch.rs
@@ -518,7 +518,19 @@ impl OpenSearchQueryBuilder {
                 let mut final_query = Map::new();
                 final_query.insert("bool".to_string(), json!({ "filter": updated_query }));
 
-                let payload = json!({ "query": Value::Object(final_query) });
+                let mut sort_obj = Map::new();
+                sort_obj.insert(
+                    "@timestamp".to_string(),
+                    json!({
+                        "order": "desc"
+                    }),
+                );
+                let payload = json!({
+                    "query": Value::Object(final_query),
+                    "sort": [
+                        Value::Object(sort_obj)
+                    ]
+                });
                 payload
             })
             .collect::<Vec<Value>>())

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [x] Bugfix
- [ ] New feature
- [x] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
When searching using global search, the results are not sorted. Sorted the results now in newest to oldest order.

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->
Enhance search experience by listing the results in newest to oldest order.
Raised by this issue: [https://github.com/juspay/hyperswitch-control-center/issues/1131](https://github.com/juspay/hyperswitch-control-center/issues/1131)

## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
- Hit the `/search` API
```bash
curl --location 'http://localhost:8080/analytics/v1/search' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36' \
--header 'api-key: hyperswitch' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiYjc2ZDVmZjMtNGI1ZS00OTMyLTk1ZDItNmE3MTEyZWZiNTNlIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzIxODE1MjkwIiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTcyMzc4ODI2OSwib3JnX2lkIjoib3JnX3VFNk1LbExxalU5MWlGUEVGck1rIiwicHJvZmlsZV9pZCI6bnVsbH0.AFuIb8uXW92J7V_0-nbPCHLDnl-l4CxSjBYIZNoW5KE' \
--header 'sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data-raw '{
    "query": "usd",
    "filters": {
        "customer_email" : [
            "test@test14.com"
        ]

    },
    "timeRange": {
        "startTime": "2024-08-14T00:30:00Z",
        "endTime": "2024-08-14T18:45:00Z"
    }
}'
```
Results should now appear sorted in descending order
```bash
{
    "@timestamp": "2024-08-14T07:25:02Z",
    "active_attempt_id": "pay_nvWZxyMCOeA5UmlfRqKX_1",
    "amount": 6540,
    "amount_captured": 6540,
    "attempt_count": 1,
    "billing_details": null,
    "business_country": null,
    "business_label": "default",
    "clickhouse_database": "default",
    "client_secret": "pay_nvWZxyMCOeA5UmlfRqKX_secret_GgDrUrwfTVSHJjTbRUDi",
    "connector_id": null,
    "created_at": 1723620302,
    "currency": "USD",
    "customer_email": "f6cd0753a831880835a0e0d23136ef66318d8303605bd37fa80b4ecf248bd303",
    "customer_id": "StripeCustomer",
    "description": "Its my first payment request",
    "feature_metadata": {
        "redirect_response": null,
        "search_tags": [
            "9c202f2fabd12f758a12b449944f5cdaeadf39132680667543033158023bc805",
            "ffd1c37eb18f3459e3da6f21f739866bce89a334061c248656cb71d83d2375f4"
        ]
    },
    "headers": {},
    "last_synced": 1723620302,
    "merchant_id": "merchant_1721815290",
    "merchant_order_reference_id": null,
    "metadata": "{\"data2\":\"camel\",\"login_date\":\"2019-09-10T10:11:12Z\",\"new_customer\":\"true\"}",
    "modified_at": 1723620304,
    "off_session": null,
    "payment_confirm_source": null,
    "payment_id": "pay_nvWZxyMCOeA5UmlfRqKX",
    "profile_id": "pro_ZTGBrEwlRmTyzKFpnV9Z",
    "return_url": "https://google.com/",
    "setup_future_usage": null,
    "shipping_details": null,
    "sign_flag": 1,
    "source_type": "kafka",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "status": "succeeded",
    "tenant_id": "public",
    "timestamp": "2024-08-14T07:25:02Z"
},
{
    "@timestamp": "2024-08-14T06:46:30Z",
    "active_attempt_id": "pay_LzTCv5OHAApqOU43CxIm_1",
    "amount": 6540,
    "amount_captured": 6540,
    "attempt_count": 1,
    "billing_details": null,
    "business_country": null,
    "business_label": "default",
    "clickhouse_database": "default",
    "client_secret": "pay_LzTCv5OHAApqOU43CxIm_secret_AwCmBtbalAU85SWJGs0W",
    "connector_id": null,
    "created_at": 1723617990,
    "currency": "USD",
    "customer_email": "f6cd0753a831880835a0e0d23136ef66318d8303605bd37fa80b4ecf248bd303",
    "customer_id": "StripeCustomer",
    "description": "Its my first payment request",
    "feature_metadata": {
        "redirect_response": null,
        "search_tags": [
            "9c202f2fabd12f758a12b449944f5cdaeadf39132680667543033158023bc805",
            "ffd1c37eb18f3459e3da6f21f739866bce89a334061c248656cb71d83d2375f4"
        ]
    },
    "headers": {},
    "last_synced": 1723617990,
    "merchant_id": "merchant_1721815290",
    "merchant_order_reference_id": null,
    "metadata": "{\"data2\":\"camel\",\"login_date\":\"2019-09-10T10:11:12Z\",\"new_customer\":\"true\"}",
    "modified_at": 1723617991,
    "off_session": null,
    "payment_confirm_source": null,
    "payment_id": "pay_LzTCv5OHAApqOU43CxIm",
    "profile_id": "pro_ZTGBrEwlRmTyzKFpnV9Z",
    "return_url": "https://google.com/",
    "setup_future_usage": null,
    "shipping_details": null,
    "sign_flag": 1,
    "source_type": "kafka",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "status": "succeeded",
    "tenant_id": "public",
    "timestamp": "2024-08-14T06:46:30Z"
},
{
    "@timestamp": "2024-08-14T06:45:39Z",
    "active_attempt_id": "pay_djRThD60oIoz3jucMvQd_1",
    "amount": 6540,
    "amount_captured": 6540,
    "attempt_count": 1,
    "billing_details": null,
    "business_country": null,
    "business_label": "default",
    "clickhouse_database": "default",
    "client_secret": "pay_djRThD60oIoz3jucMvQd_secret_16zPOM5hVp7uY1Tjt6zW",
    "connector_id": null,
    "created_at": 1723617939,
    "currency": "USD",
    "customer_email": "f6cd0753a831880835a0e0d23136ef66318d8303605bd37fa80b4ecf248bd303",
    "customer_id": "StripeCustomer",
    "description": "Its my first payment request",
    "feature_metadata": {
        "redirect_response": null,
        "search_tags": [
            "9c202f2fabd12f758a12b449944f5cdaeadf39132680667543033158023bc805",
            "ffd1c37eb18f3459e3da6f21f739866bce89a334061c248656cb71d83d2375f4"
        ]
    },
    "headers": {},
    "last_synced": 1723617939,
    "merchant_id": "merchant_1721815290",
    "merchant_order_reference_id": null,
    "metadata": "{\"data2\":\"camel\",\"login_date\":\"2019-09-10T10:11:12Z\",\"new_customer\":\"true\"}",
    "modified_at": 1723617941,
    "off_session": null,
    "payment_confirm_source": null,
    "payment_id": "pay_djRThD60oIoz3jucMvQd",
    "profile_id": "pro_ZTGBrEwlRmTyzKFpnV9Z",
    "return_url": "https://google.com/",
    "setup_future_usage": null,
    "shipping_details": null,
    "sign_flag": 1,
    "source_type": "kafka",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "status": "succeeded",
    "tenant_id": "public",
    "timestamp": "2024-08-14T06:45:39Z"
},
```
<img width="769" alt="Screenshot 2024-08-14 at 1 03 32 PM" src="https://github.com/user-attachments/assets/6c275ea3-4fee-44d6-ad38-a96300e6151a">

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
