|
19 | 19 | import static org.springframework.util.CollectionUtils.*;
|
20 | 20 |
|
21 | 21 | import co.elastic.clients.elasticsearch._types.Conflicts;
|
| 22 | +import co.elastic.clients.elasticsearch._types.ExpandWildcard; |
22 | 23 | import co.elastic.clients.elasticsearch._types.FieldValue;
|
23 | 24 | import co.elastic.clients.elasticsearch._types.InlineScript;
|
24 | 25 | import co.elastic.clients.elasticsearch._types.OpType;
|
|
67 | 68 | import java.util.Arrays;
|
68 | 69 | import java.util.Collections;
|
69 | 70 | import java.util.HashMap;
|
70 |
| -import java.util.LinkedHashMap; |
71 | 71 | import java.util.List;
|
72 | 72 | import java.util.Map;
|
73 | 73 | import java.util.function.Function;
|
74 | 74 | import java.util.stream.Collectors;
|
75 | 75 |
|
| 76 | +import org.apache.commons.logging.Log; |
| 77 | +import org.apache.commons.logging.LogFactory; |
76 | 78 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
77 | 79 | import org.springframework.data.domain.Sort;
|
78 | 80 | import org.springframework.data.elasticsearch.core.RefreshPolicy;
|
|
105 | 107 | */
|
106 | 108 | class RequestConverter {
|
107 | 109 |
|
| 110 | + private static final Log LOGGER = LogFactory.getLog(RequestConverter.class); |
| 111 | + |
108 | 112 | // the default max result window size of Elasticsearch
|
109 | 113 | public static final Integer INDEX_MAX_RESULT_WINDOW = 10_000;
|
110 | 114 |
|
@@ -1119,7 +1123,7 @@ private <T> void prepareSearchRequest(Query query, @Nullable Class<T> clazz, Ind
|
1119 | 1123 | }
|
1120 | 1124 |
|
1121 | 1125 | if (query.getIndicesOptions() != null) {
|
1122 |
| - // new Elasticsearch client does not support the old Indices options, need to be adapted |
| 1126 | + addIndicesOptions(builder, query.getIndicesOptions()); |
1123 | 1127 | }
|
1124 | 1128 |
|
1125 | 1129 | if (query.isLimiting()) {
|
@@ -1213,6 +1217,34 @@ private <T> void prepareSearchRequest(Query query, @Nullable Class<T> clazz, Ind
|
1213 | 1217 | }
|
1214 | 1218 | }
|
1215 | 1219 |
|
| 1220 | + private void addIndicesOptions(SearchRequest.Builder builder, IndicesOptions indicesOptions) { |
| 1221 | + |
| 1222 | + indicesOptions.getOptions().forEach(option -> { |
| 1223 | + switch (option) { |
| 1224 | + case ALLOW_NO_INDICES -> builder.allowNoIndices(true); |
| 1225 | + case IGNORE_UNAVAILABLE -> builder.ignoreUnavailable(true); |
| 1226 | + case IGNORE_THROTTLED -> builder.ignoreThrottled(true); |
| 1227 | + // the following ones aren't supported by the builder |
| 1228 | + case FORBID_ALIASES_TO_MULTIPLE_INDICES, FORBID_CLOSED_INDICES, IGNORE_ALIASES -> { |
| 1229 | + if (LOGGER.isWarnEnabled()) { |
| 1230 | + LOGGER |
| 1231 | + .warn(String.format("indices option %s is not supported by the Elasticsearch client.", option.name())); |
| 1232 | + } |
| 1233 | + } |
| 1234 | + } |
| 1235 | + }); |
| 1236 | + |
| 1237 | + builder.expandWildcards(indicesOptions.getExpandWildcards().stream().map(wildcardStates -> { |
| 1238 | + return switch (wildcardStates) { |
| 1239 | + case OPEN -> ExpandWildcard.Open; |
| 1240 | + case CLOSED -> ExpandWildcard.Closed; |
| 1241 | + case HIDDEN -> ExpandWildcard.Hidden; |
| 1242 | + case ALL -> ExpandWildcard.All; |
| 1243 | + case NONE -> ExpandWildcard.None; |
| 1244 | + }; |
| 1245 | + }).collect(Collectors.toList())); |
| 1246 | + } |
| 1247 | + |
1216 | 1248 | private Rescore getRescore(RescorerQuery rescorerQuery) {
|
1217 | 1249 |
|
1218 | 1250 | return Rescore.of(r -> r //
|
|
0 commit comments