Skip to content

Commit

Permalink
Fix enrich policy test bug.
Browse files Browse the repository at this point in the history
Backport #63182 to 7.x branch.

The `randomEnrichPolicy(...)` helper method stores the policy and creates the source indices.
If a source index already exists, because it was creates for a random policy created earlier then
skipping the source index fails, but that is ignored and the test continues. However if the policy
has a match field that doesn't exist in the previous random policy then the mapping is never updated
and the put policy api fails with the fact that the match field can't be found.

This pr fixes that by execute a put mapping call in the event that the source index already exists.

Closes #63126
  • Loading branch information
martijnvg committed Oct 2, 2020
1 parent a4ec87c commit 3e45796
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.elasticsearch.ResourceAlreadyExistsException;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
Expand Down Expand Up @@ -66,7 +67,11 @@ protected static void createSourceIndices(Client client, EnrichPolicy policy) {
try {
client.admin().indices().create(createIndexRequest).actionGet();
} catch (ResourceAlreadyExistsException e) {
// and that is okay
// and that is okay, but update the mapping so that there is always a mapping for match field:
PutMappingRequest putMappingRequest = new PutMappingRequest(sourceIndex);
putMappingRequest.type("_doc");
putMappingRequest.source(policy.getMatchField(), "type=keyword");
client.admin().indices().putMapping(putMappingRequest).actionGet();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public void testGetMultiplePolicies() throws InterruptedException {
assertThat(error.get(), nullValue());

// save a second one to verify the count below on GET
error = saveEnrichPolicy("something-else", randomEnrichPolicy(XContentType.JSON), clusterService);
EnrichPolicy policy2 = randomEnrichPolicy(XContentType.JSON);
error = saveEnrichPolicy("something-else", policy2, clusterService);
assertThat(error.get(), nullValue());

final CountDownLatch latch = new CountDownLatch(1);
Expand Down

0 comments on commit 3e45796

Please sign in to comment.