mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 09:38:33 +08:00
feat(opensearch): add additional global search filters and create sessionizer indexes for local (#6352)
This commit is contained in:
@ -42,6 +42,10 @@ pub struct OpenSearchIndexes {
|
||||
pub payment_intents: String,
|
||||
pub refunds: String,
|
||||
pub disputes: String,
|
||||
pub sessionizer_payment_attempts: String,
|
||||
pub sessionizer_payment_intents: String,
|
||||
pub sessionizer_refunds: String,
|
||||
pub sessionizer_disputes: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
|
||||
@ -81,6 +85,10 @@ impl Default for OpenSearchConfig {
|
||||
payment_intents: "hyperswitch-payment-intent-events".to_string(),
|
||||
refunds: "hyperswitch-refund-events".to_string(),
|
||||
disputes: "hyperswitch-dispute-events".to_string(),
|
||||
sessionizer_payment_attempts: "sessionizer-payment-attempt-events".to_string(),
|
||||
sessionizer_payment_intents: "sessionizer-payment-intent-events".to_string(),
|
||||
sessionizer_refunds: "sessionizer-refund-events".to_string(),
|
||||
sessionizer_disputes: "sessionizer-dispute-events".to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -219,6 +227,14 @@ impl OpenSearchClient {
|
||||
SearchIndex::PaymentIntents => self.indexes.payment_intents.clone(),
|
||||
SearchIndex::Refunds => self.indexes.refunds.clone(),
|
||||
SearchIndex::Disputes => self.indexes.disputes.clone(),
|
||||
SearchIndex::SessionizerPaymentAttempts => {
|
||||
self.indexes.sessionizer_payment_attempts.clone()
|
||||
}
|
||||
SearchIndex::SessionizerPaymentIntents => {
|
||||
self.indexes.sessionizer_payment_intents.clone()
|
||||
}
|
||||
SearchIndex::SessionizerRefunds => self.indexes.sessionizer_refunds.clone(),
|
||||
SearchIndex::SessionizerDisputes => self.indexes.sessionizer_disputes.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,6 +340,36 @@ impl OpenSearchIndexes {
|
||||
))
|
||||
})?;
|
||||
|
||||
when(
|
||||
self.sessionizer_payment_attempts.is_default_or_empty(),
|
||||
|| {
|
||||
Err(ApplicationError::InvalidConfigurationValueError(
|
||||
"Opensearch Sessionizer Payment Attempts index must not be empty".into(),
|
||||
))
|
||||
},
|
||||
)?;
|
||||
|
||||
when(
|
||||
self.sessionizer_payment_intents.is_default_or_empty(),
|
||||
|| {
|
||||
Err(ApplicationError::InvalidConfigurationValueError(
|
||||
"Opensearch Sessionizer Payment Intents index must not be empty".into(),
|
||||
))
|
||||
},
|
||||
)?;
|
||||
|
||||
when(self.sessionizer_refunds.is_default_or_empty(), || {
|
||||
Err(ApplicationError::InvalidConfigurationValueError(
|
||||
"Opensearch Sessionizer Refunds index must not be empty".into(),
|
||||
))
|
||||
})?;
|
||||
|
||||
when(self.sessionizer_disputes.is_default_or_empty(), || {
|
||||
Err(ApplicationError::InvalidConfigurationValueError(
|
||||
"Opensearch Sessionizer Disputes index must not be empty".into(),
|
||||
))
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,6 +92,44 @@ pub async fn msearch_results(
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
if let Some(connector) = filters.connector {
|
||||
if !connector.is_empty() {
|
||||
query_builder
|
||||
.add_filter_clause("connector.keyword".to_string(), connector.clone())
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
if let Some(payment_method_type) = filters.payment_method_type {
|
||||
if !payment_method_type.is_empty() {
|
||||
query_builder
|
||||
.add_filter_clause(
|
||||
"payment_method_type.keyword".to_string(),
|
||||
payment_method_type.clone(),
|
||||
)
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
if let Some(card_network) = filters.card_network {
|
||||
if !card_network.is_empty() {
|
||||
query_builder
|
||||
.add_filter_clause("card_network.keyword".to_string(), card_network.clone())
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
if let Some(card_last_4) = filters.card_last_4 {
|
||||
if !card_last_4.is_empty() {
|
||||
query_builder
|
||||
.add_filter_clause("card_last_4.keyword".to_string(), card_last_4.clone())
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
if let Some(payment_id) = filters.payment_id {
|
||||
if !payment_id.is_empty() {
|
||||
query_builder
|
||||
.add_filter_clause("payment_id.keyword".to_string(), payment_id.clone())
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
if let Some(time_range) = req.time_range {
|
||||
@ -217,6 +255,44 @@ pub async fn search_results(
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
if let Some(connector) = filters.connector {
|
||||
if !connector.is_empty() {
|
||||
query_builder
|
||||
.add_filter_clause("connector.keyword".to_string(), connector.clone())
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
if let Some(payment_method_type) = filters.payment_method_type {
|
||||
if !payment_method_type.is_empty() {
|
||||
query_builder
|
||||
.add_filter_clause(
|
||||
"payment_method_type.keyword".to_string(),
|
||||
payment_method_type.clone(),
|
||||
)
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
if let Some(card_network) = filters.card_network {
|
||||
if !card_network.is_empty() {
|
||||
query_builder
|
||||
.add_filter_clause("card_network.keyword".to_string(), card_network.clone())
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
if let Some(card_last_4) = filters.card_last_4 {
|
||||
if !card_last_4.is_empty() {
|
||||
query_builder
|
||||
.add_filter_clause("card_last_4.keyword".to_string(), card_last_4.clone())
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
if let Some(payment_id) = filters.payment_id {
|
||||
if !payment_id.is_empty() {
|
||||
query_builder
|
||||
.add_filter_clause("payment_id.keyword".to_string(), payment_id.clone())
|
||||
.switch()?;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
if let Some(time_range) = search_req.time_range {
|
||||
|
||||
Reference in New Issue
Block a user