Skip to content

armgit / xerj

Public Imported from GitHub
0

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.

fix(api): _bulk reports real per-item _seq_no/_version, not a timestamp

Vincenzo Lombardoadc428933a25
diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rs
index c27161890..5c583f2ff 100644
--- a/engine/crates/xerj-api/src/es_compat.rs
+++ b/engine/crates/xerj-api/src/es_compat.rs
@@ -11913,13 +11913,27 @@ async fn process_bulk_body(
"_source": s,
})
});
+ // Real per-item `_seq_no` / `_version` — same resolvers `_mget` and
+ // GET `_doc` use (were hardcoded `_version: 1` / a wall-clock
+ // timestamp masquerading as `_seq_no`).
+ let (version, seq_no) = state
+ .engine
+ .get_index(&item.index)
+ .ok()
+ .map(|idx| {
+ (
+ idx.lookup_version(&item.id).unwrap_or(1),
+ idx.lookup_seq_no(&item.id).unwrap_or(0),
+ )
+ })
+ .unwrap_or((1, 0));
let item_result = EsBulkItemResult {
index: item.index,
id: item.id,
- version: 1,
+ version,
result: item.result.unwrap_or_else(|| "deleted".to_string()),
shards: crate::responses::EsShards::single_success(),
- seq_no: current_timestamp_micros(),
+ seq_no,
primary_term: 1,
status: item.status,
get,
@@ -12282,13 +12296,6 @@ fn native_type_to_es(ft: &FieldType) -> &'static str {
}
}
-fn current_timestamp_micros() -> u64 {
- std::time::SystemTime::now()
- .duration_since(std::time::UNIX_EPOCH)
- .unwrap_or_default()
- .as_micros() as u64
-}
-
// ─────────────────────────────────────────────────────────────────────────────
// Date math in index names
// ─────────────────────────────────────────────────────────────────────────────