From 5f4f06907e77cf694b01bb3c3b8464e97ca36396 Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Thu, 16 Jan 2025 18:12:40 -0500 Subject: [PATCH] Tidy up some enrich code (#120330) --- .../xpack/core/enrich/EnrichPolicy.java | 4 ++-- .../xpack/enrich/AbstractEnrichProcessor.java | 2 +- .../xpack/enrich/EnrichCache.java | 4 ++-- .../xpack/enrich/GeoMatchProcessor.java | 6 +----- .../action/EnrichCoordinatorProxyAction.java | 20 ++++++++----------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/enrich/EnrichPolicy.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/enrich/EnrichPolicy.java index 916bd3c62a598..c8693c66458ca 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/enrich/EnrichPolicy.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/enrich/EnrichPolicy.java @@ -35,7 +35,7 @@ */ public final class EnrichPolicy implements Writeable, ToXContentFragment { - private static final String ELASTICEARCH_VERSION_DEPRECATION_MESSAGE = + private static final String ELASTICSEARCH_VERSION_DEPRECATION_MESSAGE = "the [elasticsearch_version] field of an enrich policy has no effect and will be removed in Elasticsearch 9.0"; private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(EnrichPolicy.class); @@ -146,7 +146,7 @@ private EnrichPolicy( deprecationLogger.warn( DeprecationCategory.OTHER, "enrich_policy_with_elasticsearch_version", - ELASTICEARCH_VERSION_DEPRECATION_MESSAGE + ELASTICSEARCH_VERSION_DEPRECATION_MESSAGE ); } } diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java index 114a26bbe83f0..ddcad949b6a79 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/AbstractEnrichProcessor.java @@ -90,7 +90,7 @@ public void execute(IngestDocument ingestDocument, BiConsumer * The key of the cache is based on the search request and the enrich index that will be used. * Search requests that enrich generates target the alias for an enrich policy, this class * resolves the alias to the actual enrich index and uses that for the cache key. This way * no stale entries will be returned if a policy execution happens and a new enrich index is created. - * + *

* There is no cleanup mechanism of stale entries in case a new enrich index is created * as part of a policy execution. This shouldn't be needed as cache entries for prior enrich * indices will be eventually evicted, because these entries will not end up being used. The diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/GeoMatchProcessor.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/GeoMatchProcessor.java index b091ec9b94752..dd164c630495c 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/GeoMatchProcessor.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/GeoMatchProcessor.java @@ -40,7 +40,7 @@ public final class GeoMatchProcessor extends AbstractEnrichProcessor { ) { super(tag, description, searchRunner, policyName, field, targetField, ignoreMissing, overrideEnabled, matchField, maxMatches); this.shapeRelation = shapeRelation; - parser = new GeometryParser(orientation.getAsBoolean(), true, true); + this.parser = new GeometryParser(orientation.getAsBoolean(), true, true); } @Override @@ -50,8 +50,4 @@ public QueryBuilder getQueryBuilder(Object fieldValue) { shapeQuery.relation(shapeRelation); return shapeQuery; } - - public ShapeRelation getShapeRelation() { - return shapeRelation; - } } diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichCoordinatorProxyAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichCoordinatorProxyAction.java index 40356f2824494..4fb12bb5ca3c7 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichCoordinatorProxyAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichCoordinatorProxyAction.java @@ -177,7 +177,7 @@ void coordinateLookups() { assert slots.isEmpty() == false; remoteRequestsTotal.increment(); final MultiSearchRequest multiSearchRequest = new MultiSearchRequest(); - slots.forEach(slot -> multiSearchRequest.add(slot.searchRequest)); + slots.forEach(slot -> multiSearchRequest.add(slot.request)); lookupFunction.accept(multiSearchRequest, (response, e) -> handleResponse(slots, response, e)); } } @@ -193,13 +193,13 @@ void handleResponse(List slots, MultiSearchResponse response, Exception e) Slot slot = slots.get(i); if (responseItem.isFailure()) { - slot.actionListener.onFailure(responseItem.getFailure()); + slot.listener.onFailure(responseItem.getFailure()); } else { - slot.actionListener.onResponse(responseItem.getResponse()); + slot.listener.onResponse(responseItem.getResponse()); } } } else if (e != null) { - slots.forEach(slot -> slot.actionListener.onFailure(e)); + slots.forEach(slot -> slot.listener.onFailure(e)); } else { throw new AssertionError("no response and no error"); } @@ -208,14 +208,10 @@ void handleResponse(List slots, MultiSearchResponse response, Exception e) coordinateLookups(); } - static class Slot { - - final SearchRequest searchRequest; - final ActionListener actionListener; - - Slot(SearchRequest searchRequest, ActionListener actionListener) { - this.searchRequest = Objects.requireNonNull(searchRequest); - this.actionListener = Objects.requireNonNull(actionListener); + record Slot(SearchRequest request, ActionListener listener) { + Slot { + Objects.requireNonNull(request); + Objects.requireNonNull(listener); } }