All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.action.support.IndicesOptions Maven / Gradle / Ivy

There is a newer version: 8.13.2
Show newest version
/*
 * Licensed to Elasticsearch under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.elasticsearch.action.support;


import org.elasticsearch.Version;
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.rest.RestRequest;

import java.io.IOException;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeStringArrayValue;

/**
 * Controls how to deal with unavailable concrete indices (closed or missing), how wildcard expressions are expanded
 * to actual indices (all, closed or open indices) and how to deal with wildcard expressions that resolve to no indices.
 */
public class IndicesOptions implements ToXContentFragment {

    public enum WildcardStates {
        OPEN,
        CLOSED;

        public static final EnumSet NONE = EnumSet.noneOf(WildcardStates.class);

        public static EnumSet parseParameter(Object value, EnumSet defaultStates) {
            if (value == null) {
                return defaultStates;
            }

            Set states = new HashSet<>();
            String[] wildcards = nodeStringArrayValue(value);
            for (String wildcard : wildcards) {
                if ("open".equals(wildcard)) {
                    states.add(OPEN);
                } else if ("closed".equals(wildcard)) {
                    states.add(CLOSED);
                } else if ("none".equals(wildcard)) {
                    states.clear();
                } else if ("all".equals(wildcard)) {
                    states.add(OPEN);
                    states.add(CLOSED);
                } else {
                    throw new IllegalArgumentException("No valid expand wildcard value [" + wildcard + "]");
                }
            }

            return states.isEmpty() ? NONE : EnumSet.copyOf(states);
        }
    }

    public enum Option {
        IGNORE_UNAVAILABLE,
        IGNORE_ALIASES,
        ALLOW_NO_INDICES,
        FORBID_ALIASES_TO_MULTIPLE_INDICES,
        FORBID_CLOSED_INDICES,
        IGNORE_THROTTLED;

        public static final EnumSet




© 2015 - 2024 Weber Informatics LLC | Privacy Policy