spring-data-examples icon indicating copy to clipboard operation
spring-data-examples copied to clipboard

Add Criteria example for nested Elasticsearch field

Open parazit-IR opened this issue 1 month ago • 0 comments

Relates to #591.

This PR adds a small Spring Data Elasticsearch example that demonstrates using org.springframework.data.elasticsearch.core.query.Criteria against a nested field.

Changes:

  • Introduced a Talk document with a speakers field annotated as @Field(type = FieldType.Nested).
  • Added a simple Speaker value object.
  • Extended ElasticsearchOperationsTest with criteriaQueryOnNestedSpeakers(), which:
    • saves one Talk with a nested Speaker,
    • saves another Talk without speakers,
    • runs a CriteriaQuery on speakers.name,
    • asserts that only the matching talk is returned.

Note: On my local machine, the existing ElasticsearchOperationsTest fails to start the ApplicationContext with a DataAccessResourceFailureException when initializing ConferenceRepository:

status: 400, [es/indices.exists] Expecting a response body, but none was sent.

This also happens on a clean checkout of main.
The changes in this PR are limited to adding the nested Criteria example and do not modify the existing Elasticsearch configuration.

parazit-IR avatar Nov 29 '25 15:11 parazit-IR