Polishing.

This commit is contained in:
Peter-Josef Meisch 2024-04-16 20:40:53 +02:00
parent 2d5f8e8219
commit a16782ec73
No known key found for this signature in database
GPG Key ID: DE108246970C7708
8 changed files with 353 additions and 360 deletions

View File

@ -10,6 +10,7 @@
* Add support for multi search template API.
* Add support for SpEL in @Query.
* Add support for field aliases in the index mapping.
* Add support for has_child and has_parent queries.
[[new-features.5-2-0]]
== New in Spring Data Elasticsearch 5.2

View File

@ -15,17 +15,16 @@
*/
package org.springframework.data.elasticsearch.client.elc;
import java.util.function.Consumer;
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.elasticsearch.core.query.StringQuery;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import java.util.function.Consumer;
/**
* An abstract class that serves as a base for query processors.
* It provides a common interface and basic functionality for query processing.
* An abstract class that serves as a base for query processors. It provides a common interface and basic functionality
* for query processing.
*
* @author Aouichaoui Youssef
* @since 5.3

View File

@ -16,7 +16,7 @@
package org.springframework.data.elasticsearch.client.elc;
import static org.springframework.data.elasticsearch.client.elc.Queries.*;
import static org.springframework.data.elasticsearch.client.elc.TypeUtils.scoreMode;
import static org.springframework.data.elasticsearch.client.elc.TypeUtils.*;
import static org.springframework.util.StringUtils.*;
import co.elastic.clients.elasticsearch._types.FieldValue;
@ -32,12 +32,10 @@ import java.util.List;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
import org.springframework.data.elasticsearch.core.query.Field;
import org.springframework.data.elasticsearch.core.query.HasChildQuery;
import org.springframework.data.elasticsearch.core.query.HasParentQuery;
import org.springframework.data.elasticsearch.core.query.InnerHitsQuery;
import org.springframework.data.elasticsearch.core.query.StringQuery;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@ -359,8 +357,7 @@ class CriteriaQueryProcessor extends AbstractQueryProcessor {
.ignoreUnmapped(query.getIgnoreUnmapped())
.minChildren(query.getMinChildren())
.maxChildren(query.getMaxChildren())
.scoreMode(scoreMode(query.getScoreMode()))
);
.scoreMode(scoreMode(query.getScoreMode())));
} else {
throw new CriteriaQueryException("value for " + fieldName + " is not a has_child query");
}
@ -372,8 +369,7 @@ class CriteriaQueryProcessor extends AbstractQueryProcessor {
.query(getEsQuery(query.getQuery(), null))
.innerHits(getInnerHits(query.getInnerHitsQuery()))
.ignoreUnmapped(query.getIgnoreUnmapped())
.score(query.getScore())
);
.score(query.getScore()));
} else {
throw new CriteriaQueryException("value for " + fieldName + " is not a has_parent query");
}

View File

@ -1007,8 +1007,7 @@ public class Criteria {
/**
* @since 5.3
*/
HAS_CHILD,
HAS_PARENT;
HAS_CHILD, HAS_PARENT;
/**
* @return true if this key does not have an associated value

View File

@ -22,7 +22,8 @@ import org.springframework.util.Assert;
* Defines a has_child request.
*
* @author Aouichaoui Youssef
* @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html">docs</a>
* @see <a href=
* "https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html">docs</a>
* @since 5.3
*/
public class HasChildQuery {
@ -37,20 +38,20 @@ public class HasChildQuery {
private final Query query;
/**
* Indicates whether to ignore an unmapped {@link #type} and not return any documents instead of an error.
* Default, this is set to {@code false}.
* Indicates whether to ignore an unmapped {@link #type} and not return any documents instead of an error. Default,
* this is set to {@code false}.
*/
@Nullable private final Boolean ignoreUnmapped;
/**
* The Maximum number of child documents that match the {@link #query} allowed for a returned parent document.
* If the parent document exceeds this limit, it is excluded from the search results.
* The Maximum number of child documents that match the {@link #query} allowed for a returned parent document. If the
* parent document exceeds this limit, it is excluded from the search results.
*/
@Nullable private final Integer maxChildren;
/**
* Minimum number of child documents that match the query required to match the {@link #query} for a returned parent document.
* If the parent document does not meet this limit, it is excluded from the search results.
* Minimum number of child documents that match the query required to match the {@link #query} for a returned parent
* document. If the parent document does not meet this limit, it is excluded from the search results.
*/
@Nullable private final Integer minChildren;
@ -147,8 +148,8 @@ public class HasChildQuery {
}
/**
* Indicates whether to ignore an unmapped {@link #type} and not return any documents instead of an error.
* Default, this is set to {@code false}.
* Indicates whether to ignore an unmapped {@link #type} and not return any documents instead of an error. Default,
* this is set to {@code false}.
*/
public Builder withIgnoreUnmapped(@Nullable Boolean ignoreUnmapped) {
this.ignoreUnmapped = ignoreUnmapped;
@ -157,8 +158,8 @@ public class HasChildQuery {
}
/**
* The Maximum number of child documents that match the {@link #query} allowed for a returned parent document.
* If the parent document exceeds this limit, it is excluded from the search results.
* The Maximum number of child documents that match the {@link #query} allowed for a returned parent document. If
* the parent document exceeds this limit, it is excluded from the search results.
*/
public Builder withMaxChildren(@Nullable Integer maxChildren) {
this.maxChildren = maxChildren;
@ -167,8 +168,8 @@ public class HasChildQuery {
}
/**
* Minimum number of child documents that match the query required to match the {@link #query} for a returned parent document.
* If the parent document does not meet this limit, it is excluded from the search results.
* Minimum number of child documents that match the query required to match the {@link #query} for a returned parent
* document. If the parent document does not meet this limit, it is excluded from the search results.
*/
public Builder withMinChildren(@Nullable Integer minChildren) {
this.minChildren = minChildren;

View File

@ -22,7 +22,8 @@ import org.springframework.util.Assert;
* Defines a has_parent request.
*
* @author Aouichaoui Youssef
* @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html">docs</a>
* @see <a href=
* "https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html">docs</a>
* @since 5.3
*/
public class HasParentQuery {

View File

@ -71,8 +71,7 @@ public class InnerHitsQuery {
@Nullable private Integer size;
@Nullable private Integer from;
private Builder() {
}
private Builder() {}
/**
* The name to be used for the particular inner hit definition in the response.

View File

@ -5013,21 +5013,18 @@ public abstract class ElasticsearchIntegrationTests {
@Document(indexName = "#{@indexNameProvider.indexName()}-join")
private static class RootEntity {
@Id
private String id;
@Id private String id;
@Field(type = FieldType.Object)
private Child child;
@Field(type = FieldType.Object) private Child child;
@Field(type = FieldType.Object)
private Parent parent;
@Field(type = FieldType.Object) private Parent parent;
@JoinTypeRelations(relations = {
@JoinTypeRelation(parent = "parent", children = { "child" })
})
private JoinField<String> relation = new JoinField<>("parent");
}) private JoinField<String> relation = new JoinField<>("parent");
private static final class Child {}
private static final class Parent {}
public static Builder builder() {