Indices query should accept alias names, closes #1698.
This commit is contained in:
parent
ff3ebe4a4b
commit
7bd87e12a2
|
@ -21,6 +21,9 @@ package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.search.MatchNoDocsQuery;
|
import org.elasticsearch.common.lucene.search.MatchNoDocsQuery;
|
||||||
import org.elasticsearch.common.lucene.search.Queries;
|
import org.elasticsearch.common.lucene.search.Queries;
|
||||||
|
@ -36,8 +39,12 @@ public class IndicesQueryParser implements QueryParser {
|
||||||
|
|
||||||
public static final String NAME = "indices";
|
public static final String NAME = "indices";
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private final ClusterService clusterService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public IndicesQueryParser() {
|
public IndicesQueryParser(@Nullable ClusterService clusterService) {
|
||||||
|
this.clusterService = clusterService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -99,7 +106,14 @@ public class IndicesQueryParser implements QueryParser {
|
||||||
if (indices.isEmpty()) {
|
if (indices.isEmpty()) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[indices] requires 'indices' element");
|
throw new QueryParsingException(parseContext.index(), "[indices] requires 'indices' element");
|
||||||
}
|
}
|
||||||
for (String index : indices) {
|
|
||||||
|
String[] concreteIndices = indices.toArray(new String[indices.size()]);
|
||||||
|
if (clusterService != null) {
|
||||||
|
MetaData metaData = clusterService.state().metaData();
|
||||||
|
concreteIndices = metaData.concreteIndices(indices.toArray(new String[indices.size()]), true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String index : concreteIndices) {
|
||||||
if (Regex.simpleMatch(index, parseContext.index().name())) {
|
if (Regex.simpleMatch(index, parseContext.index().name())) {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ package org.elasticsearch.indices.query;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.query.*;
|
import org.elasticsearch.index.query.*;
|
||||||
|
@ -36,7 +38,7 @@ public class IndicesQueriesRegistry {
|
||||||
private ImmutableMap<String, FilterParser> filterParsers;
|
private ImmutableMap<String, FilterParser> filterParsers;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public IndicesQueriesRegistry(Settings settings) {
|
public IndicesQueriesRegistry(Settings settings, @Nullable ClusterService clusterService) {
|
||||||
Map<String, QueryParser> queryParsers = Maps.newHashMap();
|
Map<String, QueryParser> queryParsers = Maps.newHashMap();
|
||||||
addQueryParser(queryParsers, new TextQueryParser());
|
addQueryParser(queryParsers, new TextQueryParser());
|
||||||
addQueryParser(queryParsers, new NestedQueryParser());
|
addQueryParser(queryParsers, new NestedQueryParser());
|
||||||
|
@ -70,7 +72,7 @@ public class IndicesQueriesRegistry {
|
||||||
addQueryParser(queryParsers, new FuzzyLikeThisQueryParser());
|
addQueryParser(queryParsers, new FuzzyLikeThisQueryParser());
|
||||||
addQueryParser(queryParsers, new FuzzyLikeThisFieldQueryParser());
|
addQueryParser(queryParsers, new FuzzyLikeThisFieldQueryParser());
|
||||||
addQueryParser(queryParsers, new WrapperQueryParser());
|
addQueryParser(queryParsers, new WrapperQueryParser());
|
||||||
addQueryParser(queryParsers, new IndicesQueryParser());
|
addQueryParser(queryParsers, new IndicesQueryParser(clusterService));
|
||||||
this.queryParsers = ImmutableMap.copyOf(queryParsers);
|
this.queryParsers = ImmutableMap.copyOf(queryParsers);
|
||||||
|
|
||||||
Map<String, FilterParser> filterParsers = Maps.newHashMap();
|
Map<String, FilterParser> filterParsers = Maps.newHashMap();
|
||||||
|
|
|
@ -19,9 +19,12 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.aliases;
|
package org.elasticsearch.test.unit.index.aliases;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.common.compress.CompressedString;
|
import org.elasticsearch.common.compress.CompressedString;
|
||||||
|
import org.elasticsearch.common.inject.AbstractModule;
|
||||||
import org.elasticsearch.common.inject.Injector;
|
import org.elasticsearch.common.inject.Injector;
|
||||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||||
|
import org.elasticsearch.common.inject.util.Providers;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.SettingsModule;
|
import org.elasticsearch.common.settings.SettingsModule;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
|
@ -67,7 +70,13 @@ public class IndexAliasesServiceTests {
|
||||||
new ScriptModule(ImmutableSettings.Builder.EMPTY_SETTINGS),
|
new ScriptModule(ImmutableSettings.Builder.EMPTY_SETTINGS),
|
||||||
new SettingsModule(ImmutableSettings.Builder.EMPTY_SETTINGS),
|
new SettingsModule(ImmutableSettings.Builder.EMPTY_SETTINGS),
|
||||||
new IndexEngineModule(ImmutableSettings.Builder.EMPTY_SETTINGS),
|
new IndexEngineModule(ImmutableSettings.Builder.EMPTY_SETTINGS),
|
||||||
new IndexCacheModule(ImmutableSettings.Builder.EMPTY_SETTINGS)
|
new IndexCacheModule(ImmutableSettings.Builder.EMPTY_SETTINGS),
|
||||||
|
new AbstractModule() {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(ClusterService.class).toProvider(Providers.of((ClusterService) null));
|
||||||
|
}
|
||||||
|
}
|
||||||
).createInjector();
|
).createInjector();
|
||||||
return injector.getInstance(IndexQueryParserService.class);
|
return injector.getInstance(IndexQueryParserService.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,11 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.percolator;
|
package org.elasticsearch.test.unit.index.percolator;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.common.inject.AbstractModule;
|
import org.elasticsearch.common.inject.AbstractModule;
|
||||||
import org.elasticsearch.common.inject.Injector;
|
import org.elasticsearch.common.inject.Injector;
|
||||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||||
|
import org.elasticsearch.common.inject.util.Providers;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.SettingsModule;
|
import org.elasticsearch.common.settings.SettingsModule;
|
||||||
|
@ -78,6 +80,7 @@ public class PercolatorExecutorTests {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(PercolatorExecutor.class).asEagerSingleton();
|
bind(PercolatorExecutor.class).asEagerSingleton();
|
||||||
|
bind(ClusterService.class).toProvider(Providers.of((ClusterService) null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
).createInjector();
|
).createInjector();
|
||||||
|
|
|
@ -23,8 +23,11 @@ import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.search.*;
|
import org.apache.lucene.search.*;
|
||||||
import org.apache.lucene.search.spans.*;
|
import org.apache.lucene.search.spans.*;
|
||||||
import org.apache.lucene.util.NumericUtils;
|
import org.apache.lucene.util.NumericUtils;
|
||||||
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
|
import org.elasticsearch.common.inject.AbstractModule;
|
||||||
import org.elasticsearch.common.inject.Injector;
|
import org.elasticsearch.common.inject.Injector;
|
||||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||||
|
import org.elasticsearch.common.inject.util.Providers;
|
||||||
import org.elasticsearch.common.lucene.search.*;
|
import org.elasticsearch.common.lucene.search.*;
|
||||||
import org.elasticsearch.common.lucene.search.function.BoostScoreFunction;
|
import org.elasticsearch.common.lucene.search.function.BoostScoreFunction;
|
||||||
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
|
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
|
||||||
|
@ -90,7 +93,13 @@ public class SimpleIndexQueryParserTests {
|
||||||
new IndexEngineModule(settings),
|
new IndexEngineModule(settings),
|
||||||
new SimilarityModule(settings),
|
new SimilarityModule(settings),
|
||||||
new IndexQueryParserModule(settings),
|
new IndexQueryParserModule(settings),
|
||||||
new IndexNameModule(index)
|
new IndexNameModule(index),
|
||||||
|
new AbstractModule() {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(ClusterService.class).toProvider(Providers.of((ClusterService) null));
|
||||||
|
}
|
||||||
|
}
|
||||||
).createInjector();
|
).createInjector();
|
||||||
|
|
||||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/test/unit/index/query/mapping.json");
|
String mapping = copyToStringFromClasspath("/org/elasticsearch/test/unit/index/query/mapping.json");
|
||||||
|
|
|
@ -19,8 +19,11 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.query.guice;
|
package org.elasticsearch.test.unit.index.query.guice;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
|
import org.elasticsearch.common.inject.AbstractModule;
|
||||||
import org.elasticsearch.common.inject.Injector;
|
import org.elasticsearch.common.inject.Injector;
|
||||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||||
|
import org.elasticsearch.common.inject.util.Providers;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.SettingsModule;
|
import org.elasticsearch.common.settings.SettingsModule;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
|
@ -68,7 +71,13 @@ public class IndexQueryParserModuleTests {
|
||||||
new IndexEngineModule(settings),
|
new IndexEngineModule(settings),
|
||||||
new SimilarityModule(settings),
|
new SimilarityModule(settings),
|
||||||
new IndexQueryParserModule(settings),
|
new IndexQueryParserModule(settings),
|
||||||
new IndexNameModule(index)
|
new IndexNameModule(index),
|
||||||
|
new AbstractModule() {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(ClusterService.class).toProvider(Providers.of((ClusterService) null));
|
||||||
|
}
|
||||||
|
}
|
||||||
).createInjector();
|
).createInjector();
|
||||||
|
|
||||||
IndexQueryParserService indexQueryParserService = injector.getInstance(IndexQueryParserService.class);
|
IndexQueryParserService indexQueryParserService = injector.getInstance(IndexQueryParserService.class);
|
||||||
|
|
|
@ -19,8 +19,11 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.query.plugin;
|
package org.elasticsearch.test.unit.index.query.plugin;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
|
import org.elasticsearch.common.inject.AbstractModule;
|
||||||
import org.elasticsearch.common.inject.Injector;
|
import org.elasticsearch.common.inject.Injector;
|
||||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||||
|
import org.elasticsearch.common.inject.util.Providers;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.SettingsModule;
|
import org.elasticsearch.common.settings.SettingsModule;
|
||||||
|
@ -66,7 +69,13 @@ public class IndexQueryParserPlugin2Tests {
|
||||||
new IndexEngineModule(settings),
|
new IndexEngineModule(settings),
|
||||||
new SimilarityModule(settings),
|
new SimilarityModule(settings),
|
||||||
queryParserModule,
|
queryParserModule,
|
||||||
new IndexNameModule(index)
|
new IndexNameModule(index),
|
||||||
|
new AbstractModule() {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(ClusterService.class).toProvider(Providers.of((ClusterService) null));
|
||||||
|
}
|
||||||
|
}
|
||||||
).createInjector();
|
).createInjector();
|
||||||
|
|
||||||
IndexQueryParserService indexQueryParserService = injector.getInstance(IndexQueryParserService.class);
|
IndexQueryParserService indexQueryParserService = injector.getInstance(IndexQueryParserService.class);
|
||||||
|
|
|
@ -19,8 +19,11 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.query.plugin;
|
package org.elasticsearch.test.unit.index.query.plugin;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
|
import org.elasticsearch.common.inject.AbstractModule;
|
||||||
import org.elasticsearch.common.inject.Injector;
|
import org.elasticsearch.common.inject.Injector;
|
||||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||||
|
import org.elasticsearch.common.inject.util.Providers;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.SettingsModule;
|
import org.elasticsearch.common.settings.SettingsModule;
|
||||||
|
@ -75,7 +78,13 @@ public class IndexQueryParserPluginTests {
|
||||||
new IndexEngineModule(settings),
|
new IndexEngineModule(settings),
|
||||||
new SimilarityModule(settings),
|
new SimilarityModule(settings),
|
||||||
queryParserModule,
|
queryParserModule,
|
||||||
new IndexNameModule(index)
|
new IndexNameModule(index),
|
||||||
|
new AbstractModule() {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(ClusterService.class).toProvider(Providers.of((ClusterService) null));
|
||||||
|
}
|
||||||
|
}
|
||||||
).createInjector();
|
).createInjector();
|
||||||
|
|
||||||
IndexQueryParserService indexQueryParserService = injector.getInstance(IndexQueryParserService.class);
|
IndexQueryParserService indexQueryParserService = injector.getInstance(IndexQueryParserService.class);
|
||||||
|
|
Loading…
Reference in New Issue