What is the bug?
When combining .or() with .exists().not() in the Criteria API, the negation is lost or misapplied, producing incorrect query results.
Standalone .exists().not() works.
How can one reproduce the bug?
Given three documents in an index:
| ID |
name |
status |
| product-1 |
Widget |
ACTIVE |
| product-2 |
Gadget |
INACTIVE |
| product-3 |
Gizmo |
(field missing) |
Execute the following Criteria query:
Criteria criteria = new Criteria("status").is("ACTIVE").or(new Criteria("status").exists().not());
CriteriaQuery query = new CriteriaQuery(criteria);
SearchHits<Product> hits = operations.search(query, Product.class);
What is the expected behavior?
Expected: Returns product-1 (status = ACTIVE) and product-3 (status field does not exist).
Actual: Does not return the expected results, the .exists().not() negation inside .or() is lost.
What is your host/environment?
- OpenSearch version: 3.5.0
- Spring Boot version: 4.0.2
- spring-data-opensearch version: 3.0.2
- Java version: 21
Do you have any additional context?
Minimal reproducible example:
https://github.com/diegourban/spring-data-opensearch-criteria-or-not-exists-issue
What is the bug?
When combining
.or()with.exists().not()in the Criteria API, the negation is lost or misapplied, producing incorrect query results.Standalone
.exists().not()works.How can one reproduce the bug?
Given three documents in an index:
Execute the following Criteria query:
What is the expected behavior?
Expected: Returns product-1 (status = ACTIVE) and product-3 (status field does not exist).
Actual: Does not return the expected results, the
.exists().not()negation inside.or()is lost.What is your host/environment?
Do you have any additional context?
Minimal reproducible example:
https://github.com/diegourban/spring-data-opensearch-criteria-or-not-exists-issue