Skip to content

Commit f366f56

Browse files
committed
Change policy runner to use helper method on EnrichPolicy instead of (#41839)
its own helper method to determine alias / policy base name. This way both the enrich processor and policy runner use the same logic to determine the alias to use. Relates to #32789
1 parent c25736c commit f366f56

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
public final class EnrichPolicy implements Writeable, ToXContentFragment {
3131

32+
private static final String ENRICH_INDEX_NAME_BASE = ".enrich-";
33+
3234
public static final String EXACT_MATCH_TYPE = "exact_match";
3335
public static final String[] SUPPORTED_POLICY_TYPES = new String[]{EXACT_MATCH_TYPE};
3436

@@ -130,9 +132,8 @@ public String getSchedule() {
130132
return schedule;
131133
}
132134

133-
public String getAliasName(String policyName) {
134-
// #41553 (list policy api) will add name to policy, so that we don't have to provide the name via a parameter.
135-
return ".enrich-" + policyName;
135+
public String getBaseName(String policyName) {
136+
return ENRICH_INDEX_NAME_BASE + policyName;
136137
}
137138

138139
@Override

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public class EnrichPolicyRunner implements Runnable {
4949

5050
private static final Logger logger = LogManager.getLogger(EnrichPolicyRunner.class);
5151

52-
private static final String ENRICH_INDEX_NAME_BASE = ".enrich-";
53-
5452
private final String policyName;
5553
private final EnrichPolicy policy;
5654
private final ActionListener<PolicyExecutionResult> listener;
@@ -121,10 +119,6 @@ private void validateMappings(final GetIndexResponse getIndexResponse) {
121119
}
122120
}
123121

124-
private String getEnrichIndexBase(final String policyName) {
125-
return ENRICH_INDEX_NAME_BASE + policyName;
126-
}
127-
128122
private XContentBuilder resolveEnrichMapping(final EnrichPolicy policy) {
129123
// Currently the only supported policy type is EnrichPolicy.EXACT_MATCH_TYPE, which is a keyword type
130124
String keyType;
@@ -160,7 +154,7 @@ private XContentBuilder resolveEnrichMapping(final EnrichPolicy policy) {
160154

161155
private void prepareAndCreateEnrichIndex() {
162156
long nowTimestamp = nowSupplier.getAsLong();
163-
String enrichIndexName = getEnrichIndexBase(policyName) + "-" + nowTimestamp;
157+
String enrichIndexName = policy.getBaseName(policyName) + "-" + nowTimestamp;
164158
Settings enrichIndexSettings = Settings.builder()
165159
.put("index.auto_expand_replicas", "0-all")
166160
.build();
@@ -234,7 +228,7 @@ public void onFailure(Exception e) {
234228
}
235229

236230
private void updateEnrichPolicyAlias(final String destinationIndexName) {
237-
String enrichIndexBase = getEnrichIndexBase(policyName);
231+
String enrichIndexBase = policy.getBaseName(policyName);
238232
logger.debug("Policy [{}]: Promoting new enrich index [{}] to alias [{}]", policyName, destinationIndexName, enrichIndexBase);
239233
GetAliasesRequest aliasRequest = new GetAliasesRequest(enrichIndexBase);
240234
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterService.state(), aliasRequest);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public IngestDocument execute(IngestDocument ingestDocument) throws Exception {
6666
}
6767

6868
// TODO: re-use the engine searcher between enriching documents from the same write request
69-
try (Engine.Searcher engineSearcher = searchProvider.apply(policy.getAliasName(policyName))) {
69+
try (Engine.Searcher engineSearcher = searchProvider.apply(policy.getBaseName(policyName))) {
7070
if (engineSearcher.getDirectoryReader().leaves().size() == 0) {
7171
return ingestDocument;
7272
} else if (engineSearcher.getDirectoryReader().leaves().size() != 1) {

0 commit comments

Comments
 (0)