Search in sources :

Example 76 with IndexService

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

the class ValuesSourceConfigTests method testEmptyLong.

public void testEmptyLong() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "long", "type=long");
    client().prepareIndex("index", "type", "1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(context, null, "long", null, null, null, null);
        ValuesSource.Numeric valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedNumericDocValues values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(0, values.count());
        config = ValuesSourceConfig.resolve(context, null, "long", null, 42, null, null);
        valuesSource = config.toValuesSource(context);
        values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(42, values.valueAt(0));
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Example 77 with IndexService

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

the class ValuesSourceConfigTests method testEmptyKeyword.

public void testEmptyKeyword() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bytes", "type=keyword");
    client().prepareIndex("index", "type", "1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Bytes> config = ValuesSourceConfig.resolve(context, null, "bytes", null, null, null, null);
        ValuesSource.Bytes valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
        values.setDocument(0);
        assertEquals(0, values.count());
        config = ValuesSourceConfig.resolve(context, null, "bytes", null, "abc", null, null);
        valuesSource = config.toValuesSource(context);
        values = valuesSource.bytesValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(new BytesRef("abc"), values.valueAt(0));
    }
}
Also used : IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) BytesRef(org.apache.lucene.util.BytesRef) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues)

Example 78 with IndexService

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

the class ValuesSourceConfigTests method testUnmappedLong.

public void testUnmappedLong() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type");
    client().prepareIndex("index", "type", "1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(context, ValueType.NUMBER, "long", null, null, null, null);
        ValuesSource.Numeric valuesSource = config.toValuesSource(context);
        assertNull(valuesSource);
        config = ValuesSourceConfig.resolve(context, ValueType.NUMBER, "long", null, 42, null, null);
        valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedNumericDocValues values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(42, values.valueAt(0));
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Example 79 with IndexService

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

the class ValuesSourceConfigTests method testKeyword.

public void testKeyword() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bytes", "type=keyword");
    client().prepareIndex("index", "type", "1").setSource("bytes", "abc").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Bytes> config = ValuesSourceConfig.resolve(context, null, "bytes", null, null, null, null);
        ValuesSource.Bytes valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(new BytesRef("abc"), values.valueAt(0));
    }
}
Also used : IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) BytesRef(org.apache.lucene.util.BytesRef) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues)

Example 80 with IndexService

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

the class ParentFieldLoadingIT method testChangingEagerParentFieldLoadingAtRuntime.

public void testChangingEagerParentFieldLoadingAtRuntime() throws Exception {
    assertAcked(prepareCreate("test").setSettings(indexSettings).addMapping("parent").addMapping("child", "_parent", "type=parent"));
    ensureGreen();
    client().prepareIndex("test", "parent", "1").setSource("{}", XContentType.JSON).get();
    client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON).get();
    refresh();
    ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
    assertThat(response.getIndicesStats().getFieldData().getMemorySizeInBytes(), equalTo(0L));
    PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("child").setSource(childMapping(true)).setUpdateAllTypes(true).get();
    assertAcked(putMappingResponse);
    Index test = resolveIndex("test");
    assertBusy(new Runnable() {

        @Override
        public void run() {
            ClusterState clusterState = internalCluster().clusterService().state();
            ShardRouting shardRouting = clusterState.routingTable().index("test").shard(0).getShards().get(0);
            String nodeName = clusterState.getNodes().get(shardRouting.currentNodeId()).getName();
            boolean verified = false;
            IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeName);
            IndexService indexService = indicesService.indexService(test);
            if (indexService != null) {
                MapperService mapperService = indexService.mapperService();
                DocumentMapper documentMapper = mapperService.documentMapper("child");
                if (documentMapper != null) {
                    verified = documentMapper.parentFieldMapper().fieldType().eagerGlobalOrdinals();
                }
            }
            assertTrue(verified);
        }
    });
    // Need to add a new doc otherwise the refresh doesn't trigger a new searcher
    // Because it ends up in its own segment, but isn't of type parent or child, this doc doesn't contribute to the size of the fielddata cache
    client().prepareIndex("test", "dummy", "dummy").setSource("{}", XContentType.JSON).get();
    refresh();
    response = client().admin().cluster().prepareClusterStats().get();
    assertThat(response.getIndicesStats().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) ClusterStatsResponse(org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) MapperService(org.elasticsearch.index.mapper.MapperService)

Aggregations

IndexService (org.elasticsearch.index.IndexService)173 IndexShard (org.elasticsearch.index.shard.IndexShard)53 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)49 IndicesService (org.elasticsearch.indices.IndicesService)38 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)30 Settings (org.elasticsearch.common.settings.Settings)25 ShardId (org.elasticsearch.index.shard.ShardId)24 Index (org.elasticsearch.index.Index)20 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)17 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)16 IOException (java.io.IOException)15 HashMap (java.util.HashMap)15 ArrayList (java.util.ArrayList)14 ClusterState (org.elasticsearch.cluster.ClusterState)13 Map (java.util.Map)12 ClusterService (org.elasticsearch.cluster.service.ClusterService)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)11 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)11 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)11 List (java.util.List)10