Java Code Examples for org.elasticsearch.index.shard.ShardId#id()

The following examples show how to use org.elasticsearch.index.shard.ShardId#id() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchContextFactory.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public CrateSearchContext createContext(
        int jobSearchContextId,
        IndexShard indexshard,
        Engine.Searcher engineSearcher,
        WhereClause whereClause) {

    ShardId shardId = indexshard.shardId();
    SearchShardTarget searchShardTarget = new SearchShardTarget(
            clusterService.state().nodes().localNodeId(),
            shardId.getIndex(),
            shardId.id()
    );
    IndexService indexService = indexshard.indexService();
    CrateSearchContext searchContext = new CrateSearchContext(
            jobSearchContextId,
            System.currentTimeMillis(),
            searchShardTarget,
            engineSearcher,
            indexService,
            indexshard,
            scriptService,
            pageCacheRecycler,
            bigArrays,
            threadPool.estimatedTimeInMillisCounter(),
            Optional.<Scroll>absent()
    );
    LuceneQueryBuilder.Context context = luceneQueryBuilder.convert(
            whereClause,  indexService.mapperService(), indexService.fieldData(), indexService.cache());
    searchContext.parsedQuery(new ParsedQuery(context.query(), EMPTY_NAMED_FILTERS));

    Float minScore = context.minScore();
    if (minScore != null) {
        searchContext.minimumScore(minScore);
    }

    return searchContext;
}
 
Example 2
Source File: UnassignedShard.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public UnassignedShard(ShardId shardId,
                       ClusterService clusterService,
                       Boolean primary,
                       ShardRoutingState state) {
    String index = shardId.index().name();
    boolean isBlobIndex = BlobIndices.isBlobIndex(index);
    String tableName;
    String ident = "";
    if (isBlobIndex) {
        this.schemaName = BlobSchemaInfo.NAME;
        tableName = BlobIndices.STRIP_PREFIX.apply(index);
    } else if (PartitionName.isPartition(index)) {
        PartitionName partitionName = PartitionName.fromIndexOrTemplate(index);
        schemaName = partitionName.tableIdent().schema();
        tableName = partitionName.tableIdent().name();
        ident = partitionName.ident();
        if (!clusterService.state().metaData().hasConcreteIndex(tableName)) {
            orphanedPartition = true;
        }
    } else {
        Matcher matcher = Schemas.SCHEMA_PATTERN.matcher(index);
        if (matcher.matches()) {
            this.schemaName = matcher.group(1);
            tableName = matcher.group(2);
        } else {
            this.schemaName = Schemas.DEFAULT_SCHEMA_NAME;
            tableName = index;
        }
    }

    this.tableName = tableName;
    partitionIdent = ident;
    this.primary = primary;
    this.id = shardId.id();
    this.state = state == ShardRoutingState.UNASSIGNED ? UNASSIGNED : INITIALIZING;
}
 
Example 3
Source File: ShardSearchLocalRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public ShardSearchLocalRequest(ShardId shardId, int numberOfShards, SearchType searchType,
                               BytesReference source, String[] types, Boolean requestCache) {
    this.index = shardId.getIndex();
    this.shardId = shardId.id();
    this.numberOfShards = numberOfShards;
    this.searchType = searchType;
    this.source = source;
    this.types = types;
    this.requestCache = requestCache;
}
 
Example 4
Source File: TransportIndicesShardStoresAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private IndicesShardStoresResponse.StoreStatus.Allocation getAllocation(String index, int shardID, DiscoveryNode node) {
    for (ShardRouting shardRouting : routingNodes.node(node.id())) {
        ShardId shardId = shardRouting.shardId();
        if (shardId.id() == shardID && shardId.getIndex().equals(index)) {
            if (shardRouting.primary()) {
                return IndicesShardStoresResponse.StoreStatus.Allocation.PRIMARY;
            } else if (shardRouting.assignedToNode()) {
                return IndicesShardStoresResponse.StoreStatus.Allocation.REPLICA;
            } else {
                return IndicesShardStoresResponse.StoreStatus.Allocation.UNUSED;
            }
        }
    }
    return IndicesShardStoresResponse.StoreStatus.Allocation.UNUSED;
}
 
Example 5
Source File: BlobStoreRepository.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Delete snapshot from shard level metadata.
 */
