Skip to main content

parse_msearch

Function parse_msearch 

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

Parses an _msearch NDJSON body into its ordered searches.

Each search is a header line followed by a body line. The header’s index may be a string or the first entry of an array (OpenSearch accepts both); any other shape leaves the index defaulted to the URL.

§Errors

Returns RewriteError::InvalidJson if a header or body line is not valid JSON, or RewriteError::MalformedBulkAction if a header line has no following body line.

§Examples

use osproxy_rewrite::parse_msearch;

let body = b"{\"index\":\"a\"}\n{\"query\":{\"match_all\":{}}}\n";
let items = parse_msearch(body).unwrap();
assert_eq!(items.len(), 1);
assert_eq!(items[0].index.as_deref(), Some("a"));