|
@@ -25,33 +25,17 @@ import org.apache.lucene.search.BoostQuery;
|
|
|
import org.apache.lucene.search.Query;
|
|
|
import org.apache.lucene.search.TermQuery;
|
|
|
import org.apache.lucene.search.spans.SpanBoostQuery;
|
|
|
-import org.apache.lucene.util.Accountable;
|
|
|
import org.elasticsearch.ElasticsearchParseException;
|
|
|
import org.elasticsearch.Version;
|
|
|
-import org.elasticsearch.action.ActionListener;
|
|
|
-import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
|
|
|
-import org.elasticsearch.action.get.GetRequest;
|
|
|
-import org.elasticsearch.action.get.GetResponse;
|
|
|
import org.elasticsearch.action.support.PlainActionFuture;
|
|
|
-import org.elasticsearch.action.termvectors.MultiTermVectorsRequest;
|
|
|
-import org.elasticsearch.action.termvectors.MultiTermVectorsResponse;
|
|
|
-import org.elasticsearch.client.Client;
|
|
|
-import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
|
-import org.elasticsearch.cluster.metadata.MetaData;
|
|
|
import org.elasticsearch.common.ParsingException;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.collect.Tuple;
|
|
|
-import org.elasticsearch.common.compress.CompressedXContent;
|
|
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
|
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
|
|
-import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
|
|
-import org.elasticsearch.common.settings.IndexScopedSettings;
|
|
|
-import org.elasticsearch.common.settings.Setting;
|
|
|
-import org.elasticsearch.common.settings.Settings;
|
|
|
-import org.elasticsearch.common.settings.SettingsModule;
|
|
|
import org.elasticsearch.common.unit.Fuzziness;
|
|
|
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
|
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
@@ -64,55 +48,18 @@ import org.elasticsearch.common.xcontent.XContentParseException;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|
|
-import org.elasticsearch.core.internal.io.IOUtils;
|
|
|
-import org.elasticsearch.env.Environment;
|
|
|
-import org.elasticsearch.env.TestEnvironment;
|
|
|
-import org.elasticsearch.index.Index;
|
|
|
-import org.elasticsearch.index.IndexSettings;
|
|
|
-import org.elasticsearch.index.analysis.IndexAnalyzers;
|
|
|
-import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
|
|
|
-import org.elasticsearch.index.fielddata.IndexFieldData;
|
|
|
-import org.elasticsearch.index.fielddata.IndexFieldDataCache;
|
|
|
-import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
|
|
-import org.elasticsearch.index.mapper.MappedFieldType;
|
|
|
-import org.elasticsearch.index.mapper.MapperService;
|
|
|
import org.elasticsearch.index.query.AbstractQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryRewriteContext;
|
|
|
import org.elasticsearch.index.query.QueryShardContext;
|
|
|
import org.elasticsearch.index.query.Rewriteable;
|
|
|
import org.elasticsearch.index.query.support.QueryParsers;
|
|
|
-import org.elasticsearch.index.shard.ShardId;
|
|
|
-import org.elasticsearch.index.similarity.SimilarityService;
|
|
|
-import org.elasticsearch.indices.IndicesModule;
|
|
|
-import org.elasticsearch.indices.analysis.AnalysisModule;
|
|
|
-import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
|
|
-import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
|
|
-import org.elasticsearch.indices.mapper.MapperRegistry;
|
|
|
-import org.elasticsearch.node.InternalSettingsPreparer;
|
|
|
-import org.elasticsearch.plugins.MapperPlugin;
|
|
|
-import org.elasticsearch.plugins.Plugin;
|
|
|
-import org.elasticsearch.plugins.PluginsService;
|
|
|
-import org.elasticsearch.plugins.ScriptPlugin;
|
|
|
-import org.elasticsearch.plugins.SearchPlugin;
|
|
|
-import org.elasticsearch.script.ScriptModule;
|
|
|
-import org.elasticsearch.script.ScriptService;
|
|
|
-import org.elasticsearch.search.SearchModule;
|
|
|
import org.elasticsearch.search.internal.SearchContext;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.joda.time.DateTimeZone;
|
|
|
-import org.junit.After;
|
|
|
-import org.junit.AfterClass;
|
|
|
-import org.junit.Before;
|
|
|
-import org.junit.BeforeClass;
|
|
|
|
|
|
-import java.io.Closeable;
|
|
|
import java.io.IOException;
|
|
|
-import java.lang.reflect.InvocationHandler;
|
|
|
-import java.lang.reflect.Method;
|
|
|
-import java.lang.reflect.Proxy;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Deque;
|
|
|
import java.util.HashSet;
|
|
@@ -121,12 +68,7 @@ import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
-import java.util.concurrent.ExecutionException;
|
|
|
-import java.util.function.Function;
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
-import static java.util.Collections.emptyList;
|
|
|
-import static java.util.stream.Collectors.toList;
|
|
|
import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder;
|
|
|
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
|
|
|
import static org.hamcrest.CoreMatchers.equalTo;
|
|
@@ -136,115 +78,9 @@ import static org.hamcrest.Matchers.greaterThan;
|
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
|
|
|
|
|
|
|
-public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>> extends ESTestCase {
|
|
|
-
|
|
|
- public static final String STRING_FIELD_NAME = "mapped_string";
|
|
|
- protected static final String STRING_FIELD_NAME_2 = "mapped_string_2";
|
|
|
- protected static final String INT_FIELD_NAME = "mapped_int";
|
|
|
- protected static final String INT_RANGE_FIELD_NAME = "mapped_int_range";
|
|
|
- protected static final String DOUBLE_FIELD_NAME = "mapped_double";
|
|
|
- protected static final String BOOLEAN_FIELD_NAME = "mapped_boolean";
|
|
|
- protected static final String DATE_FIELD_NAME = "mapped_date";
|
|
|
- protected static final String DATE_RANGE_FIELD_NAME = "mapped_date_range";
|
|
|
- protected static final String OBJECT_FIELD_NAME = "mapped_object";
|
|
|
- protected static final String GEO_POINT_FIELD_NAME = "mapped_geo_point";
|
|
|
- protected static final String GEO_SHAPE_FIELD_NAME = "mapped_geo_shape";
|
|
|
- protected static final String[] MAPPED_FIELD_NAMES = new String[]{STRING_FIELD_NAME, INT_FIELD_NAME, INT_RANGE_FIELD_NAME,
|
|
|
- DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME, DATE_RANGE_FIELD_NAME, OBJECT_FIELD_NAME, GEO_POINT_FIELD_NAME,
|
|
|
- GEO_SHAPE_FIELD_NAME};
|
|
|
- private static final String[] MAPPED_LEAF_FIELD_NAMES = new String[]{STRING_FIELD_NAME, INT_FIELD_NAME, INT_RANGE_FIELD_NAME,
|
|
|
- DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME, DATE_RANGE_FIELD_NAME, GEO_POINT_FIELD_NAME, };
|
|
|
- private static final int NUMBER_OF_TESTQUERIES = 20;
|
|
|
-
|
|
|
- protected static Version indexVersionCreated;
|
|
|
-
|
|
|
- private static ServiceHolder serviceHolder;
|
|
|
- private static int queryNameId = 0;
|
|
|
- private static Settings nodeSettings;
|
|
|
- private static Index index;
|
|
|
- private static String[] currentTypes;
|
|
|
- private static String[] randomTypes;
|
|
|
-
|
|
|
- protected static Index getIndex() {
|
|
|
- return index;
|
|
|
- }
|
|
|
-
|
|
|
- protected static String[] getCurrentTypes() {
|
|
|
- return currentTypes;
|
|
|
- }
|
|
|
-
|
|
|
- protected Collection<Class<? extends Plugin>> getPlugins() {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
-
|
|
|
- protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
|
|
|
- }
|
|
|
-
|
|
|
- @BeforeClass
|
|
|
- public static void beforeClass() {
|
|
|
- nodeSettings = Settings.builder()
|
|
|
- .put("node.name", AbstractQueryTestCase.class.toString())
|
|
|
- .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
|
|
|
- .build();
|
|
|
-
|
|
|
- index = new Index(randomAlphaOfLengthBetween(1, 10), "_na_");
|
|
|
-
|
|
|
- // Set a single type in the index
|
|
|
- switch (random().nextInt(3)) {
|
|
|
- case 0:
|
|
|
- currentTypes = new String[0]; // no types
|
|
|
- break;
|
|
|
- default:
|
|
|
- currentTypes = new String[] { "_doc" };
|
|
|
- break;
|
|
|
- }
|
|
|
- randomTypes = getRandomTypes();
|
|
|
- }
|
|
|
-
|
|
|
- protected Settings indexSettings() {
|
|
|
- // we have to prefer CURRENT since with the range of versions we support it's rather unlikely to get the current actually.
|
|
|
- indexVersionCreated = randomBoolean() ? Version.CURRENT
|
|
|
- : VersionUtils.randomVersionBetween(random(), null, Version.CURRENT);
|
|
|
- return Settings.builder()
|
|
|
- .put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated)
|
|
|
- .build();
|
|
|
- }
|
|
|
-
|
|
|
- @AfterClass
|
|
|
- public static void afterClass() throws Exception {
|
|
|
- IOUtils.close(serviceHolder);
|
|
|
- serviceHolder = null;
|
|
|
- }
|
|
|
-
|
|
|
- @Before
|
|
|
- public void beforeTest() throws IOException {
|
|
|
- if (serviceHolder == null) {
|
|
|
- serviceHolder = new ServiceHolder(nodeSettings, indexSettings(), getPlugins(), this);
|
|
|
- }
|
|
|
- serviceHolder.clientInvocationHandler.delegate = this;
|
|
|
- }
|
|
|
+public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>> extends AbstractBuilderTestCase {
|
|
|
|
|
|
- private static SearchContext getSearchContext(String[] types, QueryShardContext context) {
|
|
|
- TestSearchContext testSearchContext = new TestSearchContext(context) {
|
|
|
- @Override
|
|
|
- public MapperService mapperService() {
|
|
|
- return serviceHolder.mapperService; // need to build / parse inner hits sort fields
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType) {
|
|
|
- return serviceHolder.indexFieldDataService.getForField(fieldType); // need to build / parse inner hits sort fields
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
- testSearchContext.getQueryShardContext().setTypes(types);
|
|
|
- return testSearchContext;
|
|
|
- }
|
|
|
-
|
|
|
- @After
|
|
|
- public void afterTest() {
|
|
|
- serviceHolder.clientInvocationHandler.delegate = null;
|
|
|
- }
|
|
|
+ private static final int NUMBER_OF_TESTQUERIES = 20;
|
|
|
|
|
|
public final QB createTestQueryBuilder() {
|
|
|
QB query = doCreateTestQueryBuilder();
|
|
@@ -260,15 +96,6 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|
|
return query;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * make sure query names are unique by suffixing them with increasing counter
|
|
|
- */
|
|
|
- private static String createUniqueRandomName() {
|
|
|
- String queryName = randomAlphaOfLengthBetween(1, 10) + queryNameId;
|
|
|
- queryNameId++;
|
|
|
- return queryName;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Create the query that is being tested
|
|
|
*/
|
|
@@ -717,18 +544,18 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- protected static QueryBuilder assertSerialization(QueryBuilder testQuery) throws IOException {
|
|
|
+ protected QueryBuilder assertSerialization(QueryBuilder testQuery) throws IOException {
|
|
|
return assertSerialization(testQuery, Version.CURRENT);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Serialize the given query builder and asserts that both are equal
|
|
|
*/
|
|
|
- protected static QueryBuilder assertSerialization(QueryBuilder testQuery, Version version) throws IOException {
|
|
|
+ protected QueryBuilder assertSerialization(QueryBuilder testQuery, Version version) throws IOException {
|
|
|
try (BytesStreamOutput output = new BytesStreamOutput()) {
|
|
|
output.setVersion(version);
|
|
|
output.writeNamedWriteable(testQuery);
|
|
|
- try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), serviceHolder.namedWriteableRegistry)) {
|
|
|
+ try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry())) {
|
|
|
in.setVersion(version);
|
|
|
QueryBuilder deserializedQuery = in.readNamedWriteable(QueryBuilder.class);
|
|
|
assertEquals(testQuery, deserializedQuery);
|
|
@@ -780,15 +607,8 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|
|
//we use the streaming infra to create a copy of the query provided as argument
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private QB copyQuery(QB query) throws IOException {
|
|
|
- Reader<QB> reader = (Reader<QB>) serviceHolder.namedWriteableRegistry.getReader(QueryBuilder.class, query.getWriteableName());
|
|
|
- return copyWriteable(query, serviceHolder.namedWriteableRegistry, reader);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return a new {@link QueryShardContext} based on the base test index and queryParserService
|
|
|
- */
|
|
|
- protected static QueryShardContext createShardContext() {
|
|
|
- return serviceHolder.createShardContext();
|
|
|
+ Reader<QB> reader = (Reader<QB>) namedWriteableRegistry().getReader(QueryBuilder.class, query.getWriteableName());
|
|
|
+ return copyWriteable(query, namedWriteableRegistry(), reader);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -840,7 +660,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|
|
*/
|
|
|
protected static String getRandomFieldName() {
|
|
|
// if no type is set then return a random field name
|
|
|
- if (currentTypes.length == 0 || randomBoolean()) {
|
|
|
+ if (getCurrentTypes().length == 0 || randomBoolean()) {
|
|
|
return randomAlphaOfLengthBetween(1, 10);
|
|
|
}
|
|
|
return randomFrom(MAPPED_LEAF_FIELD_NAMES);
|
|
@@ -863,24 +683,6 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|
|
return rewrite;
|
|
|
}
|
|
|
|
|
|
- private static String[] getRandomTypes() {
|
|
|
- String[] types;
|
|
|
- if (currentTypes.length > 0 && randomBoolean()) {
|
|
|
- int numberOfQueryTypes = randomIntBetween(1, currentTypes.length);
|
|
|
- types = new String[numberOfQueryTypes];
|
|
|
- for (int i = 0; i < numberOfQueryTypes; i++) {
|
|
|
- types[i] = randomFrom(currentTypes);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (randomBoolean()) {
|
|
|
- types = new String[]{MetaData.ALL};
|
|
|
- } else {
|
|
|
- types = new String[0];
|
|
|
- }
|
|
|
- }
|
|
|
- return types;
|
|
|
- }
|
|
|
-
|
|
|
protected static Fuzziness randomFuzziness(String fieldName) {
|
|
|
switch (fieldName) {
|
|
|
case INT_FIELD_NAME:
|
|
@@ -905,50 +707,6 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|
|
return randomFrom("1", "-1", "75%", "-25%", "2<75%", "2<-25%");
|
|
|
}
|
|
|
|
|
|
- private static class ClientInvocationHandler implements InvocationHandler {
|
|
|
- AbstractQueryTestCase<?> delegate;
|
|
|
-
|
|
|
- @Override
|
|
|
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
|
|
- if (method.equals(Client.class.getMethod("get", GetRequest.class, ActionListener.class))){
|
|
|
- GetResponse getResponse = delegate.executeGet((GetRequest) args[0]);
|
|
|
- ActionListener<GetResponse> listener = (ActionListener<GetResponse>) args[1];
|
|
|
- if (randomBoolean()) {
|
|
|
- listener.onResponse(getResponse);
|
|
|
- } else {
|
|
|
- new Thread(() -> listener.onResponse(getResponse)).start();
|
|
|
- }
|
|
|
- return null;
|
|
|
- } else if (method.equals(Client.class.getMethod
|
|
|
- ("multiTermVectors", MultiTermVectorsRequest.class))) {
|
|
|
- return new PlainActionFuture<MultiTermVectorsResponse>() {
|
|
|
- @Override
|
|
|
- public MultiTermVectorsResponse get() throws InterruptedException, ExecutionException {
|
|
|
- return delegate.executeMultiTermVectors((MultiTermVectorsRequest) args[0]);
|
|
|
- }
|
|
|
- };
|
|
|
- } else if (method.equals(Object.class.getMethod("toString"))) {
|
|
|
- return "MockClient";
|
|
|
- }
|
|
|
- throw new UnsupportedOperationException("this test can't handle calls to: " + method);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Override this to handle {@link Client#get(GetRequest)} calls from parsers / builders
|
|
|
- */
|
|
|
- protected GetResponse executeGet(GetRequest getRequest) {
|
|
|
- throw new UnsupportedOperationException("this test can't handle GET requests");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Override this to handle {@link Client#get(GetRequest)} calls from parsers / builders
|
|
|
- */
|
|
|
- protected MultiTermVectorsResponse executeMultiTermVectors(MultiTermVectorsRequest mtvRequest) {
|
|
|
- throw new UnsupportedOperationException("this test can't handle MultiTermVector requests");
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Call this method to check a valid json string representing the query under test against
|
|
|
* it's generated json.
|
|
@@ -1015,113 +773,6 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|
|
return query;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected NamedXContentRegistry xContentRegistry() {
|
|
|
- return serviceHolder.xContentRegistry;
|
|
|
- }
|
|
|
-
|
|
|
- private static class ServiceHolder implements Closeable {
|
|
|
- private final IndexFieldDataService indexFieldDataService;
|
|
|
- private final SearchModule searchModule;
|
|
|
- private final NamedWriteableRegistry namedWriteableRegistry;
|
|
|
- private final NamedXContentRegistry xContentRegistry;
|
|
|
- private final ClientInvocationHandler clientInvocationHandler = new ClientInvocationHandler();
|
|
|
- private final IndexSettings idxSettings;
|
|
|
- private final SimilarityService similarityService;
|
|
|
- private final MapperService mapperService;
|
|
|
- private final BitsetFilterCache bitsetFilterCache;
|
|
|
- private final ScriptService scriptService;
|
|
|
- private final Client client;
|
|
|
- private final long nowInMillis = randomNonNegativeLong();
|
|
|
-
|
|
|
- ServiceHolder(Settings nodeSettings, Settings indexSettings,
|
|
|
- Collection<Class<? extends Plugin>> plugins, AbstractQueryTestCase<?> testCase) throws IOException {
|
|
|
- Environment env = InternalSettingsPreparer.prepareEnvironment(nodeSettings);
|
|
|
- PluginsService pluginsService;
|
|
|
- pluginsService = new PluginsService(nodeSettings, null, env.modulesFile(), env.pluginsFile(), plugins);
|
|
|
-
|
|
|
- client = (Client) Proxy.newProxyInstance(
|
|
|
- Client.class.getClassLoader(),
|
|
|
- new Class[]{Client.class},
|
|
|
- clientInvocationHandler);
|
|
|
- ScriptModule scriptModule = createScriptModule(pluginsService.filterPlugins(ScriptPlugin.class));
|
|
|
- List<Setting<?>> additionalSettings = pluginsService.getPluginSettings();
|
|
|
- additionalSettings.add(InternalSettingsPlugin.VERSION_CREATED);
|
|
|
- SettingsModule settingsModule = new SettingsModule(nodeSettings, additionalSettings, pluginsService.getPluginSettingsFilter());
|
|
|
- searchModule = new SearchModule(nodeSettings, false, pluginsService.filterPlugins(SearchPlugin.class));
|
|
|
- IndicesModule indicesModule = new IndicesModule(pluginsService.filterPlugins(MapperPlugin.class));
|
|
|
- List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
|
|
- entries.addAll(indicesModule.getNamedWriteables());
|
|
|
- entries.addAll(searchModule.getNamedWriteables());
|
|
|
- namedWriteableRegistry = new NamedWriteableRegistry(entries);
|
|
|
- xContentRegistry = new NamedXContentRegistry(Stream.of(
|
|
|
- searchModule.getNamedXContents().stream()
|
|
|
- ).flatMap(Function.identity()).collect(toList()));
|
|
|
- IndexScopedSettings indexScopedSettings = settingsModule.getIndexScopedSettings();
|
|
|
- idxSettings = IndexSettingsModule.newIndexSettings(index, indexSettings, indexScopedSettings);
|
|
|
- AnalysisModule analysisModule = new AnalysisModule(TestEnvironment.newEnvironment(nodeSettings), emptyList());
|
|
|
- IndexAnalyzers indexAnalyzers = analysisModule.getAnalysisRegistry().build(idxSettings);
|
|
|
- scriptService = scriptModule.getScriptService();
|
|
|
- similarityService = new SimilarityService(idxSettings, null, Collections.emptyMap());
|
|
|
- MapperRegistry mapperRegistry = indicesModule.getMapperRegistry();
|
|
|
- mapperService = new MapperService(idxSettings, indexAnalyzers, xContentRegistry, similarityService, mapperRegistry,
|
|
|
- this::createShardContext);
|
|
|
- IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(nodeSettings, new IndexFieldDataCache.Listener() {
|
|
|
- });
|
|
|
- indexFieldDataService = new IndexFieldDataService(idxSettings, indicesFieldDataCache,
|
|
|
- new NoneCircuitBreakerService(), mapperService);
|
|
|
- bitsetFilterCache = new BitsetFilterCache(idxSettings, new BitsetFilterCache.Listener() {
|
|
|
- @Override
|
|
|
- public void onCache(ShardId shardId, Accountable accountable) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onRemoval(ShardId shardId, Accountable accountable) {
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- for (String type : currentTypes) {
|
|
|
- mapperService.merge(type, new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(type,
|
|
|
- STRING_FIELD_NAME, "type=text",
|
|
|
- STRING_FIELD_NAME_2, "type=keyword",
|
|
|
- INT_FIELD_NAME, "type=integer",
|
|
|
- INT_RANGE_FIELD_NAME, "type=integer_range",
|
|
|
- DOUBLE_FIELD_NAME, "type=double",
|
|
|
- BOOLEAN_FIELD_NAME, "type=boolean",
|
|
|
- DATE_FIELD_NAME, "type=date",
|
|
|
- DATE_RANGE_FIELD_NAME, "type=date_range",
|
|
|
- OBJECT_FIELD_NAME, "type=object",
|
|
|
- GEO_POINT_FIELD_NAME, "type=geo_point",
|
|
|
- GEO_SHAPE_FIELD_NAME, "type=geo_shape"
|
|
|
- ))), MapperService.MergeReason.MAPPING_UPDATE);
|
|
|
- // also add mappings for two inner field in the object field
|
|
|
- mapperService.merge(type, new CompressedXContent("{\"properties\":{\"" + OBJECT_FIELD_NAME + "\":{\"type\":\"object\","
|
|
|
- + "\"properties\":{\"" + DATE_FIELD_NAME + "\":{\"type\":\"date\"},\"" +
|
|
|
- INT_FIELD_NAME + "\":{\"type\":\"integer\"}}}}}"),
|
|
|
- MapperService.MergeReason.MAPPING_UPDATE);
|
|
|
- }
|
|
|
- testCase.initializeAdditionalMappings(mapperService);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void close() throws IOException {
|
|
|
- }
|
|
|
-
|
|
|
- QueryShardContext createShardContext() {
|
|
|
- return new QueryShardContext(0, idxSettings, bitsetFilterCache, indexFieldDataService::getForField, mapperService,
|
|
|
- similarityService, scriptService, xContentRegistry, namedWriteableRegistry, this.client, null, () -> nowInMillis, null);
|
|
|
- }
|
|
|
-
|
|
|
- ScriptModule createScriptModule(List<ScriptPlugin> scriptPlugins) {
|
|
|
- if (scriptPlugins == null || scriptPlugins.isEmpty()) {
|
|
|
- return newTestScriptModule();
|
|
|
- }
|
|
|
- return new ScriptModule(Settings.EMPTY, scriptPlugins);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
protected QueryBuilder rewriteAndFetch(QueryBuilder builder, QueryRewriteContext context) throws IOException {
|
|
|
PlainActionFuture<QueryBuilder> future = new PlainActionFuture<>();
|
|
|
Rewriteable.rewriteAndFetch(builder, context, future);
|