private ShardSnapshotMetaDeleteResult deleteFromShardSnapshotMeta(Set<SnapshotId> survivingSnapshots, IndexId indexId,
                                                                  ShardId snapshotShardId, SnapshotId snapshotId,
                                                                  BlobContainer shardContainer, Set<String> blobs,
                                                                  BlobStoreIndexShardSnapshots snapshots, String indexGeneration) {
    // Build a list of snapshots that should be preserved
    List<SnapshotFiles> newSnapshotsList = new ArrayList<>();
    final Set<String> survivingSnapshotNames = survivingSnapshots.stream().map(SnapshotId::getName).collect(Collectors.toSet());
    for (SnapshotFiles point : snapshots) {
        if (survivingSnapshotNames.contains(point.snapshot())) {
            newSnapshotsList.add(point);
        }
    }
    try {
        if (newSnapshotsList.isEmpty()) {
            return new ShardSnapshotMetaDeleteResult(indexId, snapshotShardId.id(), ShardGenerations.DELETED_SHARD_GEN, blobs);
        } else {
            final BlobStoreIndexShardSnapshots updatedSnapshots = new BlobStoreIndexShardSnapshots(newSnapshotsList);
            writeShardIndexBlob(shardContainer, indexGeneration, updatedSnapshots);
            final Set<String> survivingSnapshotUUIDs = survivingSnapshots.stream().map(SnapshotId::getUUID).collect(Collectors.toSet());
            return new ShardSnapshotMetaDeleteResult(indexId, snapshotShardId.id(), indexGeneration,
                                                     unusedBlobs(blobs, survivingSnapshotUUIDs, updatedSnapshots));
        }
    } catch (IOException e) {
        throw new IndexShardSnapshotFailedException(snapshotShardId,
                                                    "Failed to finalize snapshot deletion [" + snapshotId + "] with shard index ["
                                                    + indexShardSnapshotsFormat.blobName(indexGeneration) + "]", e);
    }
}
 
Example 6
Source File: RandomScoreFunctionParser.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ScoreFunction parse(QueryParseContext parseContext, XContentParser parser) throws IOException, QueryParsingException {

    int seed = -1;

    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if ("seed".equals(currentFieldName)) {
                if (token == XContentParser.Token.VALUE_NUMBER) {
                    if (parser.numberType() == XContentParser.NumberType.INT) {
                        seed = parser.intValue();
                    } else if (parser.numberType() == XContentParser.NumberType.LONG) {
                        seed = Longs.hashCode(parser.longValue());
                    } else {
                        throw new QueryParsingException(parseContext, "random_score seed must be an int, long or string, not '"
                                + token.toString() + "'");
                    }
                } else if (token == XContentParser.Token.VALUE_STRING) {
                    seed = parser.text().hashCode();
                } else {
                    throw new QueryParsingException(parseContext, "random_score seed must be an int/long or string, not '"
                            + token.toString() + "'");
                }
            } else {
                throw new QueryParsingException(parseContext, NAMES[0] + " query does not support [" + currentFieldName + "]");
            }
        }
    }

    final MappedFieldType fieldType = SearchContext.current().mapperService().smartNameFieldType("_uid");
    if (fieldType == null) {
        // mapper could be null if we are on a shard with no docs yet, so this won't actually be used
        return new RandomScoreFunction();
    }

    if (seed == -1) {
        seed = Longs.hashCode(parseContext.nowInMillis());
    }
    final ShardId shardId = SearchContext.current().indexShard().shardId();
    final int salt = (shardId.index().name().hashCode() << 10) | shardId.id();
    final IndexFieldData<?> uidFieldData = SearchContext.current().fieldData().getForField(fieldType);

    return new RandomScoreFunction(seed, salt, uidFieldData);
}
 
Example 7
Source File: UnavailableShardsException.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private static String buildMessage(ShardId shardId, String message) {
    if (shardId == null) {
        return message;
    }
    return "[" + shardId.index().name() + "][" + shardId.id() + "] " + message;
}
 
Example 8
Source File: SnapshotShardFailure.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs new snapshot shard failure object
 *
 * @param nodeId  node where failure occurred
 * @param shardId shard id
 * @param reason  failure reason
 * @param status  rest status
 */
private SnapshotShardFailure(@Nullable String nodeId, ShardId shardId, String reason, RestStatus status) {
    super(shardId.getIndexName(), shardId.id(), reason, status, new IndexShardSnapshotFailedException(shardId, reason));
    this.nodeId = nodeId;
    this.shardId = shardId;
}