From eabde9c543eac66b170694c2092e7b5ed1abe777 Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Wed, 21 Sep 2022 22:14:31 +0200 Subject: [PATCH] Adapt to Elasticsearch fix. Original Pull Request #2302 Closes #2171 --- .../elasticsearch/client/elc/RequestConverter.java | 12 +++++++++--- .../core/RuntimeFieldsELCIntegrationTests.java | 5 ----- .../core/RuntimeFieldsIntegrationTests.java | 5 +---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java index 82dc30400..6f7258834 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java @@ -1252,9 +1252,15 @@ class RequestConverter { Map runtimeMappings = new HashMap<>(); query.getRuntimeFields() - .forEach(runtimeField -> runtimeMappings.put(runtimeField.getName(), RuntimeField.of(rt -> rt // - .type(RuntimeFieldType._DESERIALIZER.parse(runtimeField.getType())) // - .script(s -> s.inline(is -> is.source(runtimeField.getScript())))))); + .forEach(runtimeField -> runtimeMappings.put(runtimeField.getName(), RuntimeField.of(runtimeFieldBuilder -> { + runtimeFieldBuilder.type(RuntimeFieldType._DESERIALIZER.parse(runtimeField.getType())); + String script = runtimeField.getScript(); + + if (script != null) { + runtimeFieldBuilder.script(s -> s.inline(is -> is.source(script))); + } + return runtimeFieldBuilder; + }))); builder.runtimeMappings(runtimeMappings); } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsELCIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsELCIntegrationTests.java index b232fa31e..417554f4a 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsELCIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsELCIntegrationTests.java @@ -37,9 +37,4 @@ public class RuntimeFieldsELCIntegrationTests extends RuntimeFieldsIntegrationTe return new IndexNameProvider("runtime-fields-rest-template"); } } - - @Override - public boolean newElasticsearchClient() { - return true; - } } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsIntegrationTests.java index 9fcb4fb13..f39bdcbc2 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsIntegrationTests.java @@ -21,7 +21,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledIf; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.NewElasticsearchClientDevelopment; @@ -41,7 +40,7 @@ import org.springframework.lang.Nullable; * @author cdalxndr */ @SpringIntegrationTest -public abstract class RuntimeFieldsIntegrationTests implements NewElasticsearchClientDevelopment { +public abstract class RuntimeFieldsIntegrationTests { @Autowired private ElasticsearchOperations operations; @Autowired protected IndexNameProvider indexNameProvider; @@ -61,7 +60,6 @@ public abstract class RuntimeFieldsIntegrationTests implements NewElasticsearchC operations.indexOps(IndexCoordinates.of(indexNameProvider.getPrefix() + "*")).delete(); } - @DisabledIf(value = "newElasticsearchClient", disabledReason = "todo #2171, ES issue 298") @Test // #1971 @DisplayName("should use runtime-field from query in search") void shouldUseRuntimeFieldFromQueryInSearch() { @@ -78,7 +76,6 @@ public abstract class RuntimeFieldsIntegrationTests implements NewElasticsearchC assertThat(searchHits.getSearchHit(0).getId()).isEqualTo("2"); } - @DisabledIf(value = "newElasticsearchClient", disabledReason = "todo #2171, ES issue 298") @Test // #2267 @DisplayName("should use runtime-field without script") void shouldUseRuntimeFieldWithoutScript() {