Skip to content

Rename enrich policy index_pattern field to indices. #41836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class EnrichPolicy implements Writeable, ToXContentFragment {

static final ParseField TYPE = new ParseField("type");
static final ParseField QUERY = new ParseField("query");
static final ParseField INDEX_PATTERN = new ParseField("index_pattern");
static final ParseField INDICES = new ParseField("indices");
static final ParseField ENRICH_KEY = new ParseField("enrich_key");
static final ParseField ENRICH_VALUES = new ParseField("enrich_values");
static final ParseField SCHEDULE = new ParseField("schedule");
Expand All @@ -45,7 +45,7 @@ public final class EnrichPolicy implements Writeable, ToXContentFragment {
return new EnrichPolicy(
(String) args[0],
(QuerySource) args[1],
(String) args[2],
(List<String>) args[2],
(String) args[3],
(List<String>) args[4],
(String) args[5]
Expand All @@ -64,7 +64,7 @@ private static void declareParserOptions(ConstructingObjectParser parser) {
contentBuilder.generator().copyCurrentStructure(p);
return new QuerySource(BytesReference.bytes(contentBuilder), contentBuilder.contentType());
}, QUERY);
parser.declareString(ConstructingObjectParser.constructorArg(), INDEX_PATTERN);
parser.declareStringArray(ConstructingObjectParser.constructorArg(), INDICES);
parser.declareString(ConstructingObjectParser.constructorArg(), ENRICH_KEY);
parser.declareStringArray(ConstructingObjectParser.constructorArg(), ENRICH_VALUES);
parser.declareString(ConstructingObjectParser.constructorArg(), SCHEDULE);
Expand All @@ -76,7 +76,7 @@ public static EnrichPolicy fromXContent(XContentParser parser) throws IOExceptio

private final String type;
private final QuerySource query;
private final String indexPattern;
private final List<String> indices;
private final String enrichKey;
private final List<String> enrichValues;
private final String schedule;
Expand All @@ -85,7 +85,7 @@ public EnrichPolicy(StreamInput in) throws IOException {
this(
in.readString(),
in.readOptionalWriteable(QuerySource::new),
in.readString(),
in.readStringList(),
in.readString(),
in.readStringList(),
in.readString()
Expand All @@ -94,14 +94,14 @@ public EnrichPolicy(StreamInput in) throws IOException {

public EnrichPolicy(String type,
QuerySource query,
String indexPattern,
List<String> indices,
String enrichKey,
List<String> enrichValues,
String schedule) {
this.type = type;
this.query= query;
this.schedule = schedule;
this.indexPattern = indexPattern;
this.indices = indices;
this.enrichKey = enrichKey;
this.enrichValues = enrichValues;
}
Expand All @@ -114,8 +114,8 @@ public QuerySource getQuery() {
return query;
}

public String getIndexPattern() {
return indexPattern;
public List<String> getIndices() {
return indices;
}

public String getEnrichKey() {
Expand All @@ -139,7 +139,7 @@ public String getAliasName(String policyName) {
public void writeTo(StreamOutput out) throws IOException {
out.writeString(type);
out.writeOptionalWriteable(query);
out.writeString(indexPattern);
out.writeStringCollection(indices);
out.writeString(enrichKey);
out.writeStringCollection(enrichValues);
out.writeString(schedule);
Expand All @@ -151,7 +151,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (query != null) {
builder.field(QUERY.getPreferredName(), query.getQueryAsMap());
}
builder.field(INDEX_PATTERN.getPreferredName(), indexPattern);
builder.array(INDICES.getPreferredName(), indices.toArray(new String[0]));
builder.field(ENRICH_KEY.getPreferredName(), enrichKey);
builder.array(ENRICH_VALUES.getPreferredName(), enrichValues.toArray(new String[0]));
builder.field(SCHEDULE.getPreferredName(), schedule);
Expand All @@ -165,7 +165,7 @@ public boolean equals(Object o) {
EnrichPolicy policy = (EnrichPolicy) o;
return type.equals(policy.type) &&
Objects.equals(query, policy.query) &&
indexPattern.equals(policy.indexPattern) &&
indices.equals(policy.indices) &&
enrichKey.equals(policy.enrichKey) &&
enrichValues.equals(policy.enrichValues) &&
schedule.equals(policy.schedule);
Expand All @@ -176,7 +176,7 @@ public int hashCode() {
return Objects.hash(
type,
query,
indexPattern,
indices,
enrichKey,
enrichValues,
schedule
Expand Down Expand Up @@ -244,7 +244,7 @@ public static class NamedPolicy implements Writeable, ToXContent {
(String) args[0],
new EnrichPolicy((String) args[1],
(QuerySource) args[2],
(String) args[3],
(List<String>) args[3],
(String) args[4],
(List<String>) args[5],
(String) args[6])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void deletePolicies() throws Exception {
public void testBasicFlow() throws Exception {
// Create the policy:
Request putPolicyRequest = new Request("PUT", "/_enrich/policy/my_policy");
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"index_pattern\": \"my-index*\", \"enrich_key\": \"host\", " +
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"my-index*\"], \"enrich_key\": \"host\", " +
"\"enrich_values\": [\"globalRank\", \"tldRank\", \"tld\"], \"schedule\": \"0 5 * * *\"}");
assertOK(client().performRequest(putPolicyRequest));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name: policy-crud
body:
type: exact_match
index_pattern: "bar*"
indices: ["bar*"]
enrich_key: baz
enrich_values: ["a", "b"]
schedule: "*/120"
Expand All @@ -17,7 +17,7 @@
- length: { policies: 1 }
- match: { policies.0.name: policy-crud }
- match: { policies.0.type: exact_match }
- match: { policies.0.index_pattern: "bar*" }
- match: { policies.0.indices: ["bar*"] }
- match: { policies.0.enrich_key: baz }
- match: { policies.0.enrich_values: ["a", "b"] }
- match: { policies.0.schedule: "*/120" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public class EnrichPolicyRunner implements Runnable {
public void run() {
// Collect the source index information
logger.info("Policy [{}]: Running enrich policy", policyName);
final String sourceIndexPattern = policy.getIndexPattern();
logger.debug("Policy [{}]: Checking source index [{}]", policyName, sourceIndexPattern);
GetIndexRequest getIndexRequest = new GetIndexRequest().indices(sourceIndexPattern);
final String[] sourceIndices = policy.getIndices().toArray(new String[0]);
logger.debug("Policy [{}]: Checking source indices [{}]", policyName, sourceIndices);
GetIndexRequest getIndexRequest = new GetIndexRequest().indices(sourceIndices);
client.admin().indices().getIndex(getIndexRequest, new ActionListener<>() {
@Override
public void onResponse(GetIndexResponse getIndexResponse) {
Expand Down Expand Up @@ -110,7 +110,7 @@ private void validateMappings(final GetIndexResponse getIndexResponse) {
listener.onFailure(
new ElasticsearchException(
"Enrich policy execution for [{}] failed. Could not read mapping for source [{}] included by pattern [{}]",
policyName, sourceIndex, policy.getIndexPattern()));
policyName, sourceIndex, policy.getIndices()));
}
if (properties.contains(policy.getEnrichKey()) == false) {
listener.onFailure(
Expand Down Expand Up @@ -193,7 +193,7 @@ private void transferDataToEnrichIndex(final String destinationIndexName) {
}
ReindexRequest reindexRequest = new ReindexRequest()
.setDestIndex(destinationIndexName)
.setSourceIndices(policy.getIndexPattern());
.setSourceIndices(policy.getIndices().toArray(new String[0]));
reindexRequest.getSearchRequest().source(searchSourceBuilder);
reindexRequest.getDestination().source(new BytesArray(new byte[0]), XContentType.SMILE);
client.execute(ReindexAction.INSTANCE, reindexRequest, new ActionListener<>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testRunner() throws Exception {
List<String> enrichFields = new ArrayList<>();
enrichFields.add("field2");
enrichFields.add("field5");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, sourceIndex, "field1", enrichFields, "");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of(sourceIndex), "field1", enrichFields, "");
String policyName = "test1";

ActionListener<PolicyExecutionResult> listener = new ActionListener<PolicyExecutionResult>() {
Expand Down Expand Up @@ -202,7 +202,8 @@ public void testRunnerMultiSource() throws Exception {
enrichFields.add("idx");
enrichFields.add("field2");
enrichFields.add("field5");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, sourceIndexPattern, "field1", enrichFields, "");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of(sourceIndexPattern), "field1",
enrichFields, "");
String policyName = "test1";

ActionListener<PolicyExecutionResult> listener = new ActionListener<PolicyExecutionResult>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static EnrichPolicy randomEnrichPolicy(XContentType xContentType) {
return new EnrichPolicy(
randomFrom(EnrichPolicy.SUPPORTED_POLICY_TYPES),
randomBoolean() ? querySource : null,
randomAlphaOfLength(4),
Arrays.asList(generateRandomStringArray(8, 4, false, false)),
randomAlphaOfLength(4),
Arrays.asList(generateRandomStringArray(8, 4, false, false)),
randomAlphaOfLength(4)
Expand Down Expand Up @@ -89,7 +89,7 @@ public static void assertEqualPolicies(EnrichPolicy expectedInstance, EnrichPoli
} else {
assertThat(expectedInstance.getQuery(), nullValue());
}
assertThat(newInstance.getIndexPattern(), equalTo(expectedInstance.getIndexPattern()));
assertThat(newInstance.getIndices(), equalTo(expectedInstance.getIndices()));
assertThat(newInstance.getEnrichKey(), equalTo(expectedInstance.getEnrichKey()));
assertThat(newInstance.getEnrichValues(), equalTo(expectedInstance.getEnrichValues()));
assertThat(newInstance.getSchedule(), equalTo(expectedInstance.getSchedule()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class EnrichProcessorFactoryTests extends ESTestCase {

public void testCreateProcessorInstance() throws Exception {
List<String> enrichValues = List.of("globalRank", "tldRank", "tld");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, "source_index", "my_key", enrichValues, "schedule");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("source_index"), "my_key",
enrichValues, "schedule");
EnrichProcessorFactory factory = new EnrichProcessorFactory(createClusterStateSupplier("majestic", policy), null);

Map<String, Object> config = new HashMap<>();
Expand Down Expand Up @@ -96,7 +97,8 @@ public void testPolicyDoesNotExist() {

public void testPolicyNameMissing() {
List<String> enrichValues = List.of("globalRank", "tldRank", "tld");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, "source_index", "my_key", enrichValues, "schedule");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("source_index"), "my_key",
enrichValues, "schedule");
EnrichProcessorFactory factory = new EnrichProcessorFactory(createClusterStateSupplier("_name", policy), null);

Map<String, Object> config = new HashMap<>();
Expand Down Expand Up @@ -124,7 +126,7 @@ public void testPolicyNameMissing() {

public void testUnsupportedPolicy() {
List<String> enrichValues = List.of("globalRank", "tldRank", "tld");
EnrichPolicy policy = new EnrichPolicy("unsupported", null, "source_index", "my_key", enrichValues, "schedule");
EnrichPolicy policy = new EnrichPolicy("unsupported", null, List.of("source_index"), "my_key", enrichValues, "schedule");
EnrichProcessorFactory factory = new EnrichProcessorFactory(createClusterStateSupplier("majestic", policy), null);

Map<String, Object> config = new HashMap<>();
Expand Down Expand Up @@ -153,7 +155,8 @@ public void testUnsupportedPolicy() {

public void testNonExistingDecorateField() throws Exception {
List<String> enrichValues = List.of("globalRank", "tldRank", "tld");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, "source_index", "my_key", enrichValues, "schedule");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("source_index"), "my_key",
enrichValues, "schedule");
EnrichProcessorFactory factory = new EnrichProcessorFactory(createClusterStateSupplier("majestic", policy), null);

Map<String, Object> config = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void testBasics() throws Exception {
indexWriter.addDocument(createEnrichDocument("eops.nl", Map.of("globalRank", 4567, "tldRank", 80, "tld", "nl")));
indexWriter.commit();

EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, "majestic_index", "key", List.of(), "schedule");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("majestic_index"), "key",
List.of(), "schedule");
Function<String, EnrichPolicy> policyLookup = policyName -> policy;

try (IndexReader indexReader = DirectoryReader.open(directory)) {
Expand Down Expand Up @@ -98,7 +99,8 @@ public void testNoMatch() throws Exception {
indexWriter.addDocument(createEnrichDocument("eops.nl", Map.of("globalRank", 4567, "tldRank", 80, "tld", "nl")));
indexWriter.commit();

EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, "majestic_index", "key", List.of(), "schedule");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("majestic_index"), "key",
List.of(), "schedule");
Function<String, EnrichPolicy> policyLookup = policyName -> policy;

try (IndexReader indexReader = DirectoryReader.open(directory)) {
Expand Down Expand Up @@ -129,7 +131,8 @@ public void testMoreThanOneSegment() throws Exception {
indexWriter.addDocument(createEnrichDocument("eops.nl", Map.of("globalRank", 4567, "tldRank", 80, "tld", "nl")));
indexWriter.commit();

EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, "majestic_index", "key", List.of(), "schedule");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("majestic_index"), "key",
List.of(), "schedule");
Function<String, EnrichPolicy> policyLookup = policyName -> policy;

try (IndexReader indexReader = DirectoryReader.open(directory)) {
Expand All @@ -156,7 +159,8 @@ public void testEmptyIndex() throws Exception {
try (IndexWriter indexWriter = new IndexWriter(directory, iwConfig)) {
indexWriter.commit();

EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, "majestic_index", "key", List.of(), "schedule");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("majestic_index"), "key",
List.of(), "schedule");
Function<String, EnrichPolicy> policyLookup = policyName -> policy;

try (IndexReader indexReader = DirectoryReader.open(directory)) {
Expand Down Expand Up @@ -187,7 +191,8 @@ public void testEnrichKeyFieldMissing() throws Exception {
indexWriter.addDocument(document);
indexWriter.commit();

EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, "majestic_index", "key", List.of(), "schedule");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("majestic_index"), "key",
List.of(), "schedule");
Function<String, EnrichPolicy> policyLookup = policyName -> policy;

try (IndexReader indexReader = DirectoryReader.open(directory)) {
Expand Down Expand Up @@ -216,7 +221,8 @@ public void testPolicyMissing() {
}

public void testIgnoreKeyMissing() throws Exception {
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, "majestic_index", "key", List.of(), "schedule");
EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("majestic_index"), "key", List.of(),
"schedule");
Function<String, EnrichPolicy> policyLookup = policyName -> policy;
{
ExactMatchProcessor processor = new ExactMatchProcessor("_tag", policyLookup, indexExpression -> null, "_name", "domain",
Expand Down