Repository navigation
fix(es): match exact date metadata values on date-typed fields - #20532
Xavierando wants to merge 1 commit into
Conversation
The doc-metadata index maps meta_fields dynamically, so ES date detection types a YYYY-MM-DD field as `date`. A date field has no `.keyword` sub-field, and the push-down built every string equality as a term on `<field>.keyword`: `=` and `in` on a date matched nothing, and because an empty push-down result is definitive there was no in-memory fallback. Exact-match clauses for ISO-date values now match either the field itself or its `.keyword` sub-field, which covers both the date-typed and the text-typed mapping.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk | ⚪ Minimal · up to
|
Summary
Fixes #16832: the Go fix for its exact-match part, as requested on #16833 ("please make modifications in Go first"). The other two points are covered below.
The document-metadata index maps
meta_fieldsdynamically (conf/doc_meta_es_mapping.json,"dynamic": true), so Elasticsearch date detection maps a field whose values look likeYYYY-MM-DDasdate. Adatefield has no.keywordsub-field, but the metadata push-down builds every string equality as atermon<field>.keyword(termOrMatchininternal/engine/elasticsearch/meta_filter.go, used by=,≠and the string members ofin/not in). So=andinon a date value match nothing. An empty push-down result is final (no in-memory fallback), so the filter returns no documents. This hits every caller of the metadata push-down:metadata_conditiononPOST /api/v1/retrieval, chatmeta_data_filter, the agent Retrieval component and the agentic RAG metadata search.Fix: for a value matching the existing
dateRegex(^\d{4}-\d{2}-\d{2}$),termOrMatchemits abool.shouldover atermon the field itself and the existing case-insensitivetermon.keyword,minimum_should_match: 1. That matches whether the field was mapped asdateor astext+keyword. Non-date strings and numbers produce the same clause as before.The other two points of #16832 on the Go path:
>=,!=, …):IsPushdownSupporteddeclines them, and the in-memory filter normalises them withcommon.NormalizeOperator, so the condition is still applied. Nothing to fix here.auto/semi_autois a behaviour question, not part of this fix; it is tracked in [Bug]: Go: auto/semi_auto meta_data_filter reports "no match" for an empty filter, and callers handle it in opposite ways #20533.How this was tested
Unit tests.
bash build.sh --test ./internal/engine/elasticsearch/...→ok. New translator tests:=,≠andinon date values (the first three fail onmain, where the clause is atermonmeta_fields.<field>.keywordonly) and a guard that a plain string keeps the single.keywordterm.Elasticsearch 8.11.3, real data. A self-hosted deployment (v1.0.0-rc1 base, ~13 000 documents with metadata). The tenant's
ragflow_doc_meta_<tenant>index has three dynamically mappeddatefields with no.keyword(date,data_pubblicazione,data); all other metadata fields aretext+keyword._countwith the clause frommainand with the clause from this PR:main:term <field>.keywordshould[term <field>, term <field>.keyword]date = 2026-04-22data_pubblicazione = 2026-07-24End to end on the same deployment with this change built in,
POST /api/v1/retrievalon one dataset withmetadata_conditionon thedatefield:total= "2026-04-22"date = 2026-04-22in the metadata indexin ["2026-04-22", "2026-04-23"]= "1999-01-01"Known limits, left out to keep this minimal:
2026-02-30) makes Elasticsearch reject thetermon adatefield. The push-down then errors and the caller falls back to the in-memory filter, so the result is still correct, just not pushed down.contains/start with/end withstill target.keyword, so on adate-typed field they return nothing through the push-down. Uncommon for dates.YYYY-MM-DDvalues get the extra clause. A value with a time of day (2026-07-23T10:30:00Z) does not matchdateRegexand still targets.keywordonly.