Skip to main content

parse_mget

Function parse_mget 

Source
pub fn parse_mget(body: &[u8]) -> Result<Vec<MgetItem>, RewriteError>
Expand description

Parses an _mget body into its ordered fetches.

Accepts both shapes OpenSearch supports: {"docs":[{"_index":…,"_id":…},…]} and {"ids":["1","2"]} (index defaulted from the URL).

§Errors

Returns RewriteError::InvalidJson if the body is not valid JSON, RewriteError::NotAnObject if it is not an object carrying docs or ids, or RewriteError::MalformedBulkAction if a docs entry is not an object with a string _id (or an ids entry is not a string).

§Examples

use osproxy_rewrite::parse_mget;

let body = br#"{"docs":[{"_index":"a","_id":"1"},{"_id":"2"}]}"#;
let items = parse_mget(body).unwrap();
assert_eq!(items.len(), 2);
assert_eq!(items[0].index.as_deref(), Some("a"));
assert_eq!(items[1].id, "2");