+ #[doc = "[Msearch API](https://www.elastic.co/guide/en/elasticsearch/reference/8.15/search-multi-search.html)\n\nAllows to execute several search operations in one request.\n\n# Examples\n\nTo make a multi-search request, specify the headers and bodies\nfor the search requests in the body. The body accepts a\n`Vec<T>` where `T` implements the [Body] trait.\n\n```rust,no_run\n# use elasticsearch::{Elasticsearch, Error, MsearchParts};\n# use serde_json::{json, Value};\n# async fn doc() -> Result<(), Box<dyn std::error::Error>> {\nlet client = Elasticsearch::default();\n\nfn print_hits(hits: &[Value]) {\n for hit in hits {\n println!(\n \"id: '{}', source: '{}', score: '{}'\",\n hit[\"_id\"].as_str().unwrap(),\n hit[\"_source\"],\n hit[\"_score\"].as_f64().unwrap()\n );\n }\n}\n\nlet msearch_response = client\n .msearch(MsearchParts::None)\n .body::<JsonBody<Value>>(vec![\n json!({\"index\":\"cat_food\"}).into(),\n json!({\"query\":{\"term\":{\"name\":{\"term\":\"Whiskers\"}}}}).into(),\n json!({\"index\":\"cat_food\"}).into(),\n json!({\"query\":{\"term\":{\"name\":{\"term\":\"Chicken\"}}}}).into(),\n json!({\"index\":\"cat_food\"}).into(),\n json!({\"query\":{\"term\":{\"name\":{\"term\":\"Turkey\"}}}}).into(),\n ])\n .send()\n .await?;\n\nlet json: Value = msearch_response.json().await?;\n\n// iterate over the responses\nfor response in json[\"responses\"]\n .as_array()\n .into_iter()\n{\n print_hits(response[\"hits\"][\"hits\"].as_array().unwrap());\n}\n \n# Ok(())\n# }\n```"]
0 commit comments