diff --git a/meilisearch-http/src/routes/indexes/documents.rs b/meilisearch-http/src/routes/indexes/documents.rs index 2f6746c90..e5eb15fbf 100644 --- a/meilisearch-http/src/routes/indexes/documents.rs +++ b/meilisearch-http/src/routes/indexes/documents.rs @@ -8,9 +8,10 @@ use meilisearch_lib::milli::update::IndexDocumentsMethod; use meilisearch_lib::MeiliSearch; use once_cell::sync::Lazy; use serde::Deserialize; -use serde_json::Value; +use serde_json::{json, Value}; use tokio::sync::mpsc; +use crate::analytics::Analytics; use crate::error::{MeilisearchHttpError, ResponseError}; use crate::extractors::authentication::{policies::*, GuardedData}; use crate::extractors::payload::Payload; @@ -131,15 +132,29 @@ pub async fn add_documents( params: web::Query, body: Payload, req: HttpRequest, + analytics: web::Data<&'static dyn Analytics>, ) -> Result { debug!("called with params: {:?}", params); + let content_type = req + .headers() + .get("Content-type") + .map(|s| s.to_str().unwrap_or("unkown")); + let params = params.into_inner(); + + analytics.publish( + "Documents Added".to_string(), + json!({ + "payload_type": content_type, + "with_primary_key": params.primary_key, + "index_creation": meilisearch.get_index(path.index_uid.clone()).await.is_ok(), + }), + ); + document_addition( - req.headers() - .get("Content-type") - .map(|s| s.to_str().unwrap_or("unkown")), + content_type, meilisearch, - path.into_inner().index_uid, - params.into_inner().primary_key, + path.index_uid.clone(), + params.primary_key, body, IndexDocumentsMethod::ReplaceDocuments, ) diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index 382147f31..092bd1186 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -302,6 +302,7 @@ mod test { impl_is_policy! {A B} impl_is_policy! {A B C} impl_is_policy! {A B C D} + impl_is_policy! {A B C D E} /// Emits a compile error if a route doesn't have the correct authentication policy. ///