Search in sources :

Example 11 with IndexService

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

the class TransportIndicesStatsAction method shardOperation.

@Override
protected ShardStats shardOperation(IndicesStatsRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
    IndexShard indexShard = indexService.getShard(shardRouting.shardId().id());
    // if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet
    if (indexShard.routingEntry() == null) {
        throw new ShardNotFoundException(indexShard.shardId());
    }
    CommonStatsFlags flags = new CommonStatsFlags().clear();
    if (request.docs()) {
        flags.set(CommonStatsFlags.Flag.Docs);
    }
    if (request.store()) {
        flags.set(CommonStatsFlags.Flag.Store);
    }
    if (request.indexing()) {
        flags.set(CommonStatsFlags.Flag.Indexing);
        flags.types(request.types());
    }
    if (request.get()) {
        flags.set(CommonStatsFlags.Flag.Get);
    }
    if (request.search()) {
        flags.set(CommonStatsFlags.Flag.Search);
        flags.groups(request.groups());
    }
    if (request.merge()) {
        flags.set(CommonStatsFlags.Flag.Merge);
    }
    if (request.refresh()) {
        flags.set(CommonStatsFlags.Flag.Refresh);
    }
    if (request.flush()) {
        flags.set(CommonStatsFlags.Flag.Flush);
    }
    if (request.warmer()) {
        flags.set(CommonStatsFlags.Flag.Warmer);
    }
    if (request.queryCache()) {
        flags.set(CommonStatsFlags.Flag.QueryCache);
    }
    if (request.fieldData()) {
        flags.set(CommonStatsFlags.Flag.FieldData);
        flags.fieldDataFields(request.fieldDataFields());
    }
    if (request.segments()) {
        flags.set(CommonStatsFlags.Flag.Segments);
        flags.includeSegmentFileSizes(request.includeSegmentFileSizes());
    }
    if (request.completion()) {
        flags.set(CommonStatsFlags.Flag.Completion);
        flags.completionDataFields(request.completionFields());
    }
    if (request.translog()) {
        flags.set(CommonStatsFlags.Flag.Translog);
    }
    if (request.suggest()) {
        flags.set(CommonStatsFlags.Flag.Suggest);
    }
    if (request.requestCache()) {
        flags.set(CommonStatsFlags.Flag.RequestCache);
    }
    if (request.recovery()) {
        flags.set(CommonStatsFlags.Flag.Recovery);
    }
    return new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesService.getIndicesQueryCache(), indexShard, flags), indexShard.commitStats(), indexShard.seqNoStats());
}
Also used : ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 12 with IndexService

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

the class TransportIndicesSegmentsAction method shardOperation.

@Override
protected ShardSegments shardOperation(IndicesSegmentsRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.index());
    IndexShard indexShard = indexService.getShard(shardRouting.id());
    return new ShardSegments(indexShard.routingEntry(), indexShard.segments(request.verbose()));
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 13 with IndexService

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

the class TransportFieldStatsAction method shardOperation.

@Override
protected FieldStatsShardResponse shardOperation(FieldStatsShardRequest request) {
    ShardId shardId = request.shardId();
    Map<String, FieldStats<?>> fieldStats = new HashMap<>();
    IndexService indexServices = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard shard = indexServices.getShard(shardId.id());
    try (Engine.Searcher searcher = shard.acquireSearcher("fieldstats")) {
        // Resolve patterns and deduplicate
        Set<String> fieldNames = new HashSet<>();
        for (String field : request.getFields()) {
            fieldNames.addAll(shard.mapperService().simpleMatchToIndexNames(field));
        }
        for (String field : fieldNames) {
            FieldStats<?> stats = indicesService.getFieldStats(shard, searcher, field, request.shouldUseCache());
            if (stats != null) {
                fieldStats.put(field, stats);
            }
        }
    } catch (Exception e) {
        throw ExceptionsHelper.convertToElastic(e);
    }
    return new FieldStatsShardResponse(shardId, fieldStats);
}
Also used : HashMap(java.util.HashMap) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) BroadcastShardOperationFailedException(org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) DefaultShardOperationFailedException(org.elasticsearch.action.support.DefaultShardOperationFailedException) ShardId(org.elasticsearch.index.shard.ShardId) Engine(org.elasticsearch.index.engine.Engine) HashSet(java.util.HashSet)

Example 14 with IndexService

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

the class TransportGetAction method shardOperation.

@Override
protected GetResponse shardOperation(GetRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.getShard(shardId.id());
    if (request.refresh() && !request.realtime()) {
        indexShard.refresh("refresh_flag_get");
    }
    GetResult result = indexShard.getService().get(request.type(), request.id(), request.storedFields(), request.realtime(), request.version(), request.versionType(), request.fetchSourceContext());
    return new GetResponse(result);
}
Also used : GetResult(org.elasticsearch.index.get.GetResult) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 15 with IndexService

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

the class TransportShardMultiGetAction method shardOperation.

@Override
protected MultiGetShardResponse shardOperation(MultiGetShardRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.getShard(shardId.id());
    if (request.refresh() && !request.realtime()) {
        indexShard.refresh("refresh_flag_mget");
    }
    MultiGetShardResponse response = new MultiGetShardResponse();
    for (int i = 0; i < request.locations.size(); i++) {
        MultiGetRequest.Item item = request.items.get(i);
        try {
            GetResult getResult = indexShard.getService().get(item.type(), item.id(), item.storedFields(), request.realtime(), item.version(), item.versionType(), item.fetchSourceContext());
            response.add(request.locations.get(i), new GetResponse(getResult));
        } catch (Exception e) {
            if (TransportActions.isShardNotAvailableException(e)) {
                throw (ElasticsearchException) e;
            } else {
                logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} failed to execute multi_get for [{}]/[{}]", shardId, item.type(), item.id()), e);
                response.add(request.locations.get(i), new MultiGetResponse.Failure(request.index(), item.type(), item.id(), e));
            }
        }
    }
    return response;
}
Also used : GetResult(org.elasticsearch.index.get.GetResult) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Aggregations

IndexService (org.elasticsearch.index.IndexService)212 IndexShard (org.elasticsearch.index.shard.IndexShard)77 IndicesService (org.elasticsearch.indices.IndicesService)56 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)50 ShardId (org.elasticsearch.index.shard.ShardId)38 Index (org.elasticsearch.index.Index)36 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)33 Settings (org.elasticsearch.common.settings.Settings)31 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)22 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)22 HashMap (java.util.HashMap)21 Map (java.util.Map)19 ClusterService (org.elasticsearch.cluster.service.ClusterService)19 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)18 ElasticsearchException (org.elasticsearch.ElasticsearchException)17 ClusterState (org.elasticsearch.cluster.ClusterState)16 List (java.util.List)14 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)13 IndexSettings (org.elasticsearch.index.IndexSettings)13