Skip to content

Commit 2559998

Browse files
authored
Improve naming of enrich policy fields. (#45494)
Renamed `enrich_key` to `match_field` and renamed `enrich_values` to `enrich_fields`. Relates #32789
1 parent 4ea8812 commit 2559998

File tree

13 files changed

+85
-85
lines changed

13 files changed

+85
-85
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/enrich/PutPolicyRequest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ public class PutPolicyRequest implements Validatable, ToXContentObject {
3939
static final ParseField TYPE_FIELD = new ParseField("type");
4040
static final ParseField QUERY_FIELD = new ParseField("query");
4141
static final ParseField INDICES_FIELD = new ParseField("indices");
42-
static final ParseField ENRICH_KEY_FIELD = new ParseField("enrich_key");
43-
static final ParseField ENRICH_VALUES_FIELD = new ParseField("enrich_values");
42+
static final ParseField MATCH_FIELD_FIELD = new ParseField("match_field");
43+
static final ParseField ENRICH_FIELDS_FIELD = new ParseField("enrich_fields");
4444

4545
private final String name;
4646
private final String type;
4747
private BytesReference query;
4848
private final List<String> indices;
49-
private final String enrichKey;
50-
private final List<String> enrichValues;
49+
private final String matchField;
50+
private final List<String> enrichFields;
5151

52-
public PutPolicyRequest(String name, String type, List<String> indices, String enrichKey, List<String> enrichValues) {
52+
public PutPolicyRequest(String name, String type, List<String> indices, String matchField, List<String> enrichFields) {
5353
if (Strings.hasLength(name) == false) {
5454
throw new IllegalArgumentException("name must be a non-null and non-empty string");
5555
}
@@ -59,18 +59,18 @@ public PutPolicyRequest(String name, String type, List<String> indices, String e
5959
if (indices == null || indices.isEmpty()) {
6060
throw new IllegalArgumentException("indices must be specified");
6161
}
62-
if (Strings.hasLength(enrichKey) == false) {
63-
throw new IllegalArgumentException("enrichKey must be a non-null and non-empty string");
62+
if (Strings.hasLength(matchField) == false) {
63+
throw new IllegalArgumentException("matchField must be a non-null and non-empty string");
6464
}
65-
if (enrichValues == null || enrichValues.isEmpty()) {
66-
throw new IllegalArgumentException("enrichValues must be specified");
65+
if (enrichFields == null || enrichFields.isEmpty()) {
66+
throw new IllegalArgumentException("enrichFields must be specified");
6767
}
6868

6969
this.name = name;
7070
this.type = type;
7171
this.indices = indices;
72-
this.enrichKey = enrichKey;
73-
this.enrichValues = enrichValues;
72+
this.matchField = matchField;
73+
this.enrichFields = enrichFields;
7474
}
7575

7676
public String getName() {
@@ -97,12 +97,12 @@ public List<String> getIndices() {
9797
return indices;
9898
}
9999

100-
public String getEnrichKey() {
101-
return enrichKey;
100+
public String getMatchField() {
101+
return matchField;
102102
}
103103

104-
public List<String> getEnrichValues() {
105-
return enrichValues;
104+
public List<String> getEnrichFields() {
105+
return enrichFields;
106106
}
107107

108108
@Override
@@ -113,8 +113,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
113113
if (query != null) {
114114
builder.field(QUERY_FIELD.getPreferredName(), asMap(query, builder.contentType()));
115115
}
116-
builder.field(ENRICH_KEY_FIELD.getPreferredName(), enrichKey);
117-
builder.field(ENRICH_VALUES_FIELD.getPreferredName(), enrichValues);
116+
builder.field(MATCH_FIELD_FIELD.getPreferredName(), matchField);
117+
builder.field(ENRICH_FIELDS_FIELD.getPreferredName(), enrichFields);
118118
builder.endObject();
119119
return builder;
120120
}
@@ -128,13 +128,13 @@ public boolean equals(Object o) {
128128
Objects.equals(type, that.type) &&
129129
Objects.equals(query, that.query) &&
130130
Objects.equals(indices, that.indices) &&
131-
Objects.equals(enrichKey, that.enrichKey) &&
132-
Objects.equals(enrichValues, that.enrichValues);
131+
Objects.equals(matchField, that.matchField) &&
132+
Objects.equals(enrichFields, that.enrichFields);
133133
}
134134

135135
@Override
136136
public int hashCode() {
137-
return Objects.hash(name, type, query, indices, enrichKey, enrichValues);
137+
return Objects.hash(name, type, query, indices, matchField, enrichFields);
138138
}
139139

140140
private static BytesReference xContentToBytes(ToXContentObject object) throws IOException {

client/rest-high-level/src/test/java/org/elasticsearch/client/EnrichIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public void testCRUD() throws Exception {
4747
Map<String, Object> responseBody = toMap(getPolicyResponse);
4848
assertThat(responseBody.get("type"), equalTo(putPolicyRequest.getType()));
4949
assertThat(responseBody.get("indices"), equalTo(putPolicyRequest.getIndices()));
50-
assertThat(responseBody.get("enrich_key"), equalTo(putPolicyRequest.getEnrichKey()));
51-
assertThat(responseBody.get("enrich_values"), equalTo(putPolicyRequest.getEnrichValues()));
50+
assertThat(responseBody.get("match_field"), equalTo(putPolicyRequest.getMatchField()));
51+
assertThat(responseBody.get("enrich_fields"), equalTo(putPolicyRequest.getEnrichFields()));
5252
}
5353

5454
private static Map<String, Object> toMap(Response response) throws IOException {

client/rest-high-level/src/test/java/org/elasticsearch/client/enrich/PutPolicyRequestTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ public void testValidate() {
4141
assertThat(request.validate().isPresent(), is(false));
4242

4343
Exception e = expectThrows(IllegalArgumentException.class,
44-
() -> new PutPolicyRequest(request.getName(), request.getType(), request.getIndices(), null, request.getEnrichValues()));
45-
assertThat(e.getMessage(), containsString("enrichKey must be a non-null and non-empty string"));
44+
() -> new PutPolicyRequest(request.getName(), request.getType(), request.getIndices(), null, request.getEnrichFields()));
45+
assertThat(e.getMessage(), containsString("matchField must be a non-null and non-empty string"));
4646
}
4747

4848
public void testEqualsAndHashcode() {
4949
PutPolicyRequest testInstance = createTestInstance();
5050
EqualsHashCodeTestUtils.checkEqualsAndHashCode(testInstance, (original) -> {
5151
PutPolicyRequest copy = new PutPolicyRequest(original.getName(), original.getType(), original.getIndices(),
52-
original.getEnrichKey(), original.getEnrichValues());
52+
original.getMatchField(), original.getEnrichFields());
5353
copy.setQuery(original.getQuery());
5454
return copy;
5555
});
@@ -99,7 +99,7 @@ protected void assertInstances(PutEnrichPolicyAction.Request serverInstance, Put
9999
} else {
100100
assertThat(serverInstance.getPolicy().getQuery(), nullValue());
101101
}
102-
assertThat(clientTestInstance.getEnrichKey(), equalTo(serverInstance.getPolicy().getEnrichKey()));
103-
assertThat(clientTestInstance.getEnrichValues(), equalTo(serverInstance.getPolicy().getEnrichValues()));
102+
assertThat(clientTestInstance.getMatchField(), equalTo(serverInstance.getPolicy().getMatchField()));
103+
assertThat(clientTestInstance.getEnrichFields(), equalTo(serverInstance.getPolicy().getEnrichFields()));
104104
}
105105
}

docs/reference/ingest/ingest-node.asciidoc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,8 @@ The main piece to configure is the enrich policy:
813813
| `type` | yes | - | The policy type.
814814
| `indices` | yes | - | The indices to fetch the data from.
815815
| `query` | no | `match_all` query | The query to be used to select which documents are included.
816-
| `enrich_key` | yes | - | The field that the enrich processor will query against.
817-
| `enrich_values` | yes | - | The fields to include in the enrich index.
816+
| `match_field` | yes | - | The field that will be used to match against an input document.
817+
| `enrich_fields` | yes | - | The fields that will be available to enrich the input document.
818818
|======
819819

820820
[[enrich-policy-types]]
@@ -859,8 +859,8 @@ PUT /_enrich/policy/users-policy
859859
{
860860
"type": "exact_match",
861861
"indices": "users",
862-
"enrich_key": "email",
863-
"enrich_values": ["first_name", "last_name", "address", "city", "zip", "state"]
862+
"match_field": "email",
863+
"enrich_fields": ["first_name", "last_name", "address", "city", "zip", "state"]
864864
}
865865
--------------------------------------------------
866866
// CONSOLE
@@ -986,8 +986,8 @@ PUT /_enrich/policy/my-policy
986986
{
987987
"type": "exact_match",
988988
"indices": "users",
989-
"enrich_key": "email",
990-
"enrich_values": ["first_name", "last_name", "address", "city", "zip", "state"]
989+
"match_field": "email",
990+
"enrich_fields": ["first_name", "last_name", "address", "city", "zip", "state"]
991991
}
992992
--------------------------------------------------
993993
// CONSOLE
@@ -1023,8 +1023,8 @@ Response:
10231023
{
10241024
"type": "exact_match",
10251025
"indices": ["users"],
1026-
"enrich_key": "email",
1027-
"enrich_values": ["first_name", "last_name", "address", "city", "zip", "state"]
1026+
"match_field": "email",
1027+
"enrich_fields": ["first_name", "last_name", "address", "city", "zip", "state"]
10281028
}
10291029
--------------------------------------------------
10301030
// TESTRESPONSE
@@ -1053,8 +1053,8 @@ Response:
10531053
"name" : "my-policy",
10541054
"type" : "exact_match",
10551055
"indices" : ["users"],
1056-
"enrich_key" : "email",
1057-
"enrich_values" : [
1056+
"match_field" : "email",
1057+
"enrich_fields" : [
10581058
"first_name",
10591059
"last_name",
10601060
"address",

docs/reference/ingest/processors/enrich.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ PUT /_enrich/policy/users-policy
4343
{
4444
"type": "exact_match",
4545
"indices": "users",
46-
"enrich_key": "email",
47-
"enrich_values": ["first_name", "last_name", "address", "city", "zip", "state"]
46+
"match_field": "email",
47+
"enrich_fields": ["first_name", "last_name", "address", "city", "zip", "state"]
4848
}
4949
--------------------------------------------------
5050
// CONSOLE

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public final class EnrichPolicy implements Writeable, ToXContentFragment {
3737
private static final ParseField TYPE = new ParseField("type");
3838
private static final ParseField QUERY = new ParseField("query");
3939
private static final ParseField INDICES = new ParseField("indices");
40-
private static final ParseField ENRICH_KEY = new ParseField("enrich_key");
41-
private static final ParseField ENRICH_VALUES = new ParseField("enrich_values");
40+
private static final ParseField MATCH_FIELD = new ParseField("match_field");
41+
private static final ParseField ENRICH_FIELDS = new ParseField("enrich_fields");
4242

4343
@SuppressWarnings("unchecked")
4444
private static final ConstructingObjectParser<EnrichPolicy, Void> PARSER = new ConstructingObjectParser<>("policy",
@@ -63,8 +63,8 @@ private static void declareParserOptions(ConstructingObjectParser<?, ?> parser)
6363
return new QuerySource(BytesReference.bytes(contentBuilder), contentBuilder.contentType());
6464
}, QUERY);
6565
parser.declareStringArray(ConstructingObjectParser.constructorArg(), INDICES);
66-
parser.declareString(ConstructingObjectParser.constructorArg(), ENRICH_KEY);
67-
parser.declareStringArray(ConstructingObjectParser.constructorArg(), ENRICH_VALUES);
66+
parser.declareString(ConstructingObjectParser.constructorArg(), MATCH_FIELD);
67+
parser.declareStringArray(ConstructingObjectParser.constructorArg(), ENRICH_FIELDS);
6868
}
6969

7070
public static EnrichPolicy fromXContent(XContentParser parser) throws IOException {
@@ -74,8 +74,8 @@ public static EnrichPolicy fromXContent(XContentParser parser) throws IOExceptio
7474
private final String type;
7575
private final QuerySource query;
7676
private final List<String> indices;
77-
private final String enrichKey;
78-
private final List<String> enrichValues;
77+
private final String matchField;
78+
private final List<String> enrichFields;
7979

8080
public EnrichPolicy(StreamInput in) throws IOException {
8181
this(
@@ -90,13 +90,13 @@ public EnrichPolicy(StreamInput in) throws IOException {
9090
public EnrichPolicy(String type,
9191
QuerySource query,
9292
List<String> indices,
93-
String enrichKey,
94-
List<String> enrichValues) {
93+
String matchField,
94+
List<String> enrichFields) {
9595
this.type = type;
9696
this.query= query;
9797
this.indices = indices;
98-
this.enrichKey = enrichKey;
99-
this.enrichValues = enrichValues;
98+
this.matchField = matchField;
99+
this.enrichFields = enrichFields;
100100
}
101101

102102
public String getType() {
@@ -111,12 +111,12 @@ public List<String> getIndices() {
111111
return indices;
112112
}
113113

114-
public String getEnrichKey() {
115-
return enrichKey;
114+
public String getMatchField() {
115+
return matchField;
116116
}
117117

118-
public List<String> getEnrichValues() {
119-
return enrichValues;
118+
public List<String> getEnrichFields() {
119+
return enrichFields;
120120
}
121121

122122
public static String getBaseName(String policyName) {
@@ -128,8 +128,8 @@ public void writeTo(StreamOutput out) throws IOException {
128128
out.writeString(type);
129129
out.writeOptionalWriteable(query);
130130
out.writeStringCollection(indices);
131-
out.writeString(enrichKey);
132-
out.writeStringCollection(enrichValues);
131+
out.writeString(matchField);
132+
out.writeStringCollection(enrichFields);
133133
}
134134

135135
@Override
@@ -139,8 +139,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
139139
builder.field(QUERY.getPreferredName(), query.getQueryAsMap());
140140
}
141141
builder.array(INDICES.getPreferredName(), indices.toArray(new String[0]));
142-
builder.field(ENRICH_KEY.getPreferredName(), enrichKey);
143-
builder.array(ENRICH_VALUES.getPreferredName(), enrichValues.toArray(new String[0]));
142+
builder.field(MATCH_FIELD.getPreferredName(), matchField);
143+
builder.array(ENRICH_FIELDS.getPreferredName(), enrichFields.toArray(new String[0]));
144144
return builder;
145145
}
146146

@@ -152,8 +152,8 @@ public boolean equals(Object o) {
152152
return type.equals(policy.type) &&
153153
Objects.equals(query, policy.query) &&
154154
indices.equals(policy.indices) &&
155-
enrichKey.equals(policy.enrichKey) &&
156-
enrichValues.equals(policy.enrichValues);
155+
matchField.equals(policy.matchField) &&
156+
enrichFields.equals(policy.enrichFields);
157157
}
158158

159159
@Override
@@ -162,8 +162,8 @@ public int hashCode() {
162162
type,
163163
query,
164164
indices,
165-
enrichKey,
166-
enrichValues
165+
matchField,
166+
enrichFields
167167
);
168168
}
169169

x-pack/plugin/enrich/qa/common/src/main/java/org/elasticsearch/test/enrich/CommonEnrichRestTestCase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ private void deletePolicies() throws Exception {
3636
public void testBasicFlow() throws Exception {
3737
// Create the policy:
3838
Request putPolicyRequest = new Request("PUT", "/_enrich/policy/my_policy");
39-
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"my-source-index\"], \"enrich_key\": \"host\", " +
40-
"\"enrich_values\": [\"globalRank\", \"tldRank\", \"tld\"]}");
39+
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"my-source-index\"], \"match_field\": \"host\", " +
40+
"\"enrich_fields\": [\"globalRank\", \"tldRank\", \"tld\"]}");
4141
assertOK(client().performRequest(putPolicyRequest));
4242

4343
// Add entry to source index and then refresh:
@@ -79,8 +79,8 @@ public void testBasicFlow() throws Exception {
7979

8080
public void testImmutablePolicy() throws IOException {
8181
Request putPolicyRequest = new Request("PUT", "/_enrich/policy/my_policy");
82-
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"my-source-index\"], \"enrich_key\": \"host\", " +
83-
"\"enrich_values\": [\"globalRank\", \"tldRank\", \"tld\"]}");
82+
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"my-source-index\"], \"match_field\": \"host\", " +
83+
"\"enrich_fields\": [\"globalRank\", \"tldRank\", \"tld\"]}");
8484
assertOK(client().performRequest(putPolicyRequest));
8585

8686
ResponseException exc = expectThrows(ResponseException.class, () -> client().performRequest(putPolicyRequest));

x-pack/plugin/enrich/qa/rest-with-security/src/test/java/org/elasticsearch/xpack/enrich/EnrichSecurityFailureIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ protected Settings restAdminSettings() {
3434

3535
public void testFailure() {
3636
Request putPolicyRequest = new Request("PUT", "/_enrich/policy/my_policy");
37-
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"my-source-index\"], \"enrich_key\": \"host\", " +
38-
"\"enrich_values\": [\"globalRank\", \"tldRank\", \"tld\"]}");
37+
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"my-source-index\"], \"match_field\": \"host\", " +
38+
"\"enrich_fields\": [\"globalRank\", \"tldRank\", \"tld\"]}");
3939
ResponseException exc = expectThrows(ResponseException.class, () -> client().performRequest(putPolicyRequest));
4040
assertTrue(exc.getMessage().contains("action [cluster:admin/xpack/enrich/put] is unauthorized for user [test_enrich_no_privs]"));
4141
}

x-pack/plugin/enrich/qa/rest-with-security/src/test/java/org/elasticsearch/xpack/enrich/EnrichSecurityIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public void testInsufficientPermissionsOnNonExistentIndex() {
3737
// This test is here because it requires a valid user that has permission to execute policy PUTs but should fail if the user
3838
// does not have access to read the backing indices used to enrich the data.
3939
Request putPolicyRequest = new Request("PUT", "/_enrich/policy/my_policy");
40-
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"some-other-index\"], \"enrich_key\": \"host\", " +
41-
"\"enrich_values\": [\"globalRank\", \"tldRank\", \"tld\"]}");
40+
putPolicyRequest.setJsonEntity("{\"type\": \"exact_match\",\"indices\": [\"some-other-index\"], \"match_field\": \"host\", " +
41+
"\"enrich_fields\": [\"globalRank\", \"tldRank\", \"tld\"]}");
4242
ResponseException exc = expectThrows(ResponseException.class, () -> client().performRequest(putPolicyRequest));
4343
assertThat(exc.getMessage(),
4444
containsString("unable to store policy because no indices match with the specified index patterns [some-other-index]"));

x-pack/plugin/enrich/qa/rest/src/test/resources/rest-api-spec/test/enrich/10_basic.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
body:
88
type: exact_match
99
indices: ["bar*"]
10-
enrich_key: baz
11-
enrich_values: ["a", "b"]
10+
match_field: baz
11+
enrich_fields: ["a", "b"]
1212
- is_true: acknowledged
1313

1414
- do:
@@ -21,17 +21,17 @@
2121
name: policy-crud
2222
- match: { type: exact_match }
2323
- match: { indices: ["bar*"] }
24-
- match: { enrich_key: baz }
25-
- match: { enrich_values: ["a", "b"] }
24+
- match: { match_field: baz }
25+
- match: { enrich_fields: ["a", "b"] }
2626

2727
- do:
2828
enrich.list_policy: {}
2929
- length: { policies: 1 }
3030
- match: { policies.0.name: policy-crud }
3131
- match: { policies.0.type: exact_match }
3232
- match: { policies.0.indices: ["bar*"] }
33-
- match: { policies.0.enrich_key: baz }
34-
- match: { policies.0.enrich_values: ["a", "b"] }
33+
- match: { policies.0.match_field: baz }
34+
- match: { policies.0.enrich_fields: ["a", "b"] }
3535

3636
- do:
3737
enrich.delete_policy:

0 commit comments

Comments
 (0)