/** * Sets the id of the document. */ public TermVectorsRequestBuilder setId(String id) { request.id(id); return this; }
/** * Sets an artificial document from which term vectors are requested for. */ public TermVectorsRequest doc(BytesReference doc, boolean generateRandomId, XContentType xContentType) { // assign a random id to this artificial document, for routing if (generateRandomId) { this.id(String.valueOf(randomInt.getAndAdd(1))); } this.doc = doc; this.xContentType = xContentType; return this; }
@Override public void onFailure(Exception e) { // create failures for all relevant requests for (int i = 0; i < shardRequest.locations.size(); i++) { TermVectorsRequest termVectorsRequest = shardRequest.requests.get(i); responses.set(shardRequest.locations.get(i), new MultiTermVectorsItemResponse(null, new MultiTermVectorsResponse.Failure(shardRequest.index(), termVectorsRequest.type(), termVectorsRequest.id(), e))); } if (counter.decrementAndGet() == 0) { finishHim(); } }
getFields[getFields.length - 1] = SourceFieldMapper.NAME; GetResult getResult = indexShard.getService().get( get, request.id(), request.type(), getFields, null); Fields generatedTermVectors = generateTermVectors(indexShard, getResult.sourceAsMap(), getResult.getFields().values(), request.offsets(), request.perFieldAnalyzer(), validFields);
curRequest.id(id); requests.add(curRequest);
@Override protected MultiTermVectorsShardResponse shardOperation(MultiTermVectorsShardRequest request, ShardId shardId) { final MultiTermVectorsShardResponse response = new MultiTermVectorsShardResponse(); final IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex()); final IndexShard indexShard = indexService.getShard(shardId.id()); for (int i = 0; i < request.locations.size(); i++) { TermVectorsRequest termVectorsRequest = request.requests.get(i); try { TermVectorsResponse termVectorsResponse = TermVectorsService.getTermVectors(indexShard, termVectorsRequest); response.add(request.locations.get(i), termVectorsResponse); } catch (RuntimeException e) { if (TransportActions.isShardNotAvailableException(e)) { throw e; } else { logger.debug(() -> new ParameterizedMessage("{} failed to execute multi term vectors for [{}]/[{}]", shardId, termVectorsRequest.type(), termVectorsRequest.id()), e); response.add(request.locations.get(i), new MultiTermVectorsResponse.Failure(request.index(), termVectorsRequest.type(), termVectorsRequest.id(), e)); } } } return response; }
/** * Sets the id of the document. */ public TermVectorsRequestBuilder setId(String id) { request.id(id); return this; }
/** * Constructs a new term vector request for a document that will be fetch * from the provided index. Use {@link #type(String)} and * {@link #id(String)} to specify the document to load. */ public TermVectorsRequest(TermVectorsRequest other) { super(other.index()); this.id = other.id(); this.type = other.type(); if (other.doc != null) { this.doc = new BytesArray(other.doc().toBytesRef(), true); this.xContentType = other.xContentType; } this.flagsEnum = other.getFlags().clone(); this.preference = other.preference(); this.routing = other.routing(); this.parent = other.parent(); if (other.selectedFields != null) { this.selectedFields = new HashSet<>(other.selectedFields); } if (other.perFieldAnalyzer != null) { this.perFieldAnalyzer = new HashMap<>(other.perFieldAnalyzer); } this.realtime = other.realtime(); this.version = other.version(); this.versionType = VersionType.fromValue(other.versionType().getValue()); this.filterSettings = other.filterSettings(); }
/** * Sets the id of the document. */ public TermVectorsRequestBuilder setId(String id) { request.id(id); return this; }
if (!clusterState.metaData().hasConcreteIndex(termVectorsRequest.index())) { responses.set(i, new MultiTermVectorsItemResponse(null, new MultiTermVectorsResponse.Failure(termVectorsRequest.index(), termVectorsRequest.type(), termVectorsRequest.id(), new IndexNotFoundException(termVectorsRequest.index())))); continue; clusterState.getMetaData().routingRequired(concreteSingleIndex, termVectorsRequest.type())) { responses.set(i, new MultiTermVectorsItemResponse(null, new MultiTermVectorsResponse.Failure(concreteSingleIndex, termVectorsRequest.type(), termVectorsRequest.id(), new RoutingMissingException(concreteSingleIndex, termVectorsRequest.type(), termVectorsRequest.id())))); continue; termVectorsRequest.id(), termVectorsRequest.routing()); MultiTermVectorsShardRequest shardRequest = shardRequests.get(shardId); if (shardRequest == null) {
@Override protected ShardIterator shards(ClusterState state, InternalRequest request) { if (request.request().doc() != null && request.request().routing() == null) { // artificial document without routing specified, ignore its "id" and use either random shard or according to preference GroupShardsIterator<ShardIterator> groupShardsIter = clusterService.operationRouting().searchShards(state, new String[] { request.concreteIndex() }, null, request.request().preference()); return groupShardsIter.iterator().next(); } return clusterService.operationRouting().getShards(state, request.concreteIndex(), request.request().id(), request.request().routing(), request.request().preference()); }
/** * Sets an artificial document from which term vectors are requested for. */ public TermVectorsRequest doc(BytesReference doc, boolean generateRandomId, XContentType xContentType) { // assign a random id to this artificial document, for routing if (generateRandomId) { this.id(String.valueOf(randomInt.getAndAdd(1))); } this.doc = doc; this.xContentType = xContentType; return this; }
/** * Convert this to a {@link TermVectorsRequest} for fetching the terms of the document. */ TermVectorsRequest toTermVectorsRequest() { TermVectorsRequest termVectorsRequest = new TermVectorsRequest(index, type, id) .selectedFields(fields) .routing(routing) .version(version) .versionType(versionType) .perFieldAnalyzer(perFieldAnalyzer) .positions(false) // ensures these following parameters are never set .offsets(false) .payloads(false) .fieldStatistics(false) .termStatistics(false); // for artificial docs to make sure that the id has changed in the item too if (doc != null) { termVectorsRequest.doc(doc, true, xContentType); this.id = termVectorsRequest.id(); } return termVectorsRequest; }
@Override protected void resolveRequest(ClusterState state, InternalRequest request) { // update the routing (request#index here is possibly an alias or a parent) request.request().routing(state.metaData() .resolveIndexRouting(request.request().parent(), request.request().routing(), request.request().index())); // Fail fast on the node that received the request. if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) { throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id()); } }
static TermVectorsResponse getTermVectors(IndexShard indexShard, TermVectorsRequest request, LongSupplier nanoTimeSupplier) { final long startTime = nanoTimeSupplier.getAsLong(); final TermVectorsResponse termVectorsResponse = new TermVectorsResponse(indexShard.shardId().getIndex().getName(), request.type(), request.id()); final Term uidTerm = indexShard.mapperService().createUidTerm(request.type(), request.id()); if (uidTerm == null) { termVectorsResponse.setExists(false); return termVectorsResponse; Engine.GetResult get = indexShard.get(new Engine.Get(request.realtime(), false, request.type(), request.id(), uidTerm) .version(request.version()).versionType(request.versionType()));
@Override protected ShardIterator shards(ClusterState state, InternalRequest request) { if (request.request().doc() != null && request.request().routing() == null) { // artificial document without routing specified, ignore its "id" and use either random shard or according to preference GroupShardsIterator<ShardIterator> groupShardsIter = clusterService.operationRouting().searchShards(state, new String[] { request.concreteIndex() }, null, request.request().preference()); return groupShardsIter.iterator().next(); } return clusterService.operationRouting().getShards(state, request.concreteIndex(), request.request().id(), request.request().routing(), request.request().preference()); }
@Override protected ShardIterator shards(ClusterState state, InternalRequest request) { if (request.request().doc() != null && request.request().routing() == null) { // artificial document without routing specified, ignore its "id" and use either random shard or according to preference GroupShardsIterator<ShardIterator> groupShardsIter = clusterService.operationRouting().searchShards(state, new String[] { request.concreteIndex() }, null, request.request().preference()); return groupShardsIter.iterator().next(); } return clusterService.operationRouting().getShards(state, request.concreteIndex(), request.request().id(), request.request().routing(), request.request().preference()); }
@Override protected void resolveRequest(ClusterState state, InternalRequest request) { // update the routing (request#index here is possibly an alias or a parent) request.request().routing(state.metaData().resolveIndexRouting(request.request().parent(), request.request().routing(), request.request().index())); // Fail fast on the node that received the request. if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) { throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id()); } }
@Override protected void resolveRequest(ClusterState state, InternalRequest request) { // update the routing (request#index here is possibly an alias or a parent) request.request().routing(state.metaData().resolveIndexRouting(request.request().parent(), request.request().routing(), request.request().index())); // Fail fast on the node that received the request. if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) { throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id()); } }
@Override protected void resolveRequest(ClusterState state, InternalRequest request) { // update the routing (request#index here is possibly an alias or a parent) request.request().routing(state.metaData().resolveIndexRouting(request.request().parent(), request.request().routing(), request.request().index())); // Fail fast on the node that received the request. if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) { throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id()); } }