|
10 | 10 |
|
11 | 11 | import org.elasticsearch.Version;
|
12 | 12 | import org.elasticsearch.index.mapper.TimeSeriesParams;
|
| 13 | +import org.elasticsearch.xcontent.InstantiatingObjectParser; |
13 | 14 | import org.elasticsearch.xcontent.ParseField;
|
14 | 15 | import org.elasticsearch.common.Strings;
|
15 | 16 | import org.elasticsearch.common.io.stream.StreamInput;
|
16 | 17 | import org.elasticsearch.common.io.stream.StreamOutput;
|
17 | 18 | import org.elasticsearch.common.io.stream.Writeable;
|
18 | 19 | import org.elasticsearch.xcontent.ConstructingObjectParser;
|
| 20 | +import org.elasticsearch.xcontent.ParserConstructor; |
19 | 21 | import org.elasticsearch.xcontent.ToXContentObject;
|
20 | 22 | import org.elasticsearch.xcontent.XContentBuilder;
|
21 | 23 | import org.elasticsearch.xcontent.XContentParser;
|
@@ -159,6 +161,59 @@ public FieldCapabilities(String name, String type,
|
159 | 161 |
|
160 | 162 | }
|
161 | 163 |
|
| 164 | + /** |
| 165 | + * Constructor for a set of indices used by parser |
| 166 | + * @param name The name of the field |
| 167 | + * @param type The type associated with the field. |
| 168 | + * @param isMetadataField Whether this field is a metadata field. |
| 169 | + * @param isSearchable Whether this field is indexed for search. |
| 170 | + * @param isAggregatable Whether this field can be aggregated on. |
| 171 | + * @param isDimension Whether this field can be used as dimension |
| 172 | + * @param metricType If this field is a metric field, returns the metric's type or null for non-metrics fields |
| 173 | + * @param indices The list of indices where this field name is defined as {@code type}, |
| 174 | + * or null if all indices have the same {@code type} for the field. |
| 175 | + * @param nonSearchableIndices The list of indices where this field is not searchable, |
| 176 | + * or null if the field is searchable in all indices. |
| 177 | + * @param nonAggregatableIndices The list of indices where this field is not aggregatable, |
| 178 | + * or null if the field is aggregatable in all indices. |
| 179 | + * @param nonDimensionIndices The list of indices where this field is not a dimension |
| 180 | + * @param metricConflictsIndices The list of indices where this field is has different metric types or not mark as a metric |
| 181 | + * @param meta Merged metadata across indices. |
| 182 | + */ |
| 183 | + @SuppressWarnings("unused") |
| 184 | + @ParserConstructor |
| 185 | + public FieldCapabilities( |
| 186 | + String name, |
| 187 | + String type, |
| 188 | + Boolean isMetadataField, |
| 189 | + boolean isSearchable, |
| 190 | + boolean isAggregatable, |
| 191 | + Boolean isDimension, |
| 192 | + String metricType, |
| 193 | + List<String> indices, |
| 194 | + List<String> nonSearchableIndices, |
| 195 | + List<String> nonAggregatableIndices, |
| 196 | + List<String> nonDimensionIndices, |
| 197 | + List<String> metricConflictsIndices, |
| 198 | + Map<String, Set<String>> meta |
| 199 | + ) { |
| 200 | + this( |
| 201 | + name, |
| 202 | + type, |
| 203 | + isMetadataField == null ? false : isMetadataField, |
| 204 | + isSearchable, |
| 205 | + isAggregatable, |
| 206 | + isDimension == null ? false : isDimension, |
| 207 | + metricType != null ? Enum.valueOf(TimeSeriesParams.MetricType.class, metricType) : null, |
| 208 | + indices != null ? indices.toArray(new String[0]) : null, |
| 209 | + nonSearchableIndices != null ? nonSearchableIndices.toArray(new String[0]) : null, |
| 210 | + nonAggregatableIndices != null ? nonAggregatableIndices.toArray(new String[0]) : null, |
| 211 | + nonDimensionIndices != null ? nonDimensionIndices.toArray(new String[0]) : null, |
| 212 | + metricConflictsIndices != null ? metricConflictsIndices.toArray(new String[0]) : null, |
| 213 | + meta != null ? meta : Collections.emptyMap() |
| 214 | + ); |
| 215 | + } |
| 216 | + |
162 | 217 | FieldCapabilities(StreamInput in) throws IOException {
|
163 | 218 | this.name = in.readString();
|
164 | 219 | this.type = in.readString();
|
@@ -254,43 +309,31 @@ public static FieldCapabilities fromXContent(String name, XContentParser parser)
|
254 | 309 | }
|
255 | 310 |
|
256 | 311 | @SuppressWarnings("unchecked")
|
257 |
| - private static final ConstructingObjectParser<FieldCapabilities, String> PARSER = new ConstructingObjectParser<>( |
258 |
| - "field_capabilities", |
259 |
| - true, |
260 |
| - (a, name) -> new FieldCapabilities( |
261 |
| - name, |
262 |
| - (String) a[0], |
263 |
| - a[3] == null ? false : (boolean) a[3], |
264 |
| - (boolean) a[1], |
265 |
| - (boolean) a[2], |
266 |
| - a[4] == null ? false : (boolean) a[4], |
267 |
| - a[5] != null ? Enum.valueOf(TimeSeriesParams.MetricType.class, (String) a[5]) : null, |
268 |
| - a[6] != null ? ((List<String>) a[6]).toArray(new String[0]) : null, |
269 |
| - a[7] != null ? ((List<String>) a[7]).toArray(new String[0]) : null, |
270 |
| - a[8] != null ? ((List<String>) a[8]).toArray(new String[0]) : null, |
271 |
| - a[9] != null ? ((List<String>) a[9]).toArray(new String[0]) : null, |
272 |
| - a[10] != null ? ((List<String>) a[10]).toArray(new String[0]) : null, |
273 |
| - a[11] != null ? ((Map<String, Set<String>>) a[11]) : Collections.emptyMap() |
274 |
| - ) |
275 |
| - ); |
| 312 | + private static final InstantiatingObjectParser<FieldCapabilities, String> PARSER; |
276 | 313 |
|
277 | 314 | static {
|
278 |
| - PARSER.declareString(ConstructingObjectParser.constructorArg(), TYPE_FIELD); // 0 |
279 |
| - PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), SEARCHABLE_FIELD); // 1 |
280 |
| - PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), AGGREGATABLE_FIELD); // 2 |
281 |
| - PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), IS_METADATA_FIELD); // 3 |
282 |
| - PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), TIME_SERIES_DIMENSION_FIELD); // 4 |
283 |
| - PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), TIME_SERIES_METRIC_FIELD); // 5 |
284 |
| - PARSER.declareStringArray(ConstructingObjectParser.optionalConstructorArg(), INDICES_FIELD); // 6 |
285 |
| - PARSER.declareStringArray(ConstructingObjectParser.optionalConstructorArg(), NON_SEARCHABLE_INDICES_FIELD); // 7 |
286 |
| - PARSER.declareStringArray(ConstructingObjectParser.optionalConstructorArg(), NON_AGGREGATABLE_INDICES_FIELD); // 8 |
287 |
| - PARSER.declareStringArray(ConstructingObjectParser.optionalConstructorArg(), NON_DIMENSION_INDICES_FIELD); // 9 |
288 |
| - PARSER.declareStringArray(ConstructingObjectParser.optionalConstructorArg(), METRIC_CONFLICTS_INDICES_FIELD); // 10 |
289 |
| - PARSER.declareObject( |
| 315 | + InstantiatingObjectParser.Builder<FieldCapabilities, String> parser = InstantiatingObjectParser.builder( |
| 316 | + "field_capabilities", |
| 317 | + true, |
| 318 | + FieldCapabilities.class |
| 319 | + ); |
| 320 | + parser.declareString(ConstructingObjectParser.constructorArg(), TYPE_FIELD); |
| 321 | + parser.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), IS_METADATA_FIELD); |
| 322 | + parser.declareBoolean(ConstructingObjectParser.constructorArg(), SEARCHABLE_FIELD); |
| 323 | + parser.declareBoolean(ConstructingObjectParser.constructorArg(), AGGREGATABLE_FIELD); |
| 324 | + parser.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), TIME_SERIES_DIMENSION_FIELD); |
| 325 | + parser.declareString(ConstructingObjectParser.optionalConstructorArg(), TIME_SERIES_METRIC_FIELD); |
| 326 | + parser.declareStringArray(ConstructingObjectParser.optionalConstructorArg(), INDICES_FIELD); |
| 327 | + parser.declareStringArray(ConstructingObjectParser.optionalConstructorArg(), NON_SEARCHABLE_INDICES_FIELD); |
| 328 | + parser.declareStringArray(ConstructingObjectParser.optionalConstructorArg(), NON_AGGREGATABLE_INDICES_FIELD); |
| 329 | + parser.declareStringArray(ConstructingObjectParser.optionalConstructorArg(), NON_DIMENSION_INDICES_FIELD); |
| 330 | + parser.declareStringArray(ConstructingObjectParser.optionalConstructorArg(), METRIC_CONFLICTS_INDICES_FIELD); |
| 331 | + parser.declareObject( |
290 | 332 | ConstructingObjectParser.optionalConstructorArg(),
|
291 |
| - (parser, context) -> parser.map(HashMap::new, p -> Set.copyOf(p.list())), |
| 333 | + (p, context) -> p.map(HashMap::new, v -> Set.copyOf(v.list())), |
292 | 334 | META_FIELD
|
293 |
| - ); // 11 |
| 335 | + ); |
| 336 | + PARSER = parser.build(); |
294 | 337 | }
|
295 | 338 |
|
296 | 339 | /**
|
|
0 commit comments