Skip to content

Commit 377d893

Browse files
authored
Tidy up some enrich code (#120330)
1 parent cfc6627 commit 377d893

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/enrich/EnrichPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
public final class EnrichPolicy implements Writeable, ToXContentFragment {
3737

38-
private static final String ELASTICEARCH_VERSION_DEPRECATION_MESSAGE =
38+
private static final String ELASTICSEARCH_VERSION_DEPRECATION_MESSAGE =
3939
"the [elasticsearch_version] field of an enrich policy has no effect and will be removed in a future version of Elasticsearch";
4040

4141
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(EnrichPolicy.class);
@@ -146,7 +146,7 @@ private EnrichPolicy(
146146
deprecationLogger.warn(
147147
DeprecationCategory.OTHER,
148148
"enrich_policy_with_elasticsearch_version",
149-
ELASTICEARCH_VERSION_DEPRECATION_MESSAGE
149+
ELASTICSEARCH_VERSION_DEPRECATION_MESSAGE
150150
);
151151
}
152152
}

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void execute(IngestDocument ingestDocument, BiConsumer<IngestDocument, Ex
9090
// If the index is empty, return the unchanged document
9191
// If the enrich key does not exist in the index, throw an error
9292
// If no documents match the key, return the unchanged document
93-
if (searchHits.size() < 1) {
93+
if (searchHits.isEmpty()) {
9494
handler.accept(ingestDocument, null);
9595
return;
9696
}

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
/**
3636
* A simple cache for enrich that uses {@link Cache}. There is one instance of this cache and
3737
* multiple enrich processors with different policies will use this cache.
38-
*
38+
* <p>
3939
* The key of the cache is based on the search request and the enrich index that will be used.
4040
* Search requests that enrich generates target the alias for an enrich policy, this class
4141
* resolves the alias to the actual enrich index and uses that for the cache key. This way
4242
* no stale entries will be returned if a policy execution happens and a new enrich index is created.
43-
*
43+
* <p>
4444
* There is no cleanup mechanism of stale entries in case a new enrich index is created
4545
* as part of a policy execution. This shouldn't be needed as cache entries for prior enrich
4646
* indices will be eventually evicted, because these entries will not end up being used. The

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/GeoMatchProcessor.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class GeoMatchProcessor extends AbstractEnrichProcessor {
4040
) {
4141
super(tag, description, searchRunner, policyName, field, targetField, ignoreMissing, overrideEnabled, matchField, maxMatches);
4242
this.shapeRelation = shapeRelation;
43-
parser = new GeometryParser(orientation.getAsBoolean(), true, true);
43+
this.parser = new GeometryParser(orientation.getAsBoolean(), true, true);
4444
}
4545

4646
@Override
@@ -50,8 +50,4 @@ public QueryBuilder getQueryBuilder(Object fieldValue) {
5050
shapeQuery.relation(shapeRelation);
5151
return shapeQuery;
5252
}
53-
54-
public ShapeRelation getShapeRelation() {
55-
return shapeRelation;
56-
}
5753
}

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichCoordinatorProxyAction.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void coordinateLookups() {
177177
assert slots.isEmpty() == false;
178178
remoteRequestsTotal.increment();
179179
final MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
180-
slots.forEach(slot -> multiSearchRequest.add(slot.searchRequest));
180+
slots.forEach(slot -> multiSearchRequest.add(slot.request));
181181
lookupFunction.accept(multiSearchRequest, (response, e) -> handleResponse(slots, response, e));
182182
}
183183
}
@@ -193,13 +193,13 @@ void handleResponse(List<Slot> slots, MultiSearchResponse response, Exception e)
193193
Slot slot = slots.get(i);
194194

195195
if (responseItem.isFailure()) {
196-
slot.actionListener.onFailure(responseItem.getFailure());
196+
slot.listener.onFailure(responseItem.getFailure());
197197
} else {
198-
slot.actionListener.onResponse(responseItem.getResponse());
198+
slot.listener.onResponse(responseItem.getResponse());
199199
}
200200
}
201201
} else if (e != null) {
202-
slots.forEach(slot -> slot.actionListener.onFailure(e));
202+
slots.forEach(slot -> slot.listener.onFailure(e));
203203
} else {
204204
throw new AssertionError("no response and no error");
205205
}
@@ -208,14 +208,10 @@ void handleResponse(List<Slot> slots, MultiSearchResponse response, Exception e)
208208
coordinateLookups();
209209
}
210210

211-
static class Slot {
212-
213-
final SearchRequest searchRequest;
214-
final ActionListener<SearchResponse> actionListener;
215-
216-
Slot(SearchRequest searchRequest, ActionListener<SearchResponse> actionListener) {
217-
this.searchRequest = Objects.requireNonNull(searchRequest);
218-
this.actionListener = Objects.requireNonNull(actionListener);
211+
record Slot(SearchRequest request, ActionListener<SearchResponse> listener) {
212+
Slot {
213+
Objects.requireNonNull(request);
214+
Objects.requireNonNull(listener);
219215
}
220216
}
221217

0 commit comments

Comments
 (0)