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

The following examples show how to use org.elasticsearch.index.shard.ShardId#getIndex() . 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: SysShardsTableInfo.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private void processShardRouting(Map<String, Map<String, List<Integer>>> routing, ShardRouting shardRouting, ShardId shardId) {
    String node;
    int id;
    String index = shardId.getIndex();

    if (shardRouting == null) {
        node = service.localNode().id();
        id = UnassignedShard.markUnassigned(shardId.id());
    } else {
        node = shardRouting.currentNodeId();
        id = shardRouting.id();
    }
    Map<String, List<Integer>> nodeMap = routing.get(node);
    if (nodeMap == null) {
        nodeMap = new TreeMap<>();
        routing.put(node, nodeMap);
    }

    List<Integer> shards = nodeMap.get(index);
    if (shards == null) {
        shards = new ArrayList<>();
        nodeMap.put(index, shards);
    }
    shards.add(id);
}
 
Example 2
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 3
Source File: ShardSchemaNameExpression.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public ShardSchemaNameExpression(ShardId shardId) {
    String indexName = shardId.getIndex();
    Matcher matcher = Schemas.SCHEMA_PATTERN.matcher(indexName);
    if (matcher.matches()) {
        schemaName = new BytesRef(matcher.group(1));
    } else {
        schemaName = DOC_SCHEMA_NAME;
    }

}
 
Example 4
Source File: ShardRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public ShardRequest(ShardId shardId,
                    @Nullable String routing,
                    UUID jobId) {
    setShardId(shardId);
    this.routing = routing;
    this.jobId = jobId;
    this.index = shardId.getIndex();
    locations = new IntArrayList();
    items = new ArrayList<>();
}
 
Example 5
Source File: IndicesService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new pending delete of an index
 */
public PendingDelete(ShardId shardId, Settings settings) {
    this.index = shardId.getIndex();
    this.shardId = shardId.getId();
    this.settings = settings;
    this.deleteIndex = false;
}
 
Example 6
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 7
Source File: BitsetFilterCache.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private BitSet getAndLoadIfNotPresent(final Query query, final LeafReaderContext context) throws IOException, ExecutionException {
    final Object coreCacheReader = context.reader().getCoreCacheKey();
    final ShardId shardId = ShardUtils.extractShardId(context.reader());
    if (shardId != null // can't require it because of the percolator
            && index.getName().equals(shardId.getIndex()) == false) {
        // insanity
        throw new IllegalStateException("Trying to load bit set for index [" + shardId.getIndex()
                + "] with cache of index [" + index.getName() + "]");
    }
    Cache<Query, Value> filterToFbs = loadedFilters.get(coreCacheReader, new Callable<Cache<Query, Value>>() {
        @Override
        public Cache<Query, Value> call() throws Exception {
            context.reader().addCoreClosedListener(BitsetFilterCache.this);
            return CacheBuilder.newBuilder().build();
        }
    });
    return filterToFbs.get(query,new Callable<Value>() {
        @Override
        public Value call() throws Exception {
            final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context);
            final IndexSearcher searcher = new IndexSearcher(topLevelContext);
            searcher.setQueryCache(null);
            final Weight weight = searcher.createNormalizedWeight(query, false);
            final Scorer s = weight.scorer(context);
            final BitSet bitSet;
            if (s == null) {
                bitSet = null;
            } else {
                bitSet = BitSet.of(s.iterator(), context.reader().maxDoc());
            }

            Value value = new Value(bitSet, shardId);
            listener.onCache(shardId, value.bitset);
            return value;
        }
    }).bitset;
}
 
Example 8
Source File: IndicesService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new pending delete of an index
 */
PendingDelete(ShardId shardId, IndexSettings settings) {
    this.index = shardId.getIndex();
    this.shardId = shardId.getId();
    this.settings = settings;
    this.deleteIndex = false;
}
 
Example 9
Source File: RoutingTable.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * All shards for the provided {@link ShardId}
 * @return All the shard routing entries for the given index and shard id
 * @throws IndexNotFoundException if provided index does not exist
 * @throws ShardNotFoundException if provided shard id is unknown
 */
public IndexShardRoutingTable shardRoutingTable(ShardId shardId) {
    IndexRoutingTable indexRouting = index(shardId.getIndexName());
    if (indexRouting == null || indexRouting.getIndex().equals(shardId.getIndex()) == false) {
        throw new IndexNotFoundException(shardId.getIndex());
    }
    IndexShardRoutingTable shard = indexRouting.shard(shardId.id());
    if (shard == null) {
        throw new ShardNotFoundException(shardId);
    }
    return shard;
}
 
Example 10
Source File: BlobIndicesService.java    From crate with Apache License 2.0 5 votes vote down vote up
public BlobShard blobShardSafe(ShardId shardId) {
    String index = shardId.getIndexName();
    if (isBlobIndex(index)) {
        BlobShard blobShard = blobShard(shardId);
        if (blobShard == null) {
            throw new ShardNotFoundException(shardId);
        }
        return blobShard;
    }
    throw new BlobsDisabledException(shardId.getIndex());
}
 
Example 11
Source File: TransportExplainAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected ExplainResponse shardOperation(ExplainRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.shardSafe(shardId.id());
    Term uidTerm = new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(request.type(), request.id()));
    Engine.GetResult result = indexShard.get(new Engine.Get(false, uidTerm));
    if (!result.exists()) {
        return new ExplainResponse(shardId.getIndex(), request.type(), request.id(), false);
    }

    SearchContext context = new DefaultSearchContext(
            0, new ShardSearchLocalRequest(new String[]{request.type()}, request.nowInMillis, request.filteringAlias()),
            null, result.searcher(), indexService, indexShard,
            scriptService, pageCacheRecycler,
            bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher,
            SearchService.NO_TIMEOUT
    );
    SearchContext.setCurrent(context);

    try {
        context.parsedQuery(indexService.queryParserService().parseQuery(request.source()));
        context.preProcess();
        int topLevelDocId = result.docIdAndVersion().docId + result.docIdAndVersion().context.docBase;
        Explanation explanation = context.searcher().explain(context.query(), topLevelDocId);
        for (RescoreSearchContext ctx : context.rescore()) {
            Rescorer rescorer = ctx.rescorer();
            explanation = rescorer.explain(topLevelDocId, context, ctx, explanation);
        }
        if (request.fields() != null || (request.fetchSourceContext() != null && request.fetchSourceContext().fetchSource())) {
            // Advantage is that we're not opening a second searcher to retrieve the _source. Also
            // because we are working in the same searcher in engineGetResult we can be sure that a
            // doc isn't deleted between the initial get and this call.
            GetResult getResult = indexShard.getService().get(result, request.id(), request.type(), request.fields(), request.fetchSourceContext(), false);
            return new ExplainResponse(shardId.getIndex(), request.type(), request.id(), true, explanation, getResult);
        } else {
            return new ExplainResponse(shardId.getIndex(), request.type(), request.id(), true, explanation);
        }
    } catch (IOException e) {
        throw new ElasticsearchException("Could not explain", e);
    } finally {
        context.close();
        SearchContext.removeCurrent();
    }
}
 
Example 12
Source File: ReplicationRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new request with resolved shard id
 */
public ReplicationRequest(ActionRequest request, ShardId shardId) {
    super(request);
    this.index = shardId.getIndex();
    this.shardId = shardId;
}