From eabebdad1551aa35f30f11db7869d72867d3b2ad Mon Sep 17 00:00:00 2001 From: Jay Modi Date: Mon, 23 Nov 2020 08:31:35 -0700 Subject: [PATCH] Watcher understands hidden expand wildcard value (#65332) Watcher has a search template that stores indices options to be used as part of a search during watch execution, but this was not updated to be aware of hidden indices and the `hidden` expand_wildcards option. This change makes use of the `IndicesOptions#toXContent` method in Watcher, which already handles the new value. Additionally, the XContent parsing is moved to the IndicesOptions class so that we will be less likely to miss updating this in the future. Closes #65148 Backport of #65332 --- .../action/support/IndicesOptions.java | 130 ++++++++++++++---- .../action/support/IndicesOptionsTests.java | 93 ++++++++++++- .../search/WatcherSearchTemplateRequest.java | 63 +-------- 3 files changed, 193 insertions(+), 93 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java b/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java index 2352fadab79b3..676112c2eb88d 100644 --- a/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java +++ b/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java @@ -19,15 +19,18 @@ package org.elasticsearch.action.support; import org.elasticsearch.Version; +import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.rest.RestRequest; import java.io.IOException; -import java.util.Collection; import java.util.EnumSet; import java.util.Locale; import java.util.Map; @@ -59,25 +62,7 @@ public static EnumSet parseParameter(Object value, EnumSet states, XConten } return builder; } + + private static void updateSetForValue(EnumSet states, String wildcard) { + switch (wildcard) { + case "open": + states.add(OPEN); + break; + case "closed": + states.add(CLOSED); + break; + case "hidden": + states.add(HIDDEN); + break; + case "none": + states.clear(); + break; + case "all": + states.addAll(EnumSet.allOf(WildcardStates.class)); + break; + default: + throw new IllegalArgumentException("No valid expand wildcard value [" + wildcard + "]"); + } + } } public enum Option { @@ -148,11 +155,6 @@ public IndicesOptions(EnumSet