5
5
*/
6
6
package org .elasticsearch .xpack .core .ml .job .results ;
7
7
8
+ import org .elasticsearch .Version ;
8
9
import org .elasticsearch .common .ParseField ;
9
10
import org .elasticsearch .common .io .stream .StreamInput ;
10
11
import org .elasticsearch .common .io .stream .StreamOutput ;
@@ -34,6 +35,7 @@ public class CategoryDefinition implements ToXContentObject, Writeable {
34
35
public static final ParseField REGEX = new ParseField ("regex" );
35
36
public static final ParseField MAX_MATCHING_LENGTH = new ParseField ("max_matching_length" );
36
37
public static final ParseField EXAMPLES = new ParseField ("examples" );
38
+ public static final ParseField GROK_PATTERN = new ParseField ("grok_pattern" );
37
39
38
40
// Used for QueryPage
39
41
public static final ParseField RESULTS_FIELD = new ParseField ("categories" );
@@ -51,6 +53,7 @@ private static ConstructingObjectParser<CategoryDefinition, Void> createParser(b
51
53
parser .declareString (CategoryDefinition ::setRegex , REGEX );
52
54
parser .declareLong (CategoryDefinition ::setMaxMatchingLength , MAX_MATCHING_LENGTH );
53
55
parser .declareStringArray (CategoryDefinition ::setExamples , EXAMPLES );
56
+ parser .declareString (CategoryDefinition ::setGrokPattern , GROK_PATTERN );
54
57
55
58
return parser ;
56
59
}
@@ -61,6 +64,7 @@ private static ConstructingObjectParser<CategoryDefinition, Void> createParser(b
61
64
private String regex = "" ;
62
65
private long maxMatchingLength = 0L ;
63
66
private final Set <String > examples ;
67
+ private String grokPattern ;
64
68
65
69
public CategoryDefinition (String jobId ) {
66
70
this .jobId = jobId ;
@@ -74,6 +78,9 @@ public CategoryDefinition(StreamInput in) throws IOException {
74
78
regex = in .readString ();
75
79
maxMatchingLength = in .readLong ();
76
80
examples = new TreeSet <>(in .readList (StreamInput ::readString ));
81
+ if (in .getVersion ().onOrAfter (Version .V_7_0_0_alpha1 )) {
82
+ grokPattern = in .readOptionalString ();
83
+ }
77
84
}
78
85
79
86
@ Override
@@ -84,6 +91,9 @@ public void writeTo(StreamOutput out) throws IOException {
84
91
out .writeString (regex );
85
92
out .writeLong (maxMatchingLength );
86
93
out .writeStringList (new ArrayList <>(examples ));
94
+ if (out .getVersion ().onOrAfter (Version .V_7_0_0_alpha1 )) {
95
+ out .writeOptionalString (grokPattern );
96
+ }
87
97
}
88
98
89
99
public String getJobId () {
@@ -139,6 +149,14 @@ public void addExample(String example) {
139
149
examples .add (example );
140
150
}
141
151
152
+ public String getGrokPattern () {
153
+ return grokPattern ;
154
+ }
155
+
156
+ public void setGrokPattern (String grokPattern ) {
157
+ this .grokPattern = grokPattern ;
158
+ }
159
+
142
160
@ Override
143
161
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
144
162
builder .startObject ();
@@ -148,6 +166,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
148
166
builder .field (REGEX .getPreferredName (), regex );
149
167
builder .field (MAX_MATCHING_LENGTH .getPreferredName (), maxMatchingLength );
150
168
builder .field (EXAMPLES .getPreferredName (), examples );
169
+ if (grokPattern != null ) {
170
+ builder .field (GROK_PATTERN .getPreferredName (), grokPattern );
171
+ }
151
172
builder .endObject ();
152
173
return builder ;
153
174
}
@@ -166,11 +187,12 @@ public boolean equals(Object other) {
166
187
&& Objects .equals (this .terms , that .terms )
167
188
&& Objects .equals (this .regex , that .regex )
168
189
&& Objects .equals (this .maxMatchingLength , that .maxMatchingLength )
169
- && Objects .equals (this .examples , that .examples );
190
+ && Objects .equals (this .examples , that .examples )
191
+ && Objects .equals (this .grokPattern , that .grokPattern );
170
192
}
171
193
172
194
@ Override
173
195
public int hashCode () {
174
- return Objects .hash (jobId , categoryId , terms , regex , maxMatchingLength , examples );
196
+ return Objects .hash (jobId , categoryId , terms , regex , maxMatchingLength , examples , grokPattern );
175
197
}
176
198
}
0 commit comments