|
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;
|
25 |
| -import co.elastic.clients.elasticsearch._types.SearchType; |
26 | 26 | import co.elastic.clients.elasticsearch._types.SortOptions;
|
27 | 27 | import co.elastic.clients.elasticsearch._types.SortOrder;
|
28 | 28 | import co.elastic.clients.elasticsearch._types.VersionType;
|
|
64 | 64 | import java.util.Arrays;
|
65 | 65 | import java.util.Collections;
|
66 | 66 | import java.util.HashMap;
|
67 |
| -import java.util.LinkedHashMap; |
68 | 67 | import java.util.List;
|
69 | 68 | import java.util.Map;
|
70 | 69 | import java.util.function.Function;
|
71 | 70 | import java.util.stream.Collectors;
|
72 | 71 |
|
| 72 | +import org.apache.commons.logging.Log; |
| 73 | +import org.apache.commons.logging.LogFactory; |
73 | 74 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
74 | 75 | import org.springframework.data.domain.Sort;
|
75 | 76 | import org.springframework.data.elasticsearch.core.RefreshPolicy;
|
|
109 | 110 | @SuppressWarnings("ClassCanBeRecord")
|
110 | 111 | class RequestConverter {
|
111 | 112 |
|
| 113 | + private static final Log LOGGER = LogFactory.getLog(RequestConverter.class); |
| 114 | + |
112 | 115 | // the default max result window size of Elasticsearch
|
113 | 116 | public static final Integer INDEX_MAX_RESULT_WINDOW = 10_000;
|
114 | 117 |
|
@@ -1342,7 +1345,7 @@ private <T> void prepareSearchRequest(Query query, @Nullable String routing, @Nu
|
1342 | 1345 | }
|
1343 | 1346 |
|
1344 | 1347 | if (query.getIndicesOptions() != null) {
|
1345 |
| - // new Elasticsearch client does not support the old Indices options, need to be adapted |
| 1348 | + addIndicesOptions(builder, query.getIndicesOptions()); |
1346 | 1349 | }
|
1347 | 1350 |
|
1348 | 1351 | if (query.isLimiting()) {
|
@@ -1429,6 +1432,34 @@ private <T> void prepareSearchRequest(Query query, @Nullable String routing, @Nu
|
1429 | 1432 | }
|
1430 | 1433 | }
|
1431 | 1434 |
|
| 1435 | + private void addIndicesOptions(SearchRequest.Builder builder, IndicesOptions indicesOptions) { |
| 1436 | + |
| 1437 | + indicesOptions.getOptions().forEach(option -> { |
| 1438 | + switch (option) { |
| 1439 | + case ALLOW_NO_INDICES -> builder.allowNoIndices(true); |
| 1440 | + case IGNORE_UNAVAILABLE -> builder.ignoreUnavailable(true); |
| 1441 | + case IGNORE_THROTTLED -> builder.ignoreThrottled(true); |
| 1442 | + // the following ones aren't supported by the builder |
| 1443 | + case FORBID_ALIASES_TO_MULTIPLE_INDICES, FORBID_CLOSED_INDICES, IGNORE_ALIASES -> { |
| 1444 | + if (LOGGER.isWarnEnabled()) { |
| 1445 | + LOGGER |
| 1446 | + .warn(String.format("indices option %s is not supported by the Elasticsearch client.", option.name())); |
| 1447 | + } |
| 1448 | + } |
| 1449 | + } |
| 1450 | + }); |
| 1451 | + |
| 1452 | + builder.expandWildcards(indicesOptions.getExpandWildcards().stream().map(wildcardStates -> { |
| 1453 | + return switch (wildcardStates) { |
| 1454 | + case OPEN -> ExpandWildcard.Open; |
| 1455 | + case CLOSED -> ExpandWildcard.Closed; |
| 1456 | + case HIDDEN -> ExpandWildcard.Hidden; |
| 1457 | + case ALL -> ExpandWildcard.All; |
| 1458 | + case NONE -> ExpandWildcard.None; |
| 1459 | + }; |
| 1460 | + }).collect(Collectors.toList())); |
| 1461 | + } |
| 1462 | + |
1432 | 1463 | private Rescore getRescore(RescorerQuery rescorerQuery) {
|
1433 | 1464 |
|
1434 | 1465 | return Rescore.of(r -> r //
|
|
0 commit comments