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): support the bare GET _ilm/policy list-all form

Vincenzo Lombardo1eb9a625aeb0
diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rs
index 29c8a1f74..c9de65b99 100644
--- a/engine/crates/xerj-api/src/es_compat.rs
+++ b/engine/crates/xerj-api/src/es_compat.rs
@@ -22787,16 +22787,30 @@ pub async fn put_ilm_policy(
}
}
+// GET _ilm/policy (no name segment) — the form Kibana's own ILM UI calls to
+// populate the "Index Lifecycle Policies" list page. Real ES returns every
+// policy from this bare path; we had only ever wired up the `*`/`_all`
+// wildcard under `/_ilm/policy/:name`, so the bare path 404'd (no route
+// matched it at all) and the UI silently rendered its "no policies" empty
+// state even when policies existed — same bug class as the ISM list-form gap.
+pub async fn list_ilm_policies(State(state): State<AppState>) -> impl IntoResponse {
+ all_ilm_policies_response(&state)
+}
+
+fn all_ilm_policies_response(state: &AppState) -> Response {
+ let mut result = serde_json::Map::new();
+ for entry in state.engine.ilm_policies.iter() {
+ result.insert(entry.key().clone(), entry.value().clone());
+ }
+ Json(Value::Object(result)).into_response()
+}
+
pub async fn get_ilm_policy(
State(state): State<AppState>,
Path(name): Path<String>,
) -> impl IntoResponse {
if name == "*" || name == "_all" {
- let mut result = serde_json::Map::new();
- for entry in state.engine.ilm_policies.iter() {
- result.insert(entry.key().clone(), entry.value().clone());
- }
- return Json(Value::Object(result)).into_response();
+ return all_ilm_policies_response(&state);
}
match state.engine.ilm_policies.get(&name) {
Some(policy) => {
@@ -22823,6 +22837,56 @@ pub async fn delete_ilm_policy(
}
}
+#[cfg(test)]
+mod ilm_policy_list_tests {
+ use super::*;
+ use axum::{body::Body, http::Request};
+ use tower::ServiceExt;
+
+ fn test_state() -> AppState {
+ let dir = tempfile::tempdir().expect("tempdir").keep();
+ let mut config = xerj_common::config::Config::default();
+ config.server.data_dir = dir.to_string_lossy().into_owned();
+ config.storage.wal_sync = xerj_common::config::WalSync::Async;
+ let metrics = xerj_common::metrics::Metrics::new().expect("metrics");
+ let engine = xerj_engine::Engine::new(config.clone()).expect("engine");
+ AppState::new(config, engine, metrics)
+ }
+
+ #[tokio::test]
+ async fn bare_get_ilm_policy_lists_every_policy() {
+ let state = test_state();
+ let app = crate::router::build_es_compat_router(state);
+
+ let put = app
+ .clone()
+ .oneshot(
+ Request::put("/_ilm/policy/kibana-verify-policy")
+ .header("content-type", "application/json")
+ .body(Body::from(
+ json!({"policy": {"phases": {"hot": {"actions": {}}}}}).to_string(),
+ ))
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(put.status(), StatusCode::OK);
+
+ // Real ES's `GET _ilm/policy` (no name segment) lists every policy —
+ // this is the exact form Kibana's UI calls for its policy list page.
+ let list = app
+ .oneshot(Request::get("/_ilm/policy").body(Body::empty()).unwrap())
+ .await
+ .unwrap();
+ assert_eq!(list.status(), StatusCode::OK);
+ let bytes = axum::body::to_bytes(list.into_body(), usize::MAX)
+ .await
+ .unwrap();
+ let body: Value = serde_json::from_slice(&bytes).unwrap();
+ assert!(body.get("kibana-verify-policy").is_some());
+ }
+}
+
// ─────────────────────────────────────────────────────────────────────────────
// GET /{index}/_ilm/explain
// ─────────────────────────────────────────────────────────────────────────────
diff --git a/engine/crates/xerj-api/src/router.rs b/engine/crates/xerj-api/src/router.rs
index f26ac4b1d..c77de4206 100644
--- a/engine/crates/xerj-api/src/router.rs
+++ b/engine/crates/xerj-api/src/router.rs
@@ -449,6 +449,7 @@ pub fn build_es_compat_router(state: AppState) -> Router {
)
.route("/:name/_rollover", post(es_compat::rollover_data_stream))
// ── ILM ────────────────────────────────────────────────────────────
+ .route("/_ilm/policy", get(es_compat::list_ilm_policies))
.route(
"/_ilm/policy/:name",
put(es_compat::put_ilm_policy)