mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-07 05:28:34 +00:00
Remove indices query (#21837)
The indices query is deprecated since 5.0.0 (#17710). It can now be removed in master (future 6.0 version).
This commit is contained in:
parent
0fe6b12553
commit
103984a4a1
@ -24,7 +24,6 @@ import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.settings.IndexScopedSettings;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Setting.Property;
|
||||
@ -40,7 +39,6 @@ import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* This class encapsulates all index level settings and handles settings updates.
|
||||
@ -147,7 +145,6 @@ public final class IndexSettings {
|
||||
private final boolean queryStringAnalyzeWildcard;
|
||||
private final boolean queryStringAllowLeadingWildcard;
|
||||
private final boolean defaultAllowUnmappedFields;
|
||||
private final Predicate<String> indexNameMatcher;
|
||||
private volatile Translog.Durability durability;
|
||||
private final TimeValue syncInterval;
|
||||
private volatile TimeValue refreshInterval;
|
||||
@ -214,7 +211,7 @@ public final class IndexSettings {
|
||||
* @param nodeSettings the nodes settings this index is allocated on.
|
||||
*/
|
||||
public IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSettings) {
|
||||
this(indexMetaData, nodeSettings, (index) -> Regex.simpleMatch(index, indexMetaData.getIndex().getName()), IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
|
||||
this(indexMetaData, nodeSettings, IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,9 +220,8 @@ public final class IndexSettings {
|
||||
*
|
||||
* @param indexMetaData the index metadata this settings object is associated with
|
||||
* @param nodeSettings the nodes settings this index is allocated on.
|
||||
* @param indexNameMatcher a matcher that can resolve an expression to the index name or index alias
|
||||
*/
|
||||
public IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSettings, final Predicate<String> indexNameMatcher, IndexScopedSettings indexScopedSettings) {
|
||||
public IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSettings, IndexScopedSettings indexScopedSettings) {
|
||||
scopedSettings = indexScopedSettings.copy(nodeSettings, indexMetaData);
|
||||
this.nodeSettings = nodeSettings;
|
||||
this.settings = Settings.builder().put(nodeSettings).put(indexMetaData.getSettings()).build();
|
||||
@ -243,7 +239,6 @@ public final class IndexSettings {
|
||||
this.queryStringAllowLeadingWildcard = QUERY_STRING_ALLOW_LEADING_WILDCARD.get(nodeSettings);
|
||||
this.parseFieldMatcher = new ParseFieldMatcher(settings);
|
||||
this.defaultAllowUnmappedFields = scopedSettings.get(ALLOW_UNMAPPED);
|
||||
this.indexNameMatcher = indexNameMatcher;
|
||||
this.durability = scopedSettings.get(INDEX_TRANSLOG_DURABILITY_SETTING);
|
||||
syncInterval = INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.get(settings);
|
||||
refreshInterval = scopedSettings.get(INDEX_REFRESH_INTERVAL_SETTING);
|
||||
@ -258,7 +253,6 @@ public final class IndexSettings {
|
||||
maxRefreshListeners = scopedSettings.get(MAX_REFRESH_LISTENERS_PER_SHARD);
|
||||
maxSlicesPerScroll = scopedSettings.get(MAX_SLICES_PER_SCROLL);
|
||||
this.mergePolicyConfig = new MergePolicyConfig(logger, this);
|
||||
assert indexNameMatcher.test(indexMetaData.getIndex().getName());
|
||||
|
||||
scopedSettings.addSettingsUpdateConsumer(MergePolicyConfig.INDEX_COMPOUND_FORMAT_SETTING, mergePolicyConfig::setNoCFSRatio);
|
||||
scopedSettings.addSettingsUpdateConsumer(MergePolicyConfig.INDEX_MERGE_POLICY_EXPUNGE_DELETES_ALLOWED_SETTING, mergePolicyConfig::setExpungeDeletesAllowed);
|
||||
@ -282,7 +276,6 @@ public final class IndexSettings {
|
||||
scopedSettings.addSettingsUpdateConsumer(INDEX_REFRESH_INTERVAL_SETTING, this::setRefreshInterval);
|
||||
scopedSettings.addSettingsUpdateConsumer(MAX_REFRESH_LISTENERS_PER_SHARD, this::setMaxRefreshListeners);
|
||||
scopedSettings.addSettingsUpdateConsumer(MAX_SLICES_PER_SCROLL, this::setMaxSlicesPerScroll);
|
||||
|
||||
}
|
||||
|
||||
private void setTranslogFlushThresholdSize(ByteSizeValue byteSizeValue) {
|
||||
@ -400,13 +393,6 @@ public final class IndexSettings {
|
||||
*/
|
||||
public ParseFieldMatcher getParseFieldMatcher() { return parseFieldMatcher; }
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the given expression matches the index name or one of it's aliases
|
||||
*/
|
||||
public boolean matchesIndexName(String expression) {
|
||||
return indexNameMatcher.test(expression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the settings and index metadata and notifies all registered settings consumers with the new settings iff at least one setting has changed.
|
||||
*
|
||||
|
@ -1,256 +0,0 @@
|
||||
/*
|
||||
* 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.index.query;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A query that will execute the wrapped query only for the specified indices,
|
||||
* and "match_all" when it does not match those indices (by default).
|
||||
*
|
||||
* @deprecated instead search on the `_index` field
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO remove this class in 6.0
|
||||
public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilder> {
|
||||
|
||||
public static final String NAME = "indices";
|
||||
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
private static final ParseField NO_MATCH_QUERY = new ParseField("no_match_query");
|
||||
private static final ParseField INDEX_FIELD = new ParseField("index");
|
||||
private static final ParseField INDICES_FIELD = new ParseField("indices");
|
||||
|
||||
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(IndicesQueryBuilder.class));
|
||||
|
||||
private final QueryBuilder innerQuery;
|
||||
|
||||
private final String[] indices;
|
||||
|
||||
private QueryBuilder noMatchQuery = defaultNoMatchQuery();
|
||||
|
||||
/**
|
||||
* @deprecated instead search on the `_index` field
|
||||
*/
|
||||
@Deprecated
|
||||
public IndicesQueryBuilder(QueryBuilder innerQuery, String... indices) {
|
||||
DEPRECATION_LOGGER.deprecated("{} query is deprecated. Instead search on the '_index' field", NAME);
|
||||
if (innerQuery == null) {
|
||||
throw new IllegalArgumentException("inner query cannot be null");
|
||||
}
|
||||
if (indices == null || indices.length == 0) {
|
||||
throw new IllegalArgumentException("list of indices cannot be null or empty");
|
||||
}
|
||||
this.innerQuery = Objects.requireNonNull(innerQuery);
|
||||
this.indices = indices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public IndicesQueryBuilder(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
innerQuery = in.readNamedWriteable(QueryBuilder.class);
|
||||
indices = in.readStringArray();
|
||||
noMatchQuery = in.readNamedWriteable(QueryBuilder.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeNamedWriteable(innerQuery);
|
||||
out.writeStringArray(indices);
|
||||
out.writeNamedWriteable(noMatchQuery);
|
||||
}
|
||||
|
||||
public QueryBuilder innerQuery() {
|
||||
return this.innerQuery;
|
||||
}
|
||||
|
||||
public String[] indices() {
|
||||
return this.indices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query to use when it executes on an index that does not match the indices provided.
|
||||
*/
|
||||
public IndicesQueryBuilder noMatchQuery(QueryBuilder noMatchQuery) {
|
||||
if (noMatchQuery == null) {
|
||||
throw new IllegalArgumentException("noMatch query cannot be null");
|
||||
}
|
||||
this.noMatchQuery = noMatchQuery;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the no match query, can either be <tt>all</tt> or <tt>none</tt>.
|
||||
*/
|
||||
public IndicesQueryBuilder noMatchQuery(String type) {
|
||||
this.noMatchQuery = parseNoMatchQuery(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryBuilder noMatchQuery() {
|
||||
return this.noMatchQuery;
|
||||
}
|
||||
|
||||
private static QueryBuilder defaultNoMatchQuery() {
|
||||
return QueryBuilders.matchAllQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.array(INDICES_FIELD.getPreferredName(), indices);
|
||||
builder.field(QUERY_FIELD.getPreferredName());
|
||||
innerQuery.toXContent(builder, params);
|
||||
builder.field(NO_MATCH_QUERY.getPreferredName());
|
||||
noMatchQuery.toXContent(builder, params);
|
||||
printBoostAndQueryName(builder);
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
public static Optional<IndicesQueryBuilder> fromXContent(QueryParseContext parseContext) throws IOException, ParsingException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
|
||||
QueryBuilder innerQuery = null;
|
||||
Collection<String> indices = new ArrayList<>();
|
||||
QueryBuilder noMatchQuery = defaultNoMatchQuery();
|
||||
|
||||
String queryName = null;
|
||||
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||
|
||||
String currentFieldName = null;
|
||||
XContentParser.Token token;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (parseContext.getParseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
// the 2.0 behaviour when encountering "query" : {} is to return no docs for matching indices
|
||||
innerQuery = parseContext.parseInnerQueryBuilder().orElse(new MatchNoneQueryBuilder());
|
||||
} else if (parseContext.getParseFieldMatcher().match(currentFieldName, NO_MATCH_QUERY)) {
|
||||
noMatchQuery = parseContext.parseInnerQueryBuilder().orElse(defaultNoMatchQuery());
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
if (parseContext.getParseFieldMatcher().match(currentFieldName, INDICES_FIELD)) {
|
||||
if (indices.isEmpty() == false) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] indices or index already specified");
|
||||
}
|
||||
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
|
||||
String value = parser.textOrNull();
|
||||
if (value == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] no value specified for 'indices' entry");
|
||||
}
|
||||
indices.add(value);
|
||||
}
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if (parseContext.getParseFieldMatcher().match(currentFieldName, INDEX_FIELD)) {
|
||||
if (indices.isEmpty() == false) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] indices or index already specified");
|
||||
}
|
||||
indices.add(parser.text());
|
||||
} else if (parseContext.getParseFieldMatcher().match(currentFieldName, NO_MATCH_QUERY)) {
|
||||
noMatchQuery = parseNoMatchQuery(parser.text());
|
||||
} else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
|
||||
queryName = parser.text();
|
||||
} else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
|
||||
boost = parser.floatValue();
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (innerQuery == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] requires 'query' element");
|
||||
}
|
||||
if (indices.isEmpty()) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] requires 'indices' or 'index' element");
|
||||
}
|
||||
return Optional.of(new IndicesQueryBuilder(innerQuery, indices.toArray(new String[indices.size()]))
|
||||
.noMatchQuery(noMatchQuery)
|
||||
.boost(boost)
|
||||
.queryName(queryName));
|
||||
}
|
||||
|
||||
static QueryBuilder parseNoMatchQuery(String type) {
|
||||
if ("all".equals(type)) {
|
||||
return QueryBuilders.matchAllQuery();
|
||||
} else if ("none".equals(type)) {
|
||||
return new MatchNoneQueryBuilder();
|
||||
}
|
||||
throw new IllegalArgumentException("query type can only be [all] or [none] but not " + "[" + type + "]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
if (context.matchesIndices(indices)) {
|
||||
return innerQuery.toQuery(context);
|
||||
}
|
||||
return noMatchQuery.toQuery(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int doHashCode() {
|
||||
return Objects.hash(innerQuery, noMatchQuery, Arrays.hashCode(indices));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(IndicesQueryBuilder other) {
|
||||
return Objects.equals(innerQuery, other.innerQuery) &&
|
||||
Arrays.equals(indices, other.indices) && // otherwise we are comparing pointers
|
||||
Objects.equals(noMatchQuery, other.noMatchQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QueryBuilder doRewrite(QueryRewriteContext queryShardContext) throws IOException {
|
||||
QueryBuilder newInnnerQuery = innerQuery.rewrite(queryShardContext);
|
||||
QueryBuilder newNoMatchQuery = noMatchQuery.rewrite(queryShardContext);
|
||||
if (newInnnerQuery != innerQuery || newNoMatchQuery != noMatchQuery) {
|
||||
return new IndicesQueryBuilder(innerQuery, indices).noMatchQuery(noMatchQuery);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
@ -585,18 +585,6 @@ public abstract class QueryBuilders {
|
||||
return new TermsQueryBuilder(name, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* A query that will execute the wrapped query only for the specified
|
||||
* indices, and "match_all" when it does not match those indices.
|
||||
*
|
||||
* @deprecated instead search on the `_index` field
|
||||
*/
|
||||
@Deprecated
|
||||
public static IndicesQueryBuilder indicesQuery(QueryBuilder queryBuilder, String... indices) {
|
||||
// TODO remove this method in 6.0
|
||||
return new IndicesQueryBuilder(queryBuilder, indices);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Query builder which allows building a query thanks to a JSON string or binary data.
|
||||
*/
|
||||
|
@ -19,16 +19,6 @@
|
||||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.queryparser.classic.MapperQueryParser;
|
||||
@ -67,6 +57,16 @@ import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
import org.elasticsearch.search.lookup.SearchLookup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
/**
|
||||
* Context object used to create lucene queries on the shard level.
|
||||
*/
|
||||
@ -282,15 +282,6 @@ public class QueryShardContext extends QueryRewriteContext {
|
||||
return indexSettings.getIndexVersionCreated();
|
||||
}
|
||||
|
||||
public boolean matchesIndices(String... indices) {
|
||||
for (String index : indices) {
|
||||
if (indexSettings.matchesIndexName(index)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ParsedQuery toFilter(QueryBuilder queryBuilder) {
|
||||
return toQuery(queryBuilder, q -> {
|
||||
Query filter = q.toFilter(this);
|
||||
|
@ -134,7 +134,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -427,8 +426,7 @@ public class IndicesService extends AbstractLifecycleComponent
|
||||
Consumer<ShardId> globalCheckpointSyncer,
|
||||
IndexingOperationListener... indexingOperationListeners) throws IOException {
|
||||
final Index index = indexMetaData.getIndex();
|
||||
final Predicate<String> indexNameMatcher = (indexExpression) -> indexNameExpressionResolver.matchesIndex(index.getName(), indexExpression, clusterService.state());
|
||||
final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexNameMatcher, indexScopeSetting);
|
||||
final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexScopeSetting);
|
||||
logger.debug("creating Index [{}], shards [{}]/[{}{}] - reason [{}]",
|
||||
indexMetaData.getIndex(),
|
||||
idxSettings.getNumberOfShards(),
|
||||
@ -466,9 +464,7 @@ public class IndicesService extends AbstractLifecycleComponent
|
||||
* Note: the returned {@link MapperService} should be closed when unneeded.
|
||||
*/
|
||||
public synchronized MapperService createIndexMapperService(IndexMetaData indexMetaData) throws IOException {
|
||||
final Index index = indexMetaData.getIndex();
|
||||
final Predicate<String> indexNameMatcher = (indexExpression) -> indexNameExpressionResolver.matchesIndex(index.getName(), indexExpression, clusterService.state());
|
||||
final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexNameMatcher, indexScopeSetting);
|
||||
final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexScopeSetting);
|
||||
final IndexModule indexModule = new IndexModule(idxSettings, analysisRegistry);
|
||||
pluginsService.onIndexModule(indexModule);
|
||||
return indexModule.newIndexMapperService(mapperRegistry);
|
||||
|
@ -43,7 +43,6 @@ import org.elasticsearch.index.query.GeoShapeQueryBuilder;
|
||||
import org.elasticsearch.index.query.HasChildQueryBuilder;
|
||||
import org.elasticsearch.index.query.HasParentQueryBuilder;
|
||||
import org.elasticsearch.index.query.IdsQueryBuilder;
|
||||
import org.elasticsearch.index.query.IndicesQueryBuilder;
|
||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||
import org.elasticsearch.index.query.MatchNoneQueryBuilder;
|
||||
import org.elasticsearch.index.query.MatchPhrasePrefixQueryBuilder;
|
||||
@ -761,8 +760,6 @@ public class SearchModule {
|
||||
registerQuery(new QuerySpec<>(MoreLikeThisQueryBuilder.NAME, MoreLikeThisQueryBuilder::new,
|
||||
MoreLikeThisQueryBuilder::fromXContent));
|
||||
registerQuery(new QuerySpec<>(WrapperQueryBuilder.NAME, WrapperQueryBuilder::new, WrapperQueryBuilder::fromXContent));
|
||||
// TODO Remove IndicesQuery in 6.0
|
||||
registerQuery(new QuerySpec<>(IndicesQueryBuilder.NAME, IndicesQueryBuilder::new, IndicesQueryBuilder::fromXContent));
|
||||
registerQuery(new QuerySpec<>(CommonTermsQueryBuilder.NAME, CommonTermsQueryBuilder::new, CommonTermsQueryBuilder::fromXContent));
|
||||
registerQuery(
|
||||
new QuerySpec<>(SpanMultiTermQueryBuilder.NAME, SpanMultiTermQueryBuilder::new, SpanMultiTermQueryBuilder::fromXContent));
|
||||
|
@ -21,7 +21,6 @@ package org.elasticsearch.index;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.settings.IndexScopedSettings;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Setting.Property;
|
||||
@ -164,8 +163,7 @@ public class IndexSettingsTests extends ESTestCase {
|
||||
if (settings.length > 0) {
|
||||
settingSet.addAll(Arrays.asList(settings));
|
||||
}
|
||||
return new IndexSettings(metaData, nodeSettings, (idx) -> Regex.simpleMatch(idx, metaData.getIndex().getName()),
|
||||
new IndexScopedSettings(Settings.EMPTY, settingSet));
|
||||
return new IndexSettings(metaData, nodeSettings, new IndexScopedSettings(Settings.EMPTY, settingSet));
|
||||
}
|
||||
|
||||
|
||||
@ -207,8 +205,7 @@ public class IndexSettingsTests extends ESTestCase {
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||
.put(indexSettings)
|
||||
.build();
|
||||
IndexMetaData metaData = IndexMetaData.builder(name).settings(build).build();
|
||||
return metaData;
|
||||
return IndexMetaData.builder(name).settings(build).build();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* 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.index.query;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.test.AbstractQueryTestCase;
|
||||
import org.junit.After;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IndicesQueryBuilderTests extends AbstractQueryTestCase<IndicesQueryBuilder> {
|
||||
|
||||
/**
|
||||
* All tests create deprecation warnings when an new {@link IndicesQueryBuilder} is created.
|
||||
* Instead of having to check them once in every single test, this is done here after each test is run
|
||||
*/
|
||||
@After
|
||||
void checkWarningHeaders() throws IOException {
|
||||
checkWarningHeaders("indices query is deprecated. Instead search on the '_index' field");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IndicesQueryBuilder doCreateTestQueryBuilder() {
|
||||
String[] indices;
|
||||
if (randomBoolean()) {
|
||||
indices = new String[]{getIndex().getName()};
|
||||
} else {
|
||||
indices = generateRandomStringArray(5, 10, false, false);
|
||||
}
|
||||
IndicesQueryBuilder query = new IndicesQueryBuilder(RandomQueryBuilder.createQuery(random()), indices);
|
||||
|
||||
switch (randomInt(2)) {
|
||||
case 0:
|
||||
query.noMatchQuery(RandomQueryBuilder.createQuery(random()));
|
||||
break;
|
||||
case 1:
|
||||
query.noMatchQuery(randomFrom(QueryBuilders.matchAllQuery(), new MatchNoneQueryBuilder()));
|
||||
break;
|
||||
default:
|
||||
// do not set noMatchQuery
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doAssertLuceneQuery(IndicesQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException {
|
||||
Query expected;
|
||||
if (queryBuilder.indices().length == 1 && getIndex().getName().equals(queryBuilder.indices()[0])) {
|
||||
expected = queryBuilder.innerQuery().toQuery(context.getQueryShardContext());
|
||||
} else {
|
||||
expected = queryBuilder.noMatchQuery().toQuery(context.getQueryShardContext());
|
||||
}
|
||||
assertEquals(expected, query);
|
||||
}
|
||||
|
||||
public void testIllegalArguments() {
|
||||
expectThrows(IllegalArgumentException.class, () -> new IndicesQueryBuilder(null, "index"));
|
||||
|
||||
expectThrows(IllegalArgumentException.class, () -> new IndicesQueryBuilder(new MatchAllQueryBuilder(), (String[]) null));
|
||||
expectThrows(IllegalArgumentException.class, () -> new IndicesQueryBuilder(new MatchAllQueryBuilder(), new String[0]));
|
||||
|
||||
IndicesQueryBuilder indicesQueryBuilder = new IndicesQueryBuilder(new MatchAllQueryBuilder(), "index");
|
||||
expectThrows(IllegalArgumentException.class, () -> indicesQueryBuilder.noMatchQuery((QueryBuilder) null));
|
||||
expectThrows(IllegalArgumentException.class, () -> indicesQueryBuilder.noMatchQuery((String) null));
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
String json =
|
||||
"{\n" +
|
||||
" \"indices\" : {\n" +
|
||||
" \"indices\" : [ \"index1\", \"index2\" ],\n" +
|
||||
" \"query\" : {\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"tag\" : {\n" +
|
||||
" \"value\" : \"wow\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"no_match_query\" : {\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"tag\" : {\n" +
|
||||
" \"value\" : \"kow\",\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
IndicesQueryBuilder parsed = (IndicesQueryBuilder) parseQuery(json);
|
||||
checkGeneratedJson(json, parsed);
|
||||
assertEquals(json, 2, parsed.indices().length);
|
||||
assertEquals(json, "kow", ((TermQueryBuilder) parsed.noMatchQuery()).value());
|
||||
assertEquals(json, "wow", ((TermQueryBuilder) parsed.innerQuery()).value());
|
||||
}
|
||||
}
|
@ -54,7 +54,6 @@ import static org.elasticsearch.index.query.QueryBuilders.geoShapeQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.hasChildQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.hasParentQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.idsQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.indicesQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.moreLikeThisQuery;
|
||||
@ -202,18 +201,6 @@ public class QueryDSLDocumentationTests extends ESTestCase {
|
||||
idsQuery().addIds("1", "4", "100");
|
||||
}
|
||||
|
||||
public void testIndices() {
|
||||
indicesQuery(
|
||||
termQuery("tag", "wow"),
|
||||
"index1", "index2"
|
||||
).noMatchQuery(termQuery("tag", "kow"));
|
||||
|
||||
indicesQuery(
|
||||
termQuery("tag", "wow"),
|
||||
"index1", "index2"
|
||||
).noMatchQuery("all");
|
||||
}
|
||||
|
||||
public void testMatchAll() {
|
||||
matchAllQuery();
|
||||
}
|
||||
|
@ -264,7 +264,6 @@ public class SearchModuleTests extends ModuleTestCase {
|
||||
"has_child",
|
||||
"has_parent",
|
||||
"ids",
|
||||
"indices",
|
||||
"match",
|
||||
"match_all",
|
||||
"match_none",
|
||||
|
@ -27,7 +27,6 @@ import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.indicesQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
|
||||
@ -171,44 +170,6 @@ public class MatchedQueriesIT extends ESIntegTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testIndicesFilterSupportsName() {
|
||||
createIndex("test1", "test2");
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test1", "type1", "1").setSource("title", "title1").get();
|
||||
client().prepareIndex("test2", "type1", "2").setSource("title", "title2").get();
|
||||
client().prepareIndex("test2", "type1", "3").setSource("title", "title3").get();
|
||||
refresh();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(boolQuery().must(matchAllQuery()).filter(
|
||||
boolQuery().should(
|
||||
indicesQuery(termQuery("title", "title1").queryName("title1"), "test1")
|
||||
.noMatchQuery(termQuery("title", "title2").queryName("title2")).queryName("indices_filter")).should(
|
||||
termQuery("title", "title3").queryName("title3")).queryName("or"))).get();
|
||||
assertHitCount(searchResponse, 3L);
|
||||
|
||||
for (SearchHit hit : searchResponse.getHits()) {
|
||||
if (hit.id().equals("1")) {
|
||||
assertThat(hit.matchedQueries().length, equalTo(3));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("indices_filter"));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("title1"));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("or"));
|
||||
} else if (hit.id().equals("2")) {
|
||||
assertThat(hit.matchedQueries().length, equalTo(3));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("indices_filter"));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("title2"));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("or"));
|
||||
} else if (hit.id().equals("3")) {
|
||||
assertThat(hit.matchedQueries().length, equalTo(2));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("title3"));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("or"));
|
||||
} else {
|
||||
fail("Unexpected document returned with id " + hit.id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testRegExpQuerySupportsName() {
|
||||
createIndex("test1");
|
||||
ensureGreen();
|
||||
|
@ -19,14 +19,12 @@
|
||||
|
||||
package org.elasticsearch.search.query;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.apache.lucene.util.English;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.action.search.ShardSearchFailure;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
@ -64,9 +62,7 @@ import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.existsQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.functionScoreQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.fuzzyQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.hasChildQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.idsQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.indicesQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.multiMatchQuery;
|
||||
@ -1719,135 +1715,6 @@ public class SearchQueryIT extends ESIntegTestCase {
|
||||
assertHitCount(response, 0);
|
||||
}
|
||||
|
||||
public void testIndicesQuery() throws Exception {
|
||||
createIndex("index1", "index2", "index3");
|
||||
|
||||
|
||||
client().prepareIndex("index1", "type1").setId("1").setSource("text", "value1").get();
|
||||
client().prepareIndex("index2", "type2").setId("2").setSource("text", "value2").get();
|
||||
client().prepareIndex("index3", "type3").setId("3").setSource("text", "value3").get();
|
||||
refresh();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("index1", "index2", "index3")
|
||||
.setQuery(indicesQuery(matchQuery("text", "value1"), "index1")
|
||||
.noMatchQuery(matchQuery("text", "value2"))).get();
|
||||
assertHitCount(searchResponse, 2L);
|
||||
assertSearchHits(searchResponse, "1", "2");
|
||||
|
||||
//default no match query is match_all
|
||||
searchResponse = client().prepareSearch("index1", "index2", "index3")
|
||||
.setQuery(indicesQuery(matchQuery("text", "value1"), "index1")).get();
|
||||
assertHitCount(searchResponse, 3L);
|
||||
assertSearchHits(searchResponse, "1", "2", "3");
|
||||
searchResponse = client().prepareSearch("index1", "index2", "index3")
|
||||
.setQuery(indicesQuery(matchQuery("text", "value1"), "index1")
|
||||
.noMatchQuery(QueryBuilders.matchAllQuery())).get();
|
||||
assertHitCount(searchResponse, 3L);
|
||||
assertSearchHits(searchResponse, "1", "2", "3");
|
||||
|
||||
searchResponse = client().prepareSearch("index1", "index2", "index3")
|
||||
.setQuery(indicesQuery(matchQuery("text", "value1"), "index1")
|
||||
.noMatchQuery("none")).get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
assertFirstHit(searchResponse, hasId("1"));
|
||||
}
|
||||
|
||||
// See #2416
|
||||
public void testIndicesQuerySkipParsing() throws Exception {
|
||||
createIndex("simple");
|
||||
assertAcked(prepareCreate("related")
|
||||
.addMapping("child", jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent")
|
||||
.endObject().endObject().endObject()));
|
||||
|
||||
client().prepareIndex("simple", "lone").setId("1").setSource("text", "value1").get();
|
||||
client().prepareIndex("related", "parent").setId("2").setSource("text", "parent").get();
|
||||
client().prepareIndex("related", "child").setId("3").setParent("2").setSource("text", "value2").get();
|
||||
refresh();
|
||||
|
||||
//has_child fails if executed on "simple" index
|
||||
SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class,
|
||||
() -> client().prepareSearch("simple").setQuery(hasChildQuery("child", matchQuery("text", "value"), ScoreMode.None)).get());
|
||||
assertThat(e.shardFailures().length, greaterThan(0));
|
||||
for (ShardSearchFailure shardSearchFailure : e.shardFailures()) {
|
||||
assertThat(shardSearchFailure.reason(), containsString("no mapping found for type [child]"));
|
||||
}
|
||||
|
||||
//has_child doesn't get parsed for "simple" index
|
||||
SearchResponse searchResponse = client().prepareSearch("related", "simple")
|
||||
.setQuery(indicesQuery(hasChildQuery("child", matchQuery("text", "value2"), ScoreMode.None), "related")
|
||||
.noMatchQuery(matchQuery("text", "value1"))).get();
|
||||
assertHitCount(searchResponse, 2L);
|
||||
assertSearchHits(searchResponse, "1", "2");
|
||||
}
|
||||
|
||||
public void testIndicesQueryMissingIndices() throws IOException, ExecutionException, InterruptedException {
|
||||
createIndex("index1");
|
||||
createIndex("index2");
|
||||
|
||||
indexRandom(true,
|
||||
client().prepareIndex("index1", "type1", "1").setSource("field", "match"),
|
||||
client().prepareIndex("index1", "type1", "2").setSource("field", "no_match"),
|
||||
client().prepareIndex("index2", "type1", "10").setSource("field", "match"),
|
||||
client().prepareIndex("index2", "type1", "20").setSource("field", "no_match"),
|
||||
client().prepareIndex("index3", "type1", "100").setSource("field", "match"),
|
||||
client().prepareIndex("index3", "type1", "200").setSource("field", "no_match"));
|
||||
|
||||
//all indices are missing
|
||||
SearchResponse searchResponse = client().prepareSearch().setQuery(
|
||||
indicesQuery(termQuery("field", "missing"), "test1", "test2", "test3")
|
||||
.noMatchQuery(termQuery("field", "match"))).get();
|
||||
|
||||
assertHitCount(searchResponse, 3L);
|
||||
|
||||
for (SearchHit hit : searchResponse.getHits().getHits()) {
|
||||
if ("index1".equals(hit.index())) {
|
||||
assertThat(hit, hasId("1"));
|
||||
} else if ("index2".equals(hit.index())) {
|
||||
assertThat(hit, hasId("10"));
|
||||
} else if ("index3".equals(hit.index())) {
|
||||
assertThat(hit, hasId("100"));
|
||||
} else {
|
||||
fail("Returned documents should belong to either index1, index2 or index3");
|
||||
}
|
||||
}
|
||||
|
||||
//only one index specified, which is missing
|
||||
searchResponse = client().prepareSearch().setQuery(
|
||||
indicesQuery(termQuery("field", "missing"), "test1")
|
||||
.noMatchQuery(termQuery("field", "match"))).get();
|
||||
|
||||
assertHitCount(searchResponse, 3L);
|
||||
|
||||
for (SearchHit hit : searchResponse.getHits().getHits()) {
|
||||
if ("index1".equals(hit.index())) {
|
||||
assertThat(hit, hasId("1"));
|
||||
} else if ("index2".equals(hit.index())) {
|
||||
assertThat(hit, hasId("10"));
|
||||
} else if ("index3".equals(hit.index())) {
|
||||
assertThat(hit, hasId("100"));
|
||||
} else {
|
||||
fail("Returned documents should belong to either index1, index2 or index3");
|
||||
}
|
||||
}
|
||||
|
||||
//more than one index specified, one of them is missing
|
||||
searchResponse = client().prepareSearch().setQuery(
|
||||
indicesQuery(termQuery("field", "missing"), "index1", "test1")
|
||||
.noMatchQuery(termQuery("field", "match"))).get();
|
||||
|
||||
assertHitCount(searchResponse, 2L);
|
||||
|
||||
for (SearchHit hit : searchResponse.getHits().getHits()) {
|
||||
if ("index2".equals(hit.index())) {
|
||||
assertThat(hit, hasId("10"));
|
||||
} else if ("index3".equals(hit.index())) {
|
||||
assertThat(hit, hasId("100"));
|
||||
} else {
|
||||
fail("Returned documents should belong to either index2 or index3");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testMinScore() throws ExecutionException, InterruptedException {
|
||||
createIndex("test");
|
||||
|
||||
|
@ -37,15 +37,9 @@ implemented with scripting.
|
||||
Return documents which match a `positive` query, but reduce the score of
|
||||
documents which also match a `negative` query.
|
||||
|
||||
<<java-query-dsl-indices-query,`indices` query>>::
|
||||
|
||||
Execute one query for the specified indices, and another for other indices.
|
||||
|
||||
|
||||
include::constant-score-query.asciidoc[]
|
||||
include::bool-query.asciidoc[]
|
||||
include::dis-max-query.asciidoc[]
|
||||
include::function-score-query.asciidoc[]
|
||||
include::boosting-query.asciidoc[]
|
||||
include::indices-query.asciidoc[]
|
||||
|
||||
|
@ -1,29 +0,0 @@
|
||||
[[java-query-dsl-indices-query]]
|
||||
==== Indices Query
|
||||
|
||||
See {ref}/query-dsl-indices-query.html[Indices Query]
|
||||
|
||||
[source,java]
|
||||
--------------------------------------------------
|
||||
// Using another query when no match for the main one
|
||||
QueryBuilder qb = indicesQuery(
|
||||
termQuery("tag", "wow"), <1>
|
||||
"index1", "index2" <2>
|
||||
).noMatchQuery(termQuery("tag", "kow")); <3>
|
||||
--------------------------------------------------
|
||||
<1> query to be executed on selected indices
|
||||
<2> selected indices
|
||||
<3> query to be executed on non matching indices
|
||||
|
||||
[source,java]
|
||||
--------------------------------------------------
|
||||
// Using all (match all) or none (match no documents)
|
||||
QueryBuilder qb = indicesQuery(
|
||||
termQuery("tag", "wow"), <1>
|
||||
"index1", "index2" <2>
|
||||
).noMatchQuery("all"); <3>
|
||||
--------------------------------------------------
|
||||
<1> query to be executed on selected indices
|
||||
<2> selected indices
|
||||
<3> `none` (to match no documents), and `all` (to match all documents). Defaults to `all`.
|
||||
|
@ -21,6 +21,8 @@
|
||||
* The `terms` query now always returns scores equal to `1` and is not subject to
|
||||
`indices.query.bool.max_clause_count` anymore.
|
||||
|
||||
* The deprecated `indices` query has been removed.
|
||||
|
||||
==== Search shards API
|
||||
|
||||
The search shards API no longer accepts the `type` url parameter, which didn't
|
||||
|
@ -37,14 +37,9 @@ implemented with scripting.
|
||||
Return documents which match a `positive` query, but reduce the score of
|
||||
documents which also match a `negative` query.
|
||||
|
||||
<<query-dsl-indices-query,`indices` query>>::
|
||||
|
||||
Execute one query for the specified indices, and another for other indices.
|
||||
|
||||
|
||||
include::constant-score-query.asciidoc[]
|
||||
include::bool-query.asciidoc[]
|
||||
include::dis-max-query.asciidoc[]
|
||||
include::function-score-query.asciidoc[]
|
||||
include::boosting-query.asciidoc[]
|
||||
include::indices-query.asciidoc[]
|
||||
|
@ -1,33 +0,0 @@
|
||||
[[query-dsl-indices-query]]
|
||||
=== Indices Query
|
||||
|
||||
deprecated[5.0.0, Search on the '_index' field instead]
|
||||
|
||||
The `indices` query is useful in cases where a search is executed across
|
||||
multiple indices. It allows to specify a list of index names and an inner
|
||||
query that is only executed for indices matching names on that list.
|
||||
For other indices that are searched, but that don't match entries
|
||||
on the list, the alternative `no_match_query` is executed.
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"indices" : {
|
||||
"indices" : ["index1", "index2"],
|
||||
"query" : { "term" : { "tag" : "wow" } },
|
||||
"no_match_query" : { "term" : { "tag" : "kow" } }
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
// TEST[warning:indices query is deprecated. Instead search on the '_index' field]
|
||||
|
||||
You can use the `index` field to provide a single index.
|
||||
|
||||
`no_match_query` can also have "string" value of `none` (to match no
|
||||
documents), and `all` (to match all). Defaults to `all`.
|
||||
|
||||
`query` is mandatory, as well as `indices` (or `index`).
|
@ -163,13 +163,6 @@ The `ids` filter has been replaced by the <<query-dsl-ids-query>>. It behaves
|
||||
as a query in ``query context'' and as a filter in ``filter context'' (see
|
||||
<<query-dsl>>).
|
||||
|
||||
[role="exclude",id="query-dsl-indices-filter"]
|
||||
=== Indices Filter
|
||||
|
||||
The `indices` filter has been replaced by the <<query-dsl-indices-query>>. It behaves
|
||||
as a query in ``query context'' and as a filter in ``filter context'' (see
|
||||
<<query-dsl>>).
|
||||
|
||||
[role="exclude",id="query-dsl-match-all-filter"]
|
||||
=== Match All Filter
|
||||
|
||||
|
@ -21,7 +21,6 @@ package org.elasticsearch.test;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.settings.IndexScopedSettings;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
@ -67,7 +66,7 @@ public class IndexSettingsModule extends AbstractModule {
|
||||
if (setting.length > 0) {
|
||||
settingSet.addAll(Arrays.asList(setting));
|
||||
}
|
||||
return new IndexSettings(metaData, nodeSettings, (idx) -> Regex.simpleMatch(idx, metaData.getIndex().getName()), new IndexScopedSettings(Settings.EMPTY, settingSet));
|
||||
return new IndexSettings(metaData, nodeSettings, new IndexScopedSettings(Settings.EMPTY, settingSet));
|
||||
}
|
||||
|
||||
public static IndexSettings newIndexSettings(Index index, Settings settings, IndexScopedSettings indexScopedSettings) {
|
||||
@ -77,7 +76,7 @@ public class IndexSettingsModule extends AbstractModule {
|
||||
.put(settings)
|
||||
.build();
|
||||
IndexMetaData metaData = IndexMetaData.builder(index.getName()).settings(build).build();
|
||||
return new IndexSettings(metaData, Settings.EMPTY, (idx) -> Regex.simpleMatch(idx, metaData.getIndex().getName()), indexScopedSettings);
|
||||
return new IndexSettings(metaData, Settings.EMPTY, indexScopedSettings);
|
||||
}
|
||||
|
||||
public static IndexSettings newIndexSettings(final IndexMetaData indexMetaData, Setting<?>... setting) {
|
||||
@ -85,7 +84,6 @@ public class IndexSettingsModule extends AbstractModule {
|
||||
if (setting.length > 0) {
|
||||
settingSet.addAll(Arrays.asList(setting));
|
||||
}
|
||||
return new IndexSettings(indexMetaData, Settings.EMPTY, (idx) -> Regex.simpleMatch(idx, indexMetaData.getIndex().getName()),
|
||||
new IndexScopedSettings(Settings.EMPTY, settingSet));
|
||||
return new IndexSettings(indexMetaData, Settings.EMPTY, new IndexScopedSettings(Settings.EMPTY, settingSet));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user