Search in sources :

Example 1 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class AggregatorTestCase method createAggregator.

protected <A extends Aggregator, B extends AggregationBuilder> A createAggregator(B aggregationBuilder, IndexSearcher indexSearcher, MappedFieldType... fieldTypes) throws IOException {
    IndexSettings indexSettings = createIndexSettings();
    SearchContext searchContext = createSearchContext(indexSearcher, indexSettings);
    CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
    when(searchContext.bigArrays()).thenReturn(new MockBigArrays(Settings.EMPTY, circuitBreakerService));
    // TODO: now just needed for top_hits, this will need to be revised for other agg unit tests:
    MapperService mapperService = mapperServiceMock();
    when(mapperService.hasNested()).thenReturn(false);
    when(searchContext.mapperService()).thenReturn(mapperService);
    IndexFieldDataService ifds = new IndexFieldDataService(indexSettings, new IndicesFieldDataCache(Settings.EMPTY, new IndexFieldDataCache.Listener() {
    }), circuitBreakerService, mapperService);
    when(searchContext.fieldData()).thenReturn(ifds);
    SearchLookup searchLookup = new SearchLookup(mapperService, ifds, new String[] { "type" });
    when(searchContext.lookup()).thenReturn(searchLookup);
    QueryShardContext queryShardContext = queryShardContextMock(fieldTypes, indexSettings, circuitBreakerService);
    when(searchContext.getQueryShardContext()).thenReturn(queryShardContext);
    @SuppressWarnings("unchecked") A aggregator = (A) aggregationBuilder.build(searchContext, null).create(null, true);
    return aggregator;
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) SearchContext(org.elasticsearch.search.internal.SearchContext) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) MapperService(org.elasticsearch.index.mapper.MapperService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) SearchLookup(org.elasticsearch.search.lookup.SearchLookup)

Example 2 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class QueryRescoreBuilderTests method testBuildRescoreSearchContext.

/**
     * test that build() outputs a {@link RescoreSearchContext} that has the same properties
     * than the test builder
     */
public void testBuildRescoreSearchContext() throws ElasticsearchParseException, IOException {
    final long nowInMillis = randomNonNegativeLong();
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAsciiOfLengthBetween(1, 10), indexSettings);
    // shard context will only need indicesQueriesRegistry for building Query objects nested in query rescorer
    QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis) {

        @Override
        public MappedFieldType fieldMapper(String name) {
            TextFieldMapper.Builder builder = new TextFieldMapper.Builder(name);
            return builder.build(new Mapper.BuilderContext(idxSettings.getSettings(), new ContentPath(1))).fieldType();
        }
    };
    for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {
        QueryRescorerBuilder rescoreBuilder = randomRescoreBuilder();
        QueryRescoreContext rescoreContext = rescoreBuilder.build(mockShardContext);
        int expectedWindowSize = rescoreBuilder.windowSize() == null ? QueryRescoreContext.DEFAULT_WINDOW_SIZE : rescoreBuilder.windowSize().intValue();
        assertEquals(expectedWindowSize, rescoreContext.window());
        Query expectedQuery = QueryBuilder.rewriteQuery(rescoreBuilder.getRescoreQuery(), mockShardContext).toQuery(mockShardContext);
        assertEquals(expectedQuery, rescoreContext.query());
        assertEquals(rescoreBuilder.getQueryWeight(), rescoreContext.queryWeight(), Float.MIN_VALUE);
        assertEquals(rescoreBuilder.getRescoreQueryWeight(), rescoreContext.rescoreQueryWeight(), Float.MIN_VALUE);
        assertEquals(rescoreBuilder.getScoreMode(), rescoreContext.scoreMode());
    }
}
Also used : Query(org.apache.lucene.search.Query) IndexSettings(org.elasticsearch.index.IndexSettings) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) ContentPath(org.elasticsearch.index.mapper.ContentPath) QueryRescoreContext(org.elasticsearch.search.rescore.QueryRescorer.QueryRescoreContext) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) TextFieldMapper(org.elasticsearch.index.mapper.TextFieldMapper)

Example 3 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class AnalysisPolishFactoryTests method testThreadSafety.

public void testThreadSafety() throws IOException {
    // TODO: is this the right boilerplate?  I forked this out of TransportAnalyzeAction.java:
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    Environment environment = new Environment(settings);
    IndexMetaData metaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(settings).build();
    IndexSettings indexSettings = new IndexSettings(metaData, Settings.EMPTY);
    testThreadSafety(new PolishStemTokenFilterFactory(indexSettings, environment, "stempelpolishstem", settings));
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Environment(org.elasticsearch.env.Environment) PolishStemTokenFilterFactory(org.elasticsearch.index.analysis.pl.PolishStemTokenFilterFactory) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 4 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class MockSearchServiceTests method testAssertNoInFlightContext.

public void testAssertNoInFlightContext() {
    final long nowInMillis = randomNonNegativeLong();
    SearchContext s = new TestSearchContext(new QueryShardContext(0, new IndexSettings(EMPTY_INDEX_METADATA, Settings.EMPTY), null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis)) {

        @Override
        public SearchShardTarget shardTarget() {
            return new SearchShardTarget("node", new Index("idx", "ignored"), 0);
        }

        @Override
        public SearchType searchType() {
            return SearchType.DEFAULT;
        }

        @Override
        public Query query() {
            return Queries.newMatchAllQuery();
        }
    };
    MockSearchService.addActiveContext(s);
    try {
        Throwable e = expectThrows(AssertionError.class, () -> MockSearchService.assertNoInFlightContext());
        assertEquals("There are still [1] in-flight contexts. The first one's creation site is listed as the cause of this exception.", e.getMessage());
        e = e.getCause();
        // The next line with throw an exception if the date looks wrong
        assertEquals("[node][idx][0] query=[*:*]", e.getMessage());
        assertEquals(MockSearchService.class.getName(), e.getStackTrace()[0].getClassName());
        assertEquals(MockSearchServiceTests.class.getName(), e.getStackTrace()[1].getClassName());
    } finally {
        MockSearchService.removeActiveContext(s);
    }
}
Also used : TestSearchContext(org.elasticsearch.test.TestSearchContext) IndexSettings(org.elasticsearch.index.IndexSettings) SearchContext(org.elasticsearch.search.internal.SearchContext) TestSearchContext(org.elasticsearch.test.TestSearchContext) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Index(org.elasticsearch.index.Index)

Example 5 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class IndexSettingsModule method newIndexSettings.

public static IndexSettings newIndexSettings(Index index, Settings settings, IndexScopedSettings indexScopedSettings) {
    Settings build = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(settings).build();
    IndexMetaData metaData = IndexMetaData.builder(index.getName()).settings(build).build();
    return new IndexSettings(metaData, Settings.EMPTY, indexScopedSettings);
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

IndexSettings (org.elasticsearch.index.IndexSettings)83 Settings (org.elasticsearch.common.settings.Settings)53 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)28 Index (org.elasticsearch.index.Index)25 ShardId (org.elasticsearch.index.shard.ShardId)13 Environment (org.elasticsearch.env.Environment)12 IOException (java.io.IOException)11 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)11 Path (java.nio.file.Path)9 ShardPath (org.elasticsearch.index.shard.ShardPath)9 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)9 Directory (org.apache.lucene.store.Directory)8 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)7 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 HashMap (java.util.HashMap)5 Version (org.elasticsearch.Version)5 IndexService (org.elasticsearch.index.IndexService)5 Store (org.elasticsearch.index.store.Store)5 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4