Bug: refactor(opensearch): Add Error Handling for Empty Query and Filters in Request




**Description:**
> **Problem:**
> Currently, there is no validation to check whether both the `query` and `filters` in the request are empty. This can lead to the processing of invalid requests, which may cause unexpected behavior or errors in the application.
>
> **Recommended Solution:**
> Implement a validation check that ensures the `query` field is not empty or consisting only of whitespace, and that the `filters` field is not entirely `None` or containing only `None` values for all its fields. If both conditions are true, an error should be returned.

diff --git a/crates/analytics/src/opensearch.rs b/crates/analytics/src/opensearch.rs
index 05f89b655cf..1031c815448 100644
--- a/crates/analytics/src/opensearch.rs
+++ b/crates/analytics/src/opensearch.rs
@@ -71,6 +71,8 @@ pub enum OpenSearchError {
     ConnectionError,
     #[error("Opensearch NON-200 response content: '{0}'")]
     ResponseNotOK(String),
+    #[error("Opensearch bad request error")]
+    BadRequestError(String),
     #[error("Opensearch response error")]
     ResponseError,
     #[error("Opensearch query building error")]
@@ -98,6 +100,9 @@ impl ErrorSwitch<ApiErrorResponse> for OpenSearchError {
                 "Connection error",
                 None,
             )),
+            Self::BadRequestError(response) => {
+                ApiErrorResponse::BadRequest(ApiError::new("IR", 1, response.to_string(), None))
+            }
             Self::ResponseNotOK(response) => ApiErrorResponse::InternalServerError(ApiError::new(
                 "IR",
                 1,
diff --git a/crates/analytics/src/search.rs b/crates/analytics/src/search.rs
index a5bd117bd63..68285afc8bb 100644
--- a/crates/analytics/src/search.rs
+++ b/crates/analytics/src/search.rs
@@ -16,6 +16,17 @@ pub async fn msearch_results(
     merchant_id: &String,
     indexes: Vec<SearchIndex>,
 ) -> CustomResult<Vec<GetSearchResponse>, OpenSearchError> {
+    if req.query.trim().is_empty()
+        && req
+            .filters
+            .as_ref()
+            .map_or(true, |filters| filters.is_all_none())
+    {
+        return Err(OpenSearchError::BadRequestError(
+            "Both query and filters are empty".to_string(),
+        )
+        .into());
+    }
     let mut query_builder =
         OpenSearchQueryBuilder::new(OpenSearchQuery::Msearch(indexes.clone()), req.query);
 
diff --git a/crates/api_models/src/analytics/search.rs b/crates/api_models/src/analytics/search.rs
index d1af00de569..f27af75936d 100644
--- a/crates/api_models/src/analytics/search.rs
+++ b/crates/api_models/src/analytics/search.rs
@@ -10,6 +10,15 @@ pub struct SearchFilters {
     pub customer_email: Option<Vec<HashedString<common_utils::pii::EmailStrategy>>>,
     pub search_tags: Option<Vec<HashedString<WithType>>>,
 }
+impl SearchFilters {
+    pub fn is_all_none(&self) -> bool {
+        self.payment_method.is_none()
+            && self.currency.is_none()
+            && self.status.is_none()
+            && self.customer_email.is_none()
+            && self.search_tags.is_none()
+    }
+}
 
 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
 #[serde(rename_all = "camelCase")]

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

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

## Description
<!-- Describe your changes in detail -->
> Implement a validation check that ensures the `query` field is not empty or consisting only of whitespace, and that the `filters` field is not entirely `None` or containing only `None` values for all its fields. If both conditions are true, an error should be returned.


### 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).
-->


## 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)?
-->
```bash
curl 'http://localhost:8080/analytics/v1/search' \
  -H 'sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTEzYWUyODItN2I1NS00MGMwLWFiZGMtYjdiMGYzNDNkMTQ2IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzIxNjQyOTczIiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTcyMjE1NzQ0Miwib3JnX2lkIjoib3JnX2drZHNlNDBIdGx6RkNob2NpU0NzIn0.Fmrxsp-emKQ-67EpcJolMf7EyeDdjl4DcwbmnVSprMU' \
  -H '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' \
  -H 'Content-Type: application/json' \
  -H 'Referer: http://localhost:9000/' \
  -H 'api-key: hyperswitch' \
  -H 'sec-ch-ua-platform: "macOS"' \
  --data-raw '{"query":"dvs"}'
```
- An empty query with an unknown filter produces an error.
- An empty filter with whitespaces in the query produces an error.
- An empty query with a known filter should give results.
<img width="1304" alt="image" src="https://github.com/user-attachments/assets/013b397e-72f8-489d-af94-b04441708946">


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

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