Repository navigation
Conversation
Place NE negation before the metadata field and isolate OR operands. Add converter tests and Testcontainers filter regression coverage. Fixes spring-projects#7153 Signed-off-by: Emrys <[email protected]>
|
Reproduced the OR-operand case on Elasticsearch 9.2.0 (Lucene 10.3.1) with the query string from Filter: year >= 2020 OR (country == "BG" AND city != "Sofia"). Query string: Elasticsearch explains that as Indexed documents: That query returned only
|
|
Thanks for reproducing this on Elasticsearch 9.2.0, @Chandra324! The explain output makes it really clear why the OR operands need parentheses here. |
Fixes #7153
The Elasticsearch converter emitted NE as
metadata.label: NOT "second", whichquery_stringrejects.Handle NE separately and emit
NOT metadata.label:"second", following the existing NIN placement.Wrap both OR operands in parentheses:
A OR NOT Bmakes B aMUST_NOTclause of the entire Boolean query, excluding B even when A matches.(A) OR (NOT B)keeps the negation inside its operand.The converter retains the inherited
doNotimplementation; the shared double-negation problem is outside this change.Regression coverage and validation
On Ubuntu WSL with OpenJDK 21.0.12 and Maven 3.9.16, compiling for Java 17, a clean reactor build and verification completed successfully with the build cache and automatic source formatting disabled.
All 21 converter unit tests and all 5
ElasticsearchVectorStoreFilterITcases passed with zero failures, errors, or skips.The integration tests ran against a real Elasticsearch 9.2.0 instance managed by Testcontainers and used a fixed embedding model with no external service calls.
Coverage includes string and numeric NE, AND, both OR operand orders, grouping,
not(group(eq)), and matching NE/NIN behavior when metadata is missing.Formatting and Checkstyle checks also passed.
Missing metadata and date scope
The integration test confirms that both NE and NIN include a document without the label field, alongside first and third, while excluding second.
This preserves Elasticsearch's existing NIN complement behavior and matches the inspected MongoDB, Qdrant, and SimpleVectorStore implementations.
The common filter API does not define a universal missing-field contract; PgVector delegates inequality to native JSONPath, whose absent-path behavior can exclude a document.
No existence condition or cross-provider semantic normalization is added.
Date NE unit tests cover Java Date and ISO date values while retaining main's existing serialization.
The independent date escaping problem tracked by #7146 remains outside this change, and no code from that unmerged PR is used.
Contribution checks