Skip to content

Criteria.or() with .exists().not() generates incorrect query - negation is lost #3247

@diegourban

Description

@diegourban

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions