1
0
mirror of synced 2026-05-23 20:53:17 +00:00

Compare commits

...

11 Commits

Author SHA1 Message Date
Mark Paluch ce64d2d6d1 Release version 5.4.4 (2024.1.4).
See #3057
2025-03-14 08:17:35 +01:00
Mark Paluch e02599d177 Prepare 5.4.4 (2024.1.4).
See #3057
2025-03-14 08:17:17 +01:00
Peter-Josef Meisch 8558c44714 Add testcontainers-local.properties handling.
Original Pull Request #3062
Closes #3061

Signed-off-by: Peter-Josef Meisch <pj.meisch@sothawo.com>
(cherry picked from commit 64f88ae9ac)
2025-03-09 12:53:46 +01:00
Peter-Josef Meisch 88e2e9da2a Fix mapping of property names in sort parameters.
Original Pull Request #3074
Closes #3072

Signed-off-by: Peter-Josef Meisch <pj.meisch@sothawo.com>
(cherry picked from commit 42383624ea)
2025-03-09 12:49:27 +01:00
Mark Paluch c15c1d08d7 After release cleanups.
See #3046
2025-02-14 10:42:42 +01:00
Mark Paluch c653e6a4ec Prepare next development iteration.
See #3046
2025-02-14 10:42:41 +01:00
Mark Paluch 7318c31692 Release version 5.4.3 (2024.1.3).
See #3046
2025-02-14 10:40:05 +01:00
Mark Paluch 6812684122 Prepare 5.4.3 (2024.1.3).
See #3046
2025-02-14 10:39:46 +01:00
Mark Paluch cd5d3da110 Update CI Properties.
See #3046
2025-02-11 15:22:46 +01:00
Mark Paluch f87f7469f1 After release cleanups.
See #3024
2025-01-17 11:40:00 +01:00
Mark Paluch 817967a282 Prepare next development iteration.
See #3024
2025-01-17 11:39:59 +01:00
8 changed files with 138 additions and 21 deletions
+1
View File
@@ -33,3 +33,4 @@ node
package-lock.json
.mvn/.develocity
/src/test/resources/testcontainers-local.properties
+1 -1
View File
@@ -3,6 +3,6 @@
<extension>
<groupId>io.spring.develocity.conventions</groupId>
<artifactId>develocity-conventions-maven-extension</artifactId>
<version>0.0.19</version>
<version>0.0.22</version>
</extension>
</extensions>
+10
View File
@@ -0,0 +1,10 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
+3 -3
View File
@@ -5,12 +5,12 @@
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>5.4.2</version>
<version>5.4.4</version>
<parent>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-parent</artifactId>
<version>3.4.2</version>
<version>3.4.4</version>
</parent>
<name>Spring Data Elasticsearch</name>
@@ -18,7 +18,7 @@
<url>https://github.com/spring-projects/spring-data-elasticsearch</url>
<properties>
<springdata.commons>3.4.2</springdata.commons>
<springdata.commons>3.4.4</springdata.commons>
<!-- version of the ElasticsearchClient -->
<elasticsearch-java>8.15.5</elasticsearch-java>
@@ -38,6 +38,7 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.EnvironmentCapable;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.ScriptedField;
import org.springframework.data.elasticsearch.core.document.Document;
@@ -50,6 +51,7 @@ import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
import org.springframework.data.elasticsearch.core.query.FetchSourceFilter;
import org.springframework.data.elasticsearch.core.query.Field;
import org.springframework.data.elasticsearch.core.query.Order;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
import org.springframework.data.elasticsearch.core.query.SourceFilter;
@@ -1231,7 +1233,7 @@ public class MappingElasticsearchConverter
return;
}
updatePropertiesInFieldsAndSourceFilter(query, domainClass);
updatePropertiesInFieldsSortAndSourceFilter(query, domainClass);
if (query instanceof CriteriaQuery criteriaQuery) {
updatePropertiesInCriteriaQuery(criteriaQuery, domainClass);
@@ -1242,7 +1244,14 @@ public class MappingElasticsearchConverter
}
}
private void updatePropertiesInFieldsAndSourceFilter(Query query, Class<?> domainClass) {
/**
* replaces the names of fields in the query, the sort or soucre filters with the field names used in Elasticsearch
* when they are defined on the ElasticsearchProperties
*
* @param query the query to process
* @param domainClass the domain class (persistent entity)
*/
private void updatePropertiesInFieldsSortAndSourceFilter(Query query, Class<?> domainClass) {
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(domainClass);
@@ -1250,12 +1259,12 @@ public class MappingElasticsearchConverter
List<String> fields = query.getFields();
if (!fields.isEmpty()) {
query.setFields(updateFieldNames(fields, persistentEntity));
query.setFields(propertyToFieldNames(fields, persistentEntity));
}
List<String> storedFields = query.getStoredFields();
if (!CollectionUtils.isEmpty(storedFields)) {
query.setStoredFields(updateFieldNames(storedFields, persistentEntity));
query.setStoredFields(propertyToFieldNames(storedFields, persistentEntity));
}
SourceFilter sourceFilter = query.getSourceFilter();
@@ -1266,37 +1275,60 @@ public class MappingElasticsearchConverter
String[] excludes = null;
if (sourceFilter.getIncludes() != null) {
includes = updateFieldNames(Arrays.asList(sourceFilter.getIncludes()), persistentEntity)
includes = propertyToFieldNames(Arrays.asList(sourceFilter.getIncludes()), persistentEntity)
.toArray(new String[] {});
}
if (sourceFilter.getExcludes() != null) {
excludes = updateFieldNames(Arrays.asList(sourceFilter.getExcludes()), persistentEntity)
excludes = propertyToFieldNames(Arrays.asList(sourceFilter.getExcludes()), persistentEntity)
.toArray(new String[] {});
}
query.addSourceFilter(new FetchSourceFilter(includes, excludes));
}
if (query.getSort() != null) {
var sort = query.getSort();
// stream the orders and map them to a new order with the changed names,
// then replace the existing sort with a new sort containing the new orders.
var newOrders = sort.stream().map(order -> {
var fieldNames = updateFieldNames(order.getProperty(), persistentEntity);
if (order instanceof Order springDataElasticsearchOrder) {
return springDataElasticsearchOrder.withProperty(fieldNames);
} else {
return new Sort.Order(order.getDirection(),
fieldNames,
order.isIgnoreCase(),
order.getNullHandling());
}
}).toList();
if (query instanceof BaseQuery baseQuery) {
baseQuery.setSort(Sort.by(newOrders));
}
}
}
}
/**
* relaces the fieldName with the property name of a property of the persistentEntity with the corresponding
* fieldname. If no such property exists, the original fieldName is kept.
* replaces property name of a property of the persistentEntity with the corresponding fieldname. If no such property
* exists, the original fieldName is kept.
*
* @param fieldNames list of fieldnames
* @param propertyNames list of fieldnames
* @param persistentEntity the persistent entity to check
* @return an updated list of field names
*/
private List<String> updateFieldNames(List<String> fieldNames, ElasticsearchPersistentEntity<?> persistentEntity) {
return fieldNames.stream().map(fieldName -> updateFieldName(persistentEntity, fieldName))
private List<String> propertyToFieldNames(List<String> propertyNames,
ElasticsearchPersistentEntity<?> persistentEntity) {
return propertyNames.stream().map(propertyName -> propertyToFieldName(persistentEntity, propertyName))
.collect(Collectors.toList());
}
@NotNull
private String updateFieldName(ElasticsearchPersistentEntity<?> persistentEntity, String fieldName) {
ElasticsearchPersistentProperty persistentProperty = persistentEntity.getPersistentProperty(fieldName);
return persistentProperty != null ? persistentProperty.getFieldName() : fieldName;
private String propertyToFieldName(ElasticsearchPersistentEntity<?> persistentEntity, String propertyName) {
ElasticsearchPersistentProperty persistentProperty = persistentEntity.getPersistentProperty(propertyName);
return persistentProperty != null ? persistentProperty.getFieldName() : propertyName;
}
private void updatePropertiesInCriteriaQuery(CriteriaQuery criteriaQuery, Class<?> domainClass) {
@@ -1410,7 +1442,7 @@ public class MappingElasticsearchConverter
if (properties.length > 0) {
var propertyName = properties[0];
var fieldName = updateFieldName(persistentEntity, propertyName);
var fieldName = propertyToFieldName(persistentEntity, propertyName);
if (properties.length > 1) {
var persistentProperty = persistentEntity.getPersistentProperty(propertyName);
@@ -1431,7 +1463,6 @@ public class MappingElasticsearchConverter
}
}
// endregion
@SuppressWarnings("ClassCanBeRecord")
+3 -1
View File
@@ -1,4 +1,4 @@
Spring Data Elasticsearch 5.4.2 (2024.1.2)
Spring Data Elasticsearch 5.4.4 (2024.1.4)
Copyright (c) [2013-2022] Pivotal Software, Inc.
This product is licensed to you under the Apache License, Version 2.0 (the "License").
@@ -26,4 +26,6 @@ conditions of the subcomponent's license, as noted in the LICENSE file.
@@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.List;
import org.json.JSONException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
@@ -639,6 +640,45 @@ public abstract class ElasticsearchPartQueryIntegrationTests {
assertEquals(expected, query, false);
}
@Test // #3072
@DisplayName("should build sort object with correct field names")
void shouldBuildSortObjectWithCorrectFieldNames() throws NoSuchMethodException, JSONException {
String methodName = "findByNameOrderBySortAuthor_SortName";
Class<?>[] parameterClasses = new Class[] { String.class };
Object[] parameters = new Object[] { BOOK_TITLE };
String query = getQueryString(methodName, parameterClasses, parameters);
String expected = """
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "Title",
"fields": [
"name"
]
}
}
]
}
},
"sort": [
{
"sort_author.sort_name": {
"order": "asc"
}
}
]
}""";
assertEquals(expected, query, false);
}
private String getQueryString(String methodName, Class<?>[] parameterClasses, Object[] parameters)
throws NoSuchMethodException {
@@ -726,6 +766,8 @@ public abstract class ElasticsearchPartQueryIntegrationTests {
List<Book> findByAvailableTrueOrderByNameDesc();
List<Book> findByNameOrderBySortAuthor_SortName(String name);
}
public static class Book {
@@ -735,6 +777,10 @@ public abstract class ElasticsearchPartQueryIntegrationTests {
@Nullable private Integer price;
@Field(type = FieldType.Boolean) private boolean available;
// this is needed for the #3072 test
@Nullable
@Field(name = "sort_author", type = FieldType.Object) private Author sortAuthor;
@Nullable
public String getId() {
return id;
@@ -766,8 +812,32 @@ public abstract class ElasticsearchPartQueryIntegrationTests {
return available;
}
@Nullable
public Author getSortAuthor() {
return sortAuthor;
}
public void setSortAuthor(@Nullable Author sortAuthor) {
this.sortAuthor = sortAuthor;
}
public void setAvailable(Boolean available) {
this.available = available;
}
}
public static class Author {
@Nullable
@Field(name = "sort_name", type = FieldType.Keyword) private String sortName;
@Nullable
public String getSortName() {
return sortName;
}
public void setSortName(@Nullable String sortName) {
this.sortName = sortName;
}
}
}
@@ -129,6 +129,9 @@ public class ClusterConnection implements ExtensionContext.Store.CloseableResour
Map<String, String> testcontainersProperties = testcontainersProperties(
"testcontainers-" + testcontainersConfiguration + ".properties");
var testcontainersPropertiesLocal = testcontainersProperties("testcontainers-local.properties");
testcontainersProperties.putAll(testcontainersPropertiesLocal);
DockerImageName dockerImageName = getDockerImageName(testcontainersProperties);
ElasticsearchContainer elasticsearchContainer = new SpringDataElasticsearchContainer(dockerImageName)