Skip to content

Commit 1ef1ef3

Browse files
committed
spring-projects#2171-Adapt-to-Elasticsearch-fix
1 parent 120ca85 commit 1ef1ef3

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1252,9 +1252,15 @@ private <T> void prepareSearchRequest(Query query, @Nullable Class<T> clazz, Ind
12521252

12531253
Map<String, RuntimeField> runtimeMappings = new HashMap<>();
12541254
query.getRuntimeFields()
1255-
.forEach(runtimeField -> runtimeMappings.put(runtimeField.getName(), RuntimeField.of(rt -> rt //
1256-
.type(RuntimeFieldType._DESERIALIZER.parse(runtimeField.getType())) //
1257-
.script(s -> s.inline(is -> is.source(runtimeField.getScript()))))));
1255+
.forEach(runtimeField -> runtimeMappings.put(runtimeField.getName(), RuntimeField.of(runtimeFieldBuilder -> {
1256+
runtimeFieldBuilder.type(RuntimeFieldType._DESERIALIZER.parse(runtimeField.getType()));
1257+
String script = runtimeField.getScript();
1258+
1259+
if (script != null) {
1260+
runtimeFieldBuilder.script(s -> s.inline(is -> is.source(script)));
1261+
}
1262+
return runtimeFieldBuilder;
1263+
})));
12581264
builder.runtimeMappings(runtimeMappings);
12591265
}
12601266

src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsELCIntegrationTests.java

-5
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,4 @@ IndexNameProvider indexNameProvider() {
3737
return new IndexNameProvider("runtime-fields-rest-template");
3838
}
3939
}
40-
41-
@Override
42-
public boolean newElasticsearchClient() {
43-
return true;
44-
}
4540
}

src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsIntegrationTests.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.junit.jupiter.api.DisplayName;
2222
import org.junit.jupiter.api.Order;
2323
import org.junit.jupiter.api.Test;
24-
import org.junit.jupiter.api.condition.DisabledIf;
2524
import org.springframework.beans.factory.annotation.Autowired;
2625
import org.springframework.data.annotation.Id;
2726
import org.springframework.data.elasticsearch.NewElasticsearchClientDevelopment;
@@ -41,7 +40,7 @@
4140
* @author cdalxndr
4241
*/
4342
@SpringIntegrationTest
44-
public abstract class RuntimeFieldsIntegrationTests implements NewElasticsearchClientDevelopment {
43+
public abstract class RuntimeFieldsIntegrationTests {
4544

4645
@Autowired private ElasticsearchOperations operations;
4746
@Autowired protected IndexNameProvider indexNameProvider;
@@ -61,7 +60,6 @@ void cleanup() {
6160
operations.indexOps(IndexCoordinates.of(indexNameProvider.getPrefix() + "*")).delete();
6261
}
6362

64-
@DisabledIf(value = "newElasticsearchClient", disabledReason = "todo #2171, ES issue 298")
6563
@Test // #1971
6664
@DisplayName("should use runtime-field from query in search")
6765
void shouldUseRuntimeFieldFromQueryInSearch() {
@@ -78,7 +76,6 @@ void shouldUseRuntimeFieldFromQueryInSearch() {
7876
assertThat(searchHits.getSearchHit(0).getId()).isEqualTo("2");
7977
}
8078

81-
@DisabledIf(value = "newElasticsearchClient", disabledReason = "todo #2171, ES issue 298")
8279
@Test // #2267
8380
@DisplayName("should use runtime-field without script")
8481
void shouldUseRuntimeFieldWithoutScript() {

0 commit comments

Comments
 (0)