AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(query): match a range against every value of a multi-valued field (#1750) (#1776)
Amartya Vikram Singhcd24652390a7
diff --git a/engine/crates/xerj-engine/src/aggs.rs b/engine/crates/xerj-engine/src/aggs.rsindex a6f6d06b5..8ab8bcede 100644--- a/engine/crates/xerj-engine/src/aggs.rs+++ b/engine/crates/xerj-engine/src/aggs.rs@@ -7323,97 +7323,108 @@ pub(crate) fn doc_matches_filter(doc: &Value, filter: &Value) -> bool {if values.is_empty() {return false;}- // Try numeric range check.- let num_val: Option<f64> = values.first().and_then(|s| s.parse().ok());- if let Some(n) = num_val {- if let Some(gte) = bounds.get("gte").and_then(Value::as_f64) {- if n < gte {- return false;- }- }- if let Some(gt) = bounds.get("gt").and_then(Value::as_f64) {- if n <= gt {- return false;- }- }- if let Some(lte) = bounds.get("lte").and_then(Value::as_f64) {- if n > lte {- return false;- }- }- if let Some(lt) = bounds.get("lt").and_then(Value::as_f64) {- if n >= lt {- return false;- }- }- } else {- // Non-numeric value — a date or a keyword. Before- // this branch existed the `if let Some(n)` above- // simply fell through, so a range over a DATE field- // matched **every** document unconditionally: no- // bound was ever compared. That silently inflated- // any date-filtered agg served over memtable-- // resident docs (measured: a one-day window on a- // 1.12 M-doc index reported 135,972 hits instead of- // 40,000 — the whole 95,972-doc memtable admitted- // wholesale).- //- // Dates compare as instants (so `2026-06-17` and- // `2026-06-17T00:00:00.000Z` are the same point);- // anything that is not a date on both sides falls- // back to lexicographic comparison, which is ES's- // keyword-range semantics.- let raw = Value::String(values[0].clone());- let doc_ms = parse_date_ms(&raw);- let bound_ms =- |k: &str| -> Option<i64> { bounds.get(k).and_then(parse_date_ms) };- if let Some(v) = doc_ms {- if let Some(b) = bound_ms("gte") {- if v < b {+ // #1750 — a multi-valued field matches when ANY one+ // of its values satisfies EVERY bound (Lucene's+ // per-value semantics). Checking only `values[0]`+ // dropped a doc whose in-range value was not first.+ let in_range = |value: &str| -> bool {+ // Try numeric range check.+ let num_val: Option<f64> = value.parse().ok();+ if let Some(n) = num_val {+ if let Some(gte) = bounds.get("gte").and_then(Value::as_f64) {+ if n < gte {return false;}}- if let Some(b) = bound_ms("gt") {- if v <= b {+ if let Some(gt) = bounds.get("gt").and_then(Value::as_f64) {+ if n <= gt {return false;}}- if let Some(b) = bound_ms("lte") {- if v > b {+ if let Some(lte) = bounds.get("lte").and_then(Value::as_f64) {+ if n > lte {return false;}}- if let Some(b) = bound_ms("lt") {- if v >= b {+ if let Some(lt) = bounds.get("lt").and_then(Value::as_f64) {+ if n >= lt {return false;}}} else {- let s = values[0].as_str();- let bound_str = |k: &str| -> Option<&str> {- bounds.get(k).and_then(Value::as_str)+ // Non-numeric value — a date or a keyword. Before+ // this branch existed the `if let Some(n)` above+ // simply fell through, so a range over a DATE field+ // matched **every** document unconditionally: no+ // bound was ever compared. That silently inflated+ // any date-filtered agg served over memtable-+ // resident docs (measured: a one-day window on a+ // 1.12 M-doc index reported 135,972 hits instead of+ // 40,000 — the whole 95,972-doc memtable admitted+ // wholesale).+ //+ // Dates compare as instants (so `2026-06-17` and+ // `2026-06-17T00:00:00.000Z` are the same point);+ // anything that is not a date on both sides falls+ // back to lexicographic comparison, which is ES's+ // keyword-range semantics.+ let raw = Value::String(value.to_string());+ let doc_ms = parse_date_ms(&raw);+ let bound_ms = |k: &str| -> Option<i64> {+ bounds.get(k).and_then(parse_date_ms)};- if let Some(b) = bound_str("gte") {- if s < b {- return false;+ if let Some(v) = doc_ms {+ if let Some(b) = bound_ms("gte") {+ if v < b {+ return false;+ }}- }- if let Some(b) = bound_str("gt") {- if s <= b {- return false;+ if let Some(b) = bound_ms("gt") {+ if v <= b {+ return false;+ }}- }- if let Some(b) = bound_str("lte") {- if s > b {- return false;+ if let Some(b) = bound_ms("lte") {+ if v > b {+ return false;+ }}- }- if let Some(b) = bound_str("lt") {- if s >= b {- return false;+ if let Some(b) = bound_ms("lt") {+ if v >= b {+ return false;+ }+ }+ } else {+ let s = value;+ let bound_str = |k: &str| -> Option<&str> {+ bounds.get(k).and_then(Value::as_str)+ };+ if let Some(b) = bound_str("gte") {+ if s < b {+ return false;+ }+ }+ if let Some(b) = bound_str("gt") {+ if s <= b {+ return false;+ }+ }+ if let Some(b) = bound_str("lte") {+ if s > b {+ return false;+ }+ }+ if let Some(b) = bound_str("lt") {+ if s >= b {+ return false;+ }}}}+ true+ };+ if !values.iter().any(|v| in_range(v)) {+ return false;}}}diff --git a/engine/crates/xerj-engine/src/index.rs b/engine/crates/xerj-engine/src/index.rsindex 1391f358e..0dfd62d41 100644--- a/engine/crates/xerj-engine/src/index.rs+++ b/engine/crates/xerj-engine/src/index.rs@@ -28033,6 +28033,15 @@ impl Index {(None, None) => (f64::INFINITY, true),};let field_str = field.as_str();+ // #1750 — the memtable numeric column keeps only an array's+ // first element, so `for_each_numeric_value` below would count a+ // multi-valued doc by that element alone. Abandon to the counting+ // scan, whose matcher checks every element. (Segments already+ // abandon: a field that is an array anywhere in a segment gets no+ // dv column, which is the `None` arm below.)+ if self.memtable.range_column_unusable(field_str) {+ return None;+ }let segments_dir = self.data_dir.join("segments");let mut seg_matches: u64 = 0;@@ -46126,69 +46135,12 @@ pub(crate) fn doc_matches_query_typed(q: &QueryNode, source: &Value, schema: &Sclte,lt,..- } => {- let doc_val = get_field_value(source, field);- match doc_val {- Some(dv) => {- // Check if we're comparing IP addresses.- let doc_is_ip = dv- .as_str()- .map(|s| parse_ip_to_u128(s).is_some())- .unwrap_or(false);- let bound_is_ip = gte- .as_ref()- .or(gt.as_ref())- .or(lte.as_ref())- .or(lt.as_ref())- .and_then(|b| b.as_str())- .map(|s| parse_ip_to_u128(s).is_some())- .unwrap_or(false);-- if doc_is_ip && bound_is_ip {- // IP address comparison using numeric ordering.- let doc_ip = parse_ip_to_u128(dv.as_str().unwrap_or("")).unwrap_or(0);- let passes_lower = match (gte, gt) {- (Some(b), _) => {- let bound = b.as_str().and_then(parse_ip_to_u128).unwrap_or(0);- doc_ip >= bound- }- (None, Some(b)) => {- let bound = b.as_str().and_then(parse_ip_to_u128).unwrap_or(0);- doc_ip > bound- }- (None, None) => true,- };- let passes_upper = match (lte, lt) {- (Some(b), _) => {- let bound =- b.as_str().and_then(parse_ip_to_u128).unwrap_or(u128::MAX);- doc_ip <= bound- }- (None, Some(b)) => {- let bound =- b.as_str().and_then(parse_ip_to_u128).unwrap_or(u128::MAX);- doc_ip < bound- }- (None, None) => true,- };- passes_lower && passes_upper- } else {- let passes_lower = match (gte, gt) {- (Some(b), _) => json_compare(&dv, b) >= 0,- (None, Some(b)) => json_compare(&dv, b) > 0,- (None, None) => true,- };- let passes_upper = match (lte, lt) {- (Some(b), _) => json_compare(&dv, b) <= 0,- (None, Some(b)) => json_compare(&dv, b) < 0,- (None, None) => true,- };- passes_lower && passes_upper- }- }- None => false,+ } => match get_field_value(source, field) {+ Some(dv) => {+ range_value_matches(&dv, gte.as_ref(), gt.as_ref(), lte.as_ref(), lt.as_ref())}- }+ None => false,+ },QueryNode::Exists { field } => match field.as_str() {"_id" | "_index" | "_seq_no" | "_version" | "_primary_term" => true,@@ -50518,6 +50470,85 @@ fn compute_sort_values(sort_vals}+/// `_source` matcher for one `range` clause against a field value.+///+/// #1750 — a multi-valued field matches when ANY single element satisfies+/// EVERY bound, which is Lucene's per-value point semantics and what ES 8.13+/// returns. Comparing the array itself sent `json_compare` to its serialized+/// text (`["alpha","mid"]`, `[22,8080]`), and because `'['` sorts after every+/// digit and before every lowercase letter, an array passed any numeric/date+/// lower bound, failed any upper bound, and failed a keyword `gte "m"` —+/// whatever its elements were. The bounds are deliberately NOT split across+/// elements: `["2020-01-01","2024-06-01"]` is outside+/// `[2021-01-01, 2023-01-01)` even though one element clears each bound.+/// Nested arrays flatten (ES indexes `[[1,2],3]` as three values) and `null`+/// elements are skipped, as ES does not index them.+fn range_value_matches(+ dv: &Value,+ gte: Option<&Value>,+ gt: Option<&Value>,+ lte: Option<&Value>,+ lt: Option<&Value>,+) -> bool {+ if let Value::Array(arr) = dv {+ return arr+ .iter()+ .any(|elem| !elem.is_null() && range_value_matches(elem, gte, gt, lte, lt));+ }+ // Check if we're comparing IP addresses.+ let doc_is_ip = dv+ .as_str()+ .map(|s| parse_ip_to_u128(s).is_some())+ .unwrap_or(false);+ let bound_is_ip = gte+ .or(gt)+ .or(lte)+ .or(lt)+ .and_then(|b| b.as_str())+ .map(|s| parse_ip_to_u128(s).is_some())+ .unwrap_or(false);++ if doc_is_ip && bound_is_ip {+ // IP address comparison using numeric ordering.+ let doc_ip = parse_ip_to_u128(dv.as_str().unwrap_or("")).unwrap_or(0);+ let passes_lower = match (gte, gt) {+ (Some(b), _) => {+ let bound = b.as_str().and_then(parse_ip_to_u128).unwrap_or(0);+ doc_ip >= bound+ }+ (None, Some(b)) => {+ let bound = b.as_str().and_then(parse_ip_to_u128).unwrap_or(0);+ doc_ip > bound+ }+ (None, None) => true,+ };+ let passes_upper = match (lte, lt) {+ (Some(b), _) => {+ let bound = b.as_str().and_then(parse_ip_to_u128).unwrap_or(u128::MAX);+ doc_ip <= bound+ }+ (None, Some(b)) => {+ let bound = b.as_str().and_then(parse_ip_to_u128).unwrap_or(u128::MAX);+ doc_ip < bound+ }+ (None, None) => true,+ };+ passes_lower && passes_upper+ } else {+ let passes_lower = match (gte, gt) {+ (Some(b), _) => json_compare(dv, b) >= 0,+ (None, Some(b)) => json_compare(dv, b) > 0,+ (None, None) => true,+ };+ let passes_upper = match (lte, lt) {+ (Some(b), _) => json_compare(dv, b) <= 0,+ (None, Some(b)) => json_compare(dv, b) < 0,+ (None, None) => true,+ };+ passes_lower && passes_upper+ }+}+pub(crate) fn get_field_value(source: &Value, field: &str) -> Option<Value> {// Fast path: literal dotted key at the source root (subobjects:false).if let Value::Object(obj) = source {diff --git a/engine/crates/xerj-engine/src/memtable.rs b/engine/crates/xerj-engine/src/memtable.rsindex 268a2d253..ba8a97bca 100644--- a/engine/crates/xerj-engine/src/memtable.rs+++ b/engine/crates/xerj-engine/src/memtable.rs@@ -2379,6 +2379,23 @@ impl ShardedFtsMemtable {self.dv_column_unusable(field)}+ /// True when ANY generation's single-valued numeric column for `field`+ /// cannot answer a `range`: the field has carried an array, and+ /// `push_field` keeps only the array's first element, so a document+ /// whose later element is in range would be missed (#1750). Callers+ /// must fall back to the stored-source scan, whose range matcher checks+ /// every element. Narrower than [`Self::dv_column_unusable`]: whitespace+ /// keyword values do not affect the numeric column.+ pub fn range_column_unusable(&self, field: &str) -> bool {+ self.shards.iter().any(|s| {+ let g = s.read();+ g.active.doc_values.array_fields.contains(field)+ || g.frozen+ .iter()+ .any(|fz| fz.gen.read().doc_values.array_fields.contains(field))+ })+ }+/// DocValues term query — aggregates hits across all shards./// Returns `Some(Vec<(doc_id, local_idx)>)` if any shard matched./// The `local_idx` is shard-local; callers use the doc_id to@@ -2536,6 +2553,12 @@ impl ShardedFtsMemtable {lt: Option<f64>,limit: usize,) -> Option<(Vec<(String, usize)>, u64)> {+ // #1750 — refuse globally, before any shard answers: a shard whose+ // column holds only an array's first element must not be folded into+ // a confident partial total (the #332 shape, for range).+ if self.range_column_unusable(field) {+ return None;+ }// #191 — per-shard bound + global `(seq_no, _id)` narrowing, as in// `doc_values_term_query`.let mut cands: Vec<(u64, String, usize)> = Vec::new();@@ -4394,6 +4417,10 @@ impl FtsMemtable {lte: Option<f64>,lt: Option<f64>,) -> Option<Vec<usize>> {+ // #1750 — the column holds only an array's first element.+ if self.doc_values.array_fields.contains(field) {+ return None;+ }let col = self.doc_values.numeric.get(field)?;let results: Vec<usize> = col.iter()@@ -4494,7 +4521,8 @@ impl FtsMemtable {////// Parameters mirror the ES range query: `gte` / `gt` / `lte` / `lt`.///- /// Returns `None` when the field has no numeric column (fall back to JSON scan).+ /// Returns `None` when the field has no numeric column, or has carried an+ /// array (fall back to JSON scan).pub fn doc_values_range_query(&self,field: &str,@@ -4504,6 +4532,12 @@ impl FtsMemtable {lt: Option<f64>,limit: usize,) -> Option<(Vec<(String, usize)>, u64)> {+ // #1750 — an array-valued field keeps only its first element in the+ // numeric column; bail to the array-aware source scan, as+ // `doc_values_bool_hits` already does for the same predicate.+ if self.doc_values.array_fields.contains(field) {+ return None;+ }let col = self.doc_values.numeric.get(field)?;// Step 1: exact total, bounded doc_id materialisation — the// unbounded id clone was the biggest read-under-write term fordiff --git a/engine/crates/xerj-engine/tests/range_on_multi_valued_field.rs b/engine/crates/xerj-engine/tests/range_on_multi_valued_field.rsnew file mode 100644index 000000000..5d3362acc--- /dev/null+++ b/engine/crates/xerj-engine/tests/range_on_multi_valued_field.rs@@ -0,0 +1,200 @@+//! Issue #1750: a `range` query must match a document when ANY one of a+//! multi-valued field's values is in range — Lucene's per-value semantics, and+//! what Elasticsearch 8.13.4 returns for the same requests.+//!+//! ROOT CAUSE (two independent defects):+//!+//! 1. The `_source` matcher (`doc_matches_query_typed`'s `Range` arm) compared+//! the whole array. `json_compare` has no array arm, so it fell back to the+//! serialized text (`["alpha","mid"]`, `[22,8080]`) and compared that+//! lexicographically: `'['` sorts after every digit and before every+//! lowercase letter, so an array passed any numeric/date lower bound, failed+//! any upper bound, and failed a keyword `gte "m"` — whatever its elements.+//! Every flushed segment reaches this matcher for a multi-valued field+//! (`build_doc_value_columns` emits no column for it), as do memtable+//! keyword/date/ip ranges.+//! 2. The memtable numeric range fast paths (`doc_values_range_query`, and the+//! `try_shortcut_count` count over `for_each_numeric_value`) read a column+//! that keeps only an array's FIRST element, with no `array_fields`+//! bailout — unlike the `term` paths (#423) and the fused bool walk.+//!+//! Every case runs before and after a flush, at `size: 0` (the count+//! shortcuts) and `size: 10` (the hit path), so each path is pinned.++use serde_json::{json, Value};+use tempfile::TempDir;+use xerj_common::config::Config;+use xerj_common::types::{FieldConfig, FieldType, Schema};+use xerj_engine::Engine;+use xerj_query::parse_request;++fn make_engine(dir: &TempDir) -> Engine {+ let mut config = Config::default();+ config.server.data_dir = dir.path().to_str().unwrap().to_string();+ Engine::new(config).expect("engine::new")+}++/// The #1750 reproduction, plus an `ip` field and two negative documents.+async fn seed(engine: &Engine) {+ let mut schema = Schema::empty();+ for (name, ty) in [+ ("tags", FieldType::Keyword),+ ("ports", FieldType::Long),+ ("seen", FieldType::Date),+ ("addr", FieldType::Ip),+ ] {+ schema.fields.push(FieldConfig::new(name, ty));+ }+ engine.create_index("events", schema).expect("create");+ let idx = engine.get_index("events").expect("get");+ let docs = [+ (+ "1",+ json!({"tags": ["alpha", "mid"], "ports": [22, 8080],+ "seen": ["2020-01-01", "2024-06-01"],+ "addr": ["10.0.0.1", "192.168.1.7"]}),+ ),+ (+ "2",+ json!({"tags": "mid", "ports": 443, "seen": "2024-01-01", "addr": "10.0.0.9"}),+ ),+ (+ "3",+ json!({"tags": "zeta", "ports": 5, "seen": ["2030-01-01", "2021-06-01"],+ "addr": "172.16.0.1"}),+ ),+ // Every element below any bound used below: must never match a+ // lower-bounded range (the old matcher admitted every array there).+ (+ "4",+ json!({"tags": ["aa", "ab"], "ports": [1, 2],+ "seen": ["1990-01-01", "1991-01-01"], "addr": ["1.1.1.1", "1.1.1.2"]}),+ ),+ ];+ for (id, doc) in docs {+ idx.index_document(Some(id.to_string()), doc)+ .await+ .expect("index");+ }+}++async fn ids(engine: &Engine, range: Value) -> (u64, u64, Vec<String>) {+ let idx = engine.get_index("events").expect("get");+ let count = idx+ .search(&parse_request(&json!({"query": {"range": range.clone()}, "size": 0})).unwrap())+ .await+ .expect("count search")+ .total+ .value;+ let res = idx+ .search(&parse_request(&json!({"query": {"range": range}, "size": 10})).unwrap())+ .await+ .expect("hit search");+ let mut ids: Vec<String> = res.hits.iter().map(|h| h.id.clone()).collect();+ ids.sort();+ (count, res.total.value, ids)+}++/// `(range body, expected ids)`. Expectations are Elasticsearch 8.13.4's for+/// the #1750 requests; the rest follow the same per-value rule.+fn cases() -> Vec<(Value, Vec<&'static str>)> {+ vec![+ // #1750 verbatim: ES counts 2, 1, 1.+ (json!({"tags": {"gte": "m", "lt": "n"}}), vec!["1", "2"]),+ (json!({"ports": {"gte": 8000, "lte": 9000}}), vec!["1"]),+ (+ json!({"seen": {"gte": "2021-01-01", "lt": "2023-01-01"}}),+ vec!["3"],+ ),+ // Bounds are not split across elements: doc 1 has a value below and+ // a value above this window, but none inside it.+ (json!({"ports": {"gt": 22, "lt": 443}}), vec![]),+ (+ json!({"seen": {"gte": "2021-01-01", "lt": "2024-01-01"}}),+ vec!["3"],+ ),+ // Lower bound only: doc 4's values are all below it.+ (json!({"seen": {"gte": "2024-05-01"}}), vec!["1", "3"]),+ (json!({"ports": {"gte": 100}}), vec!["1", "2"]),+ // Upper bound only: the old matcher never admitted an array here.+ (json!({"ports": {"lte": 5}}), vec!["3", "4"]),+ (json!({"seen": {"lt": "2000-01-01"}}), vec!["4"]),+ (+ json!({"addr": {"gte": "192.168.0.0", "lte": "192.168.255.255"}}),+ vec!["1"],+ ),+ ]+}++async fn assert_cases(engine: &Engine, phase: &str) {+ for (range, want) in cases() {+ let (count, total, got) = ids(engine, range.clone()).await;+ assert_eq!(+ got, want,+ "#1750 [{phase}] range {range}: hit ids (size:10) disagree"+ );+ assert_eq!(+ total,+ want.len() as u64,+ "#1750 [{phase}] range {range}: hits.total (size:10)"+ );+ assert_eq!(+ count,+ want.len() as u64,+ "#1750 [{phase}] range {range}: hits.total (size:0 count path)"+ );+ }+}++#[tokio::test]+async fn range_matches_any_element_of_a_multi_valued_field() {+ let dir = TempDir::new().unwrap();+ let engine = make_engine(&dir);+ seed(&engine).await;++ assert_cases(&engine, "buffered").await;++ engine+ .get_index("events")+ .unwrap()+ .refresh()+ .await+ .expect("refresh");+ assert_cases(&engine, "flushed").await;+}++/// `filter` aggregation with a `range` clause counts like the query does+/// (aggs.rs `doc_matches_filter` read only the first value).+#[tokio::test]+async fn filter_agg_range_matches_any_element() {+ let dir = TempDir::new().unwrap();+ let engine = make_engine(&dir);+ seed(&engine).await;+ let idx = engine.get_index("events").unwrap();++ for phase in ["buffered", "flushed"] {+ if phase == "flushed" {+ idx.refresh().await.expect("refresh");+ }+ let req = parse_request(&json!({+ "size": 0,+ "aggs": {+ "p": {"filter": {"range": {"ports": {"gte": 8000, "lte": 9000}}}},+ "s": {"filter": {"range": {"seen": {"gte": "2021-01-01", "lt": "2023-01-01"}}}}+ }+ }))+ .unwrap();+ let res = idx.search(&req).await.expect("agg search");+ let aggs = res.aggs.as_ref().expect("aggs present");+ assert_eq!(+ aggs["p"]["doc_count"],+ json!(1),+ "#1750 [{phase}] filter agg ports 8000..9000: {aggs}"+ );+ assert_eq!(+ aggs["s"]["doc_count"],+ json!(1),+ "#1750 [{phase}] filter agg seen 2021..2023: {aggs}"+ );+ }+}diff --git a/engine/tests/es-compat-yaml/yaml/search/770_range_on_multi_valued_fields.yml b/engine/tests/es-compat-yaml/yaml/search/770_range_on_multi_valued_fields.ymlnew file mode 100644index 000000000..22edf9056--- /dev/null+++ b/engine/tests/es-compat-yaml/yaml/search/770_range_on_multi_valued_fields.yml@@ -0,0 +1,117 @@+# #1750: a `range` query matches a document when ANY ONE value of a+# multi-valued field satisfies EVERY bound (Lucene per-value semantics).+# Expected values are Elasticsearch 8.13.4's for the requests in #1750.+# Documents stay buffered (no flush): the memtable numeric column keeps only+# an array's first element, so its fast paths must defer to the source scan.+setup:+ - do:+ indices.create:+ index: range_mv+ body:+ mappings:+ properties:+ name: { type: keyword }+ tags: { type: keyword }+ ports: { type: long }+ seen: { type: date }+ addr: { type: ip }+ - do:+ bulk:+ refresh: true+ body:+ - '{"index": {"_index": "range_mv", "_id": "1"}}'+ - '{"name": "d1", "tags": ["alpha", "mid"], "ports": [22, 8080], "seen": ["2020-01-01", "2024-06-01"], "addr": ["10.0.0.1", "192.168.1.7"]}'+ - '{"index": {"_index": "range_mv", "_id": "2"}}'+ - '{"name": "d2", "tags": "mid", "ports": 443, "seen": "2024-01-01", "addr": "10.0.0.9"}'+ - '{"index": {"_index": "range_mv", "_id": "3"}}'+ - '{"name": "d3", "tags": "zeta", "ports": 5, "seen": ["2030-01-01", "2021-06-01"], "addr": "172.16.0.1"}'++---+"keyword range matches a later array element":+ - do:+ count:+ index: range_mv+ body: { query: { range: { tags: { gte: m, lt: n } } } }+ - match: { count: 2 }+ - do:+ search:+ index: range_mv+ body: { query: { range: { tags: { gte: m, lt: n } } }, sort: [ name ] }+ - match: { hits.total.value: 2 }+ - length: { hits.hits: 2 }+ - match: { hits.hits.0._id: "1" }+ - match: { hits.hits.1._id: "2" }++---+"numeric range matches a later array element":+ - do:+ count:+ index: range_mv+ body: { query: { range: { ports: { gte: 8000, lte: 9000 } } } }+ - match: { count: 1 }+ - do:+ search:+ index: range_mv+ body: { query: { range: { ports: { gte: 8000, lte: 9000 } } }, sort: [ name ] }+ - match: { hits.total.value: 1 }+ - length: { hits.hits: 1 }+ - match: { hits.hits.0._id: "1" }++---+"date range matches a later array element":+ - do:+ count:+ index: range_mv+ body: { query: { range: { seen: { gte: "2021-01-01", lt: "2023-01-01" } } } }+ - match: { count: 1 }+ - do:+ search:+ index: range_mv+ body: { query: { range: { seen: { gte: "2021-01-01", lt: "2023-01-01" } } }, sort: [ name ] }+ - match: { hits.total.value: 1 }+ - length: { hits.hits: 1 }+ - match: { hits.hits.0._id: "3" }++---+"bounds are not split across array elements":+ - do:+ count:+ index: range_mv+ body: { query: { range: { ports: { gt: 22, lt: 443 } } } }+ - match: { count: 0 }+ - do:+ search:+ index: range_mv+ body: { query: { range: { ports: { gt: 22, lt: 443 } } }, sort: [ name ] }+ - match: { hits.total.value: 0 }+ - length: { hits.hits: 0 }++---+"upper bound only matches an array element":+ - do:+ count:+ index: range_mv+ body: { query: { range: { ports: { lte: 5 } } } }+ - match: { count: 1 }+ - do:+ search:+ index: range_mv+ body: { query: { range: { ports: { lte: 5 } } }, sort: [ name ] }+ - match: { hits.total.value: 1 }+ - length: { hits.hits: 1 }+ - match: { hits.hits.0._id: "3" }++---+"ip range matches a later array element":+ - do:+ count:+ index: range_mv+ body: { query: { range: { addr: { gte: "192.168.0.0", lte: "192.168.255.255" } } } }+ - match: { count: 1 }+ - do:+ search:+ index: range_mv+ body: { query: { range: { addr: { gte: "192.168.0.0", lte: "192.168.255.255" } } }, sort: [ name ] }+ - match: { hits.total.value: 1 }+ - length: { hits.hits: 1 }+ - match: { hits.hits.0._id: "1" }diff --git a/engine/tests/es-compat-yaml/yaml/search/771_range_on_multi_valued_fields_flushed.yml b/engine/tests/es-compat-yaml/yaml/search/771_range_on_multi_valued_fields_flushed.ymlnew file mode 100644index 000000000..3f458a489--- /dev/null+++ b/engine/tests/es-compat-yaml/yaml/search/771_range_on_multi_valued_fields_flushed.yml@@ -0,0 +1,121 @@+# #1750: a `range` query matches a document when ANY ONE value of a+# multi-valued field satisfies EVERY bound (Lucene per-value semantics).+# Expected values are Elasticsearch 8.13.4's for the requests in #1750.+# Same cases as 770, answered by a flushed SEGMENT: a field that is an+# array in any document gets no doc-values column, so these go through the+# stored-source matcher.+setup:+ - do:+ indices.create:+ index: range_mv_flushed+ body:+ mappings:+ properties:+ name: { type: keyword }+ tags: { type: keyword }+ ports: { type: long }+ seen: { type: date }+ addr: { type: ip }+ - do:+ bulk:+ refresh: true+ body:+ - '{"index": {"_index": "range_mv_flushed", "_id": "1"}}'+ - '{"name": "d1", "tags": ["alpha", "mid"], "ports": [22, 8080], "seen": ["2020-01-01", "2024-06-01"], "addr": ["10.0.0.1", "192.168.1.7"]}'+ - '{"index": {"_index": "range_mv_flushed", "_id": "2"}}'+ - '{"name": "d2", "tags": "mid", "ports": 443, "seen": "2024-01-01", "addr": "10.0.0.9"}'+ - '{"index": {"_index": "range_mv_flushed", "_id": "3"}}'+ - '{"name": "d3", "tags": "zeta", "ports": 5, "seen": ["2030-01-01", "2021-06-01"], "addr": "172.16.0.1"}'+ - do:+ indices.flush:+ index: range_mv_flushed++---+"keyword range matches a later array element":+ - do:+ count:+ index: range_mv_flushed+ body: { query: { range: { tags: { gte: m, lt: n } } } }+ - match: { count: 2 }+ - do:+ search:+ index: range_mv_flushed+ body: { query: { range: { tags: { gte: m, lt: n } } }, sort: [ name ] }+ - match: { hits.total.value: 2 }+ - length: { hits.hits: 2 }+ - match: { hits.hits.0._id: "1" }+ - match: { hits.hits.1._id: "2" }++---+"numeric range matches a later array element":+ - do:+ count:+ index: range_mv_flushed+ body: { query: { range: { ports: { gte: 8000, lte: 9000 } } } }+ - match: { count: 1 }+ - do:+ search:+ index: range_mv_flushed+ body: { query: { range: { ports: { gte: 8000, lte: 9000 } } }, sort: [ name ] }+ - match: { hits.total.value: 1 }+ - length: { hits.hits: 1 }+ - match: { hits.hits.0._id: "1" }++---+"date range matches a later array element":+ - do:+ count:+ index: range_mv_flushed+ body: { query: { range: { seen: { gte: "2021-01-01", lt: "2023-01-01" } } } }+ - match: { count: 1 }+ - do:+ search:+ index: range_mv_flushed+ body: { query: { range: { seen: { gte: "2021-01-01", lt: "2023-01-01" } } }, sort: [ name ] }+ - match: { hits.total.value: 1 }+ - length: { hits.hits: 1 }+ - match: { hits.hits.0._id: "3" }++---+"bounds are not split across array elements":+ - do:+ count:+ index: range_mv_flushed+ body: { query: { range: { ports: { gt: 22, lt: 443 } } } }+ - match: { count: 0 }+ - do:+ search:+ index: range_mv_flushed+ body: { query: { range: { ports: { gt: 22, lt: 443 } } }, sort: [ name ] }+ - match: { hits.total.value: 0 }+ - length: { hits.hits: 0 }++---+"upper bound only matches an array element":+ - do:+ count:+ index: range_mv_flushed+ body: { query: { range: { ports: { lte: 5 } } } }+ - match: { count: 1 }+ - do:+ search:+ index: range_mv_flushed+ body: { query: { range: { ports: { lte: 5 } } }, sort: [ name ] }+ - match: { hits.total.value: 1 }+ - length: { hits.hits: 1 }+ - match: { hits.hits.0._id: "3" }++---+"ip range matches a later array element":+ - do:+ count:+ index: range_mv_flushed+ body: { query: { range: { addr: { gte: "192.168.0.0", lte: "192.168.255.255" } } } }+ - match: { count: 1 }+ - do:+ search:+ index: range_mv_flushed+ body: { query: { range: { addr: { gte: "192.168.0.0", lte: "192.168.255.255" } } }, sort: [ name ] }+ - match: { hits.total.value: 1 }+ - length: { hits.hits: 1 }+ - match: { hits.hits.0._id: "1" }