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
feat(search): echo external _version in the Fields API path
xerj-org105a3b0ef455
diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rsindex 8328f60e9..b31fc0cf3 100644--- a/engine/crates/xerj-api/src/es_compat.rs+++ b/engine/crates/xerj-api/src/es_compat.rs@@ -7608,12 +7608,19 @@ pub async fn search(continue;}"_version" => {- // ES returns _version as doc_values. xerj- // doesn't track per-doc version separately;- // emit 1 as a placeholder for newly-indexed- // docs (the common case covered by the- // metadata-fetch test).- fmap.insert("_version".to_string(), Value::Array(vec![json!(1)]));+ // Echo the caller-supplied external `_version`+ // (`version_type=external[_gte]`) from the same+ // map the top-level and inner_hits `_version`+ // paths use. Internal per-doc version increments+ // aren't tracked yet, so freshly-indexed docs+ // default to 1.+ let v = state+ .engine+ .get_index(&idx_name)+ .ok()+ .and_then(|idx| idx.external_versions.get(&h.id).map(|v| *v))+ .unwrap_or(1);+ fmap.insert("_version".to_string(), Value::Array(vec![json!(v)]));continue;}_ => {}diff --git a/engine/tests/es-compat-yaml/yaml/search/330_fetch_fields.yml b/engine/tests/es-compat-yaml/yaml/search/330_fetch_fields.ymlindex 06fa5d242..4172cc8e3 100644--- a/engine/tests/es-compat-yaml/yaml/search/330_fetch_fields.yml+++ b/engine/tests/es-compat-yaml/yaml/search/330_fetch_fields.yml@@ -1243,3 +1243,29 @@ object with subobjects false and dynamic false:my.nested.keyword.field: abc- match: { hits.total.value: 1 }++---+"fetch _version echoes external version":+ - do:+ indices.create:+ index: ver_test++ # Index a doc carrying an explicit external version.+ - do:+ index:+ index: ver_test+ id: "1"+ version: 5+ version_type: external+ refresh: true+ body:+ field: foo++ - do:+ search:+ index: ver_test+ body:+ fields: [ "_version" ]++ # Before the fix the Fields API hardcoded 1; now it echoes the caller's 5.+ - match: { hits.hits.0.fields._version.0: 5 }