spring-projects / spring-data-elasticsearch

Provide support to increase developer productivity in Java when using Elasticsearch. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-elasticsearch/
Apache License 2.0
2.92k stars 1.33k forks source link

Fix missing parent document type specification in hasChild query example #2900

Closed 1autodidact closed 6 months ago

1autodidact commented 6 months ago

Description:

1、This pull request addresses an issue in the Spring Data Elasticsearch documentation where the specification of the parent document type is missing in the example code for the hasChild query.

2、The Routing property in the Statement class is incorrectly typed as Routing, when it should be String according to the context. 3、In the example code, there is a typo where a comma is used instead of a period: .withText("+1 for the sun") ,withRouting(savedWeather.getId()), where it should be .withText("+1 for the sun").withRouting(savedWeather.getId()).

In Elasticsearch 8.x, it's essential to specify the parent document type when using the hasChild query. Failure to specify the parent type results in an error from Elasticsearch. This pull request adds the missing .type("answer") statement to ensure the correct behavior of the query.

Changes Made:

Added .type("answer") statement to specify the parent document type in the hasChild query. Updated the example code to reflect the correct usage of the hasChild query. References:

Elasticsearch Documentation: has_child query

ClientVersion: elastic-search-java :8.10.4

Excption: co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'HasChildQuery.type' at co.elastic.clients.util.ApiTypeHelper.requireNonNull(ApiTypeHelper.java:76) at co.elastic.clients.elasticsearch._types.query_dsl.HasChildQuery.(HasChildQuery.java:82) at co.elastic.clients.elasticsearch._types.query_dsl.HasChildQuery.(HasChildQuery.java:51) at co.elastic.clients.elasticsearch._types.query_dsl.HasChildQuery$Builder.build(HasChildQuery.java:349) at co.elastic.clients.elasticsearch._types.query_dsl.HasChildQuery$Builder.build(HasChildQuery.java:216) at co.elastic.clients.elasticsearch._types.query_dsl.Query$Builder.hasChild(Query.java:1412)

sothawo commented 6 months ago

Thanks for finding and fixing.