Skip to content

Commit 68ba4cd

Browse files
committed
Polishing.
See #2267
1 parent 6b39b39 commit 68ba4cd

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

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

+13-19
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,7 @@
3232
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
3333
import co.elastic.clients.elasticsearch._types.query_dsl.Like;
3434
import co.elastic.clients.elasticsearch.cluster.HealthRequest;
35-
import co.elastic.clients.elasticsearch.core.BulkRequest;
36-
import co.elastic.clients.elasticsearch.core.DeleteByQueryRequest;
37-
import co.elastic.clients.elasticsearch.core.DeleteRequest;
38-
import co.elastic.clients.elasticsearch.core.GetRequest;
39-
import co.elastic.clients.elasticsearch.core.IndexRequest;
40-
import co.elastic.clients.elasticsearch.core.MgetRequest;
41-
import co.elastic.clients.elasticsearch.core.MsearchRequest;
42-
import co.elastic.clients.elasticsearch.core.SearchRequest;
43-
import co.elastic.clients.elasticsearch.core.UpdateByQueryRequest;
44-
import co.elastic.clients.elasticsearch.core.UpdateRequest;
35+
import co.elastic.clients.elasticsearch.core.*;
4536
import co.elastic.clients.elasticsearch.core.bulk.BulkOperation;
4637
import co.elastic.clients.elasticsearch.core.bulk.CreateOperation;
4738
import co.elastic.clients.elasticsearch.core.bulk.IndexOperation;
@@ -52,6 +43,7 @@
5243
import co.elastic.clients.elasticsearch.core.search.Rescore;
5344
import co.elastic.clients.elasticsearch.core.search.SourceConfig;
5445
import co.elastic.clients.elasticsearch.indices.*;
46+
import co.elastic.clients.elasticsearch.indices.ExistsRequest;
5547
import co.elastic.clients.elasticsearch.indices.update_aliases.Action;
5648
import co.elastic.clients.json.JsonData;
5749
import co.elastic.clients.json.JsonpDeserializer;
@@ -1134,10 +1126,13 @@ public MsearchRequest searchMsearchRequest(
11341126
Map<String, List<RuntimeField>> runtimeMappings = new HashMap<>();
11351127
query.getRuntimeFields().forEach(runtimeField -> {
11361128
RuntimeField esRuntimeField = RuntimeField.of(rt -> {
1137-
RuntimeField.Builder builder = rt.type(RuntimeFieldType._DESERIALIZER.parse(runtimeField.getType()));
1129+
RuntimeField.Builder builder = rt
1130+
.type(RuntimeFieldType._DESERIALIZER.parse(runtimeField.getType()));
11381131
String script = runtimeField.getScript();
1139-
if (script != null)
1132+
1133+
if (script != null) {
11401134
builder = builder.script(s -> s.inline(is -> is.source(script)));
1135+
}
11411136
return builder;
11421137
});
11431138
runtimeMappings.put(runtimeField.getName(), Collections.singletonList(esRuntimeField));
@@ -1168,7 +1163,6 @@ public MsearchRequest searchMsearchRequest(
11681163
});
11691164
}
11701165

1171-
11721166
private <T> void prepareSearchRequest(Query query, @Nullable Class<T> clazz, IndexCoordinates indexCoordinates,
11731167
SearchRequest.Builder builder, boolean forCount, boolean useScroll) {
11741168

@@ -1330,9 +1324,9 @@ private void addHighlight(Query query, SearchRequest.Builder builder) {
13301324
private void addHighlight(Query query, MultisearchBody.Builder builder) {
13311325

13321326
Highlight highlight = query.getHighlightQuery()
1333-
.map(highlightQuery -> new HighlightQueryBuilder(elasticsearchConverter.getMappingContext())
1334-
.getHighlight(highlightQuery.getHighlight(), highlightQuery.getType()))
1335-
.orElse(null);
1327+
.map(highlightQuery -> new HighlightQueryBuilder(elasticsearchConverter.getMappingContext())
1328+
.getHighlight(highlightQuery.getHighlight(), highlightQuery.getType()))
1329+
.orElse(null);
13361330

13371331
builder.highlight(highlight);
13381332
}
@@ -1428,9 +1422,9 @@ private void prepareNativeSearch(NativeQuery query, MultisearchBody.Builder buil
14281422
});
14291423

14301424
builder //
1431-
.suggest(query.getSuggester()) //
1432-
.collapse(query.getFieldCollapse()) //
1433-
.sort(query.getSortOptions());
1425+
.suggest(query.getSuggester()) //
1426+
.collapse(query.getFieldCollapse()) //
1427+
.sort(query.getSortOptions());
14341428

14351429
if (!isEmpty(query.getAggregations())) {
14361430
builder.aggregations(query.getAggregations());

Diff for: src/main/java/org/springframework/data/elasticsearch/core/RuntimeField.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ public class RuntimeField {
3232

3333
private final String name;
3434
private final String type;
35-
@Nullable
36-
private final String script;
35+
@Nullable private final String script;
3736

38-
public RuntimeField(String name, String type){
37+
public RuntimeField(String name, String type) {
3938
this(name, type, null);
4039
}
4140

@@ -59,6 +58,7 @@ public String getName() {
5958
public Map<String, Object> getMapping() {
6059
Map<String, Object> map = new HashMap<>();
6160
map.put("type", type);
61+
6262
if (script != null) {
6363
map.put("script", script);
6464
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.data.elasticsearch.core;
217

3-
418
import static org.assertj.core.api.Assertions.*;
519

620
import java.util.Map;
@@ -10,25 +24,26 @@
1024

1125
/**
1226
* @author cdalxndr
27+
* @since 5.0
1328
*/
1429
class RuntimeFieldTest {
1530

16-
@Test //#2267
31+
@Test // #2267
1732
@DisplayName("should return mapping with script")
1833
void testMapping() {
34+
1935
RuntimeField runtimeField = new RuntimeField("name", "double", "myscript");
2036
Map<String, Object> mapping = runtimeField.getMapping();
21-
assertThat(mapping).containsEntry("type", "double")
22-
.containsEntry("script", "myscript");
37+
assertThat(mapping).containsEntry("type", "double").containsEntry("script", "myscript");
2338
}
2439

25-
@Test //#2267
40+
@Test // #2267
2641
@DisplayName("should return mapping without script")
2742
void testMappingNoScript() {
43+
2844
RuntimeField runtimeField = new RuntimeField("name", "double");
2945
Map<String, Object> mapping = runtimeField.getMapping();
30-
assertThat(mapping).containsEntry("type", "double")
31-
.doesNotContainKey("script");
46+
assertThat(mapping).containsEntry("type", "double").doesNotContainKey("script");
3247
}
3348

34-
}
49+
}

0 commit comments

Comments
 (0)