org.elasticsearch.index.VersionType Java Examples

The following examples show how to use org.elasticsearch.index.VersionType. 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: MultiGetRequest.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    index = in.readString();
    type = in.readOptionalString();
    id = in.readString();
    routing = in.readOptionalString();
    int size = in.readVInt();
    if (size > 0) {
        fields = new String[size];
        for (int i = 0; i < size; i++) {
            fields[i] = in.readString();
        }
    }
    version = in.readLong();
    versionType = VersionType.fromValue(in.readByte());

    fetchSourceContext = FetchSourceContext.optionalReadFromStream(in);
}
 
Example #2
Source File: TransportShardUpsertAction.java    From crate with Apache License 2.0 6 votes vote down vote up
private static Doc getDocument(IndexShard indexShard, String id, long version, long seqNo, long primaryTerm) {
    // when sequence versioning is used, this lookup will throw VersionConflictEngineException
    Doc doc = PKLookupOperation.lookupDoc(indexShard, id, Versions.MATCH_ANY, VersionType.INTERNAL, seqNo, primaryTerm);
    if (doc == null) {
        throw new DocumentMissingException(indexShard.shardId(), Constants.DEFAULT_MAPPING_TYPE, id);
    }
    if (doc.getSource() == null) {
        throw new DocumentSourceMissingException(indexShard.shardId(), Constants.DEFAULT_MAPPING_TYPE, id);
    }
    if (version != Versions.MATCH_ANY && version != doc.getVersion()) {
        throw new VersionConflictEngineException(
            indexShard.shardId(),
            id,
            "Requested version: " + version + " but got version: " + doc.getVersion());
    }
    return doc;
}
 
Example #3
Source File: IndexShard.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private void reindex(QueryFetchSearchResult hits, String index, String type) {
    logger.debug("Reindex: [index:{}, type:{}]", index, type);

    if (state == IndexShardState.STARTED) {
        for (InternalSearchHit hit : hits.fetchResult().hits().internalHits()) {
            // no difference between PRIMARY and REPLICA
            SourceToParse source = SourceToParse.source(SourceToParse.Origin.REPLICA, hit.sourceRef())
                    .index(index).type(type).id(hit.id());
            if (hit.field(ParentFieldMapper.NAME).getValue() != null) {
                source.parent((String) hit.field(ParentFieldMapper.NAME).getValue());
            }
            if (hit.field(TimestampFieldMapper.NAME).getValue() != null) {
                source.timestamp((long) hit.field(TimestampFieldMapper.NAME).getValue());
            }
            long version = 0;
            if (hit.field(VersionFieldMapper.NAME).getValue() != null) {
                version = (long) hit.field(VersionFieldMapper.NAME).getValue();
            }
            Engine.Index indexOp = prepareIndex(docMapper(source.type()), source, version, VersionType.EXTERNAL_GTE, Engine.Operation.Origin.RECOVERY, state != IndexShardState.STARTED);
            indexOp.setReindex(true);
            index(indexOp);
        }
    }
}
 
Example #4
Source File: RestDeleteIndexedScriptAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, Client client) {
    DeleteIndexedScriptRequest deleteIndexedScriptRequest = new DeleteIndexedScriptRequest(getScriptLang(request), request.param("id"));
    deleteIndexedScriptRequest.version(request.paramAsLong("version", deleteIndexedScriptRequest.version()));
    deleteIndexedScriptRequest.versionType(VersionType.fromString(request.param("version_type"), deleteIndexedScriptRequest.versionType()));
    client.deleteIndexedScript(deleteIndexedScriptRequest, new RestBuilderListener<DeleteIndexedScriptResponse>(channel) {
        @Override
        public RestResponse buildResponse(DeleteIndexedScriptResponse result, XContentBuilder builder) throws Exception {
            builder.startObject()
                    .field(Fields.FOUND, result.isFound())
                    .field(Fields._INDEX, result.getIndex())
                    .field(Fields._TYPE, result.getType())
                    .field(Fields._ID, result.getId())
                    .field(Fields._VERSION, result.getVersion())
                    .endObject();
            RestStatus status = OK;
            if (!result.isFound()) {
                status = NOT_FOUND;
            }
            return new BytesRestResponse(status, builder);
        }
    });
}
 
Example #5
Source File: RecoverySourceHandlerTests.java    From crate with Apache License 2.0 6 votes vote down vote up
private Engine.Index getIndex(final String id) {
    final String type = "test";
    final ParseContext.Document document = new ParseContext.Document();
    document.add(new TextField("test", "test", Field.Store.YES));
    final Field idField = new Field("_id", Uid.encodeId(id), IdFieldMapper.Defaults.FIELD_TYPE);
    final Field versionField = new NumericDocValuesField("_version", Versions.MATCH_ANY);
    final SeqNoFieldMapper.SequenceIDFields seqID = SeqNoFieldMapper.SequenceIDFields.emptySeqID();
    document.add(idField);
    document.add(versionField);
    document.add(seqID.seqNo);
    document.add(seqID.seqNoDocValue);
    document.add(seqID.primaryTerm);
    final BytesReference source = new BytesArray(new byte[] { 1 });
    final ParsedDocument doc =
        new ParsedDocument(versionField, seqID, id, type, List.of(document), source, null);
    return new Engine.Index(
        new Term("_id", Uid.encodeId(doc.id())), doc, UNASSIGNED_SEQ_NO, 0,
        Versions.MATCH_ANY, VersionType.INTERNAL, PRIMARY, System.nanoTime(), -1, false, UNASSIGNED_SEQ_NO, 0);

}
 
Example #6
Source File: RestTermVectorsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
static public void readURIParameters(TermVectorsRequest termVectorsRequest, RestRequest request) {
    String fields = request.param("fields");
    addFieldStringsFromParameter(termVectorsRequest, fields);
    termVectorsRequest.offsets(request.paramAsBoolean("offsets", termVectorsRequest.offsets()));
    termVectorsRequest.positions(request.paramAsBoolean("positions", termVectorsRequest.positions()));
    termVectorsRequest.payloads(request.paramAsBoolean("payloads", termVectorsRequest.payloads()));
    termVectorsRequest.routing(request.param("routing"));
    termVectorsRequest.realtime(request.paramAsBoolean("realtime", null));
    termVectorsRequest.version(RestActions.parseVersion(request, termVectorsRequest.version()));
    termVectorsRequest.versionType(VersionType.fromString(request.param("version_type"), termVectorsRequest.versionType()));
    termVectorsRequest.parent(request.param("parent"));
    termVectorsRequest.preference(request.param("preference"));
    termVectorsRequest.termStatistics(request.paramAsBoolean("termStatistics", termVectorsRequest.termStatistics()));
    termVectorsRequest.termStatistics(request.paramAsBoolean("term_statistics", termVectorsRequest.termStatistics()));
    termVectorsRequest.fieldStatistics(request.paramAsBoolean("fieldStatistics", termVectorsRequest.fieldStatistics()));
    termVectorsRequest.fieldStatistics(request.paramAsBoolean("field_statistics", termVectorsRequest.fieldStatistics()));
    termVectorsRequest.dfs(request.paramAsBoolean("dfs", termVectorsRequest.dfs()));
}
 
Example #7
Source File: ShardUpsertRequest.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    id = in.readString();
    int assignmentsSize = in.readVInt();
    if (assignmentsSize > 0) {
        updateAssignments = new Symbol[assignmentsSize];
        for (int i = 0; i < assignmentsSize; i++) {
            updateAssignments[i] = Symbol.fromStream(in);
        }
    }
    int missingAssignmentsSize = in.readVInt();
    if (missingAssignmentsSize > 0) {
        this.insertValues = new Object[missingAssignmentsSize];
        for (int i = 0; i < missingAssignmentsSize; i++) {
            insertValues[i] = insertValuesStreamer[i].readValueFrom(in);
        }
    }
    this.version = Version.readVersion(in).id;
    versionType = VersionType.fromValue(in.readByte());
    opType = IndexRequest.OpType.fromId(in.readByte());
    if (in.readBoolean()) {
        source = in.readBytesReference();
    }
}
 
Example #8
Source File: IndexShard.java    From crate with Apache License 2.0 5 votes vote down vote up
private Engine.DeleteResult applyDeleteOperation(Engine engine,
                                                 long seqNo,
                                                 long opPrimaryTerm,
                                                 long version,
                                                 String type,
                                                 String id,
                                                 @Nullable VersionType versionType,
                                                 long ifSeqNo,
                                                 long ifPrimaryTerm,
                                                 Engine.Operation.Origin origin) throws IOException {
    assert opPrimaryTerm <= this.operationPrimaryTerm : "op term [ " + opPrimaryTerm + " ] > shard term [" + this.operationPrimaryTerm
        + "]";
    ensureWriteAllowed(origin);
    // When there is a single type, the unique identifier is only composed of the _id,
    // so there is no way to differentiate foo#1 from bar#1. This is especially an issue
    // if a user first deletes foo#1 and then indexes bar#1: since we do not encode the
    // _type in the uid it might look like we are reindexing the same document, which
    // would fail if bar#1 is indexed with a lower version than foo#1 was deleted with.
    // In order to work around this issue, we make deletions create types. This way, we
    // fail if index and delete operations do not use the same type.
    final Term uid = extractUidForDelete(type, id);
    final Engine.Delete delete = prepareDelete(
        type,
        id,
        uid,
        seqNo,
        opPrimaryTerm,
        version,
        versionType,
        origin,
        ifSeqNo,
        ifPrimaryTerm
    );
    return delete(engine, delete);
}
 
Example #9
Source File: Translog.java    From crate with Apache License 2.0 5 votes vote down vote up
private void write(final StreamOutput out) throws IOException {
    final int format = out.getVersion().onOrAfter(Version.V_4_0_0) ? SERIALIZATION_FORMAT : FORMAT_6_0;
    out.writeVInt(format);
    out.writeString(type);
    out.writeString(id);
    out.writeString(uid.field());
    out.writeBytesRef(uid.bytes());
    out.writeLong(version);
    if (format < FORMAT_NO_VERSION_TYPE) {
        out.writeByte(VersionType.EXTERNAL.getValue());
    }
    out.writeLong(seqNo);
    out.writeLong(primaryTerm);
}
 
Example #10
Source File: UpdateRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    consistencyLevel = WriteConsistencyLevel.fromId(in.readByte());
    type = in.readString();
    id = in.readString();
    routing = in.readOptionalString();
    parent = in.readOptionalString();
    if (in.readBoolean()) {
        script = Script.readScript(in);
    }
    retryOnConflict = in.readVInt();
    refresh = in.readBoolean();
    if (in.readBoolean()) {
        doc = new IndexRequest();
        doc.readFrom(in);
    }
    int size = in.readInt();
    if (size >= 0) {
        fields = new String[size];
        for (int i = 0; i < size; i++) {
            fields[i] = in.readString();
        }
    }
    if (in.readBoolean()) {
        upsertRequest = new IndexRequest();
        upsertRequest.readFrom(in);
    }
    docAsUpsert = in.readBoolean();
    version = in.readLong();
    versionType = VersionType.fromValue(in.readByte());
    detectNoop = in.readBoolean();
    scriptedUpsert = in.readBoolean();
}
 
Example #11
Source File: IndexRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    if (in.getVersion().before(Version.V_2_3_0)) {
        type = in.readString();
    } else {
        type = in.readOptionalString();
    }
    id = in.readOptionalString();
    routing = in.readOptionalString();
    parent = in.readOptionalString();
    timestamp = in.readOptionalString();
    if (in.getVersion().before(Version.V_2_2_0)) {
        long ttl = in.readLong();
        if (ttl == -1) {
            this.ttl = null;
        } else {
            ttl(ttl);
        }
    } else {
        ttl = in.readBoolean() ? TimeValue.readTimeValue(in) : null;
    }
    source = in.readBytesReference();

    opType = OpType.fromId(in.readByte());
    refresh = in.readBoolean();
    version = in.readLong();
    versionType = VersionType.fromValue(in.readByte());
    autoGeneratedId = in.readBoolean();
}
 
Example #12
Source File: TermVectorsRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    type = in.readString();
    id = in.readString();

    if (in.readBoolean()) {
        doc = in.readBytesReference();
    }
    routing = in.readOptionalString();
    preference = in.readOptionalString();
    long flags = in.readVLong();

    flagsEnum.clear();
    for (Flag flag : Flag.values()) {
        if ((flags & (1 << flag.ordinal())) != 0) {
            flagsEnum.add(flag);
        }
    }
    int numSelectedFields = in.readVInt();
    if (numSelectedFields > 0) {
        selectedFields = new HashSet<>();
        for (int i = 0; i < numSelectedFields; i++) {
            selectedFields.add(in.readString());
        }
    }
    if (in.readBoolean()) {
        perFieldAnalyzer = readPerFieldAnalyzer(in.readMap());
    }
    if (in.readBoolean()) {
        filterSettings = new FilterSettings();
        filterSettings.readFrom(in);
    }
    realtime = in.readBoolean();
    versionType = VersionType.fromValue(in.readByte());
    version = in.readLong();
}
 
Example #13
Source File: IndexShard.java    From crate with Apache License 2.0 5 votes vote down vote up
public Engine.DeleteResult applyDeleteOperationOnPrimary(long version,
                                                         String type,
                                                         String id,
                                                         VersionType versionType,
                                                         long ifSeqNo,
                                                         long ifPrimaryTerm)
    throws IOException {
    return applyDeleteOperation(getEngine(), UNASSIGNED_SEQ_NO, operationPrimaryTerm, version, type, id, versionType,
                                ifSeqNo, ifPrimaryTerm, Engine.Operation.Origin.PRIMARY);
}
 
Example #14
Source File: IndexShard.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
static Engine.Create prepareCreate(DocumentMapperForType docMapper, SourceToParse source, long version, VersionType versionType,
                                   Engine.Operation.Origin origin, boolean canHaveDuplicates, boolean autoGeneratedId) {
    long startTime = System.nanoTime();
    ParsedDocument doc = docMapper.getDocumentMapper().parse(source);
    if (docMapper.getMapping() != null) {
        doc.addDynamicMappingsUpdate(docMapper.getMapping());
    }
    return new Engine.Create(docMapper.getDocumentMapper().uidMapper().term(doc.uid().stringValue()), doc, version, versionType,
            origin, startTime, canHaveDuplicates, autoGeneratedId);
}
 
Example #15
Source File: IndexShard.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
static Engine.Index prepareIndex(DocumentMapperForType docMapper, SourceToParse source, long version, VersionType versionType, Engine
        .Operation.Origin origin, boolean canHaveDuplicates) {
    long startTime = System.nanoTime();
    ParsedDocument doc = docMapper.getDocumentMapper().parse(source);
    if (docMapper.getMapping() != null) {
        doc.addDynamicMappingsUpdate(docMapper.getMapping());
    }
    return new Engine.Index(docMapper.getDocumentMapper().uidMapper().term(doc.uid().stringValue()), doc, version, versionType,
            origin, startTime, canHaveDuplicates);
}
 
Example #16
Source File: IndexShard.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Engine.Delete prepareDeleteOnPrimary(String type, String id, long version, VersionType versionType) {
    if (shardRouting.primary() == false) {
        throw new IllegalIndexShardStateException(shardId, state, "shard is not a primary");
    }
    final DocumentMapper documentMapper = docMapper(type).getDocumentMapper();
    return prepareDelete(type, id, documentMapper.uidMapper().term(Uid.createUid(type, id)), version, versionType, Engine.Operation
            .Origin.PRIMARY);
}
 
Example #17
Source File: IndexShard.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Engine.Index prepareIndexOnReplica(SourceToParse source, long version, VersionType versionType, boolean canHaveDuplicates) {
    try {
        return prepareIndex(docMapper(source.type()), source, version, versionType, Engine.Operation.Origin.REPLICA, state !=
                IndexShardState.STARTED || canHaveDuplicates);
    } catch (Throwable t) {
        verifyNotClosed(t);
        throw t;
    }
}
 
Example #18
Source File: Engine.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public IndexingOperation(Term uid, ParsedDocument doc, long version, VersionType versionType, Origin origin, long startTime, boolean canHaveDuplicates) {
    this.uid = uid;
    this.doc = doc;
    this.version = version;
    this.versionType = versionType;
    this.origin = origin;
    this.startTime = startTime;
    this.canHaveDuplicates = canHaveDuplicates;
    this.reindex = false;
}
 
Example #19
Source File: PutIndexedScriptRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    scriptLang = in.readString();
    id = in.readOptionalString();
    source = in.readBytesReference();

    opType = IndexRequest.OpType.fromId(in.readByte());
    version = in.readLong();
    versionType = VersionType.fromValue(in.readByte());
}
 
Example #20
Source File: DeleteIndexedScriptRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    scriptLang = in.readString();
    id = in.readString();
    version = in.readLong();
    versionType = VersionType.fromValue(in.readByte());
}
 
Example #21
Source File: IndexShard.java    From crate with Apache License 2.0 5 votes vote down vote up
public Engine.IndexResult applyIndexOperationOnPrimary(long version,
                                                       VersionType versionType,
                                                       SourceToParse sourceToParse,
                                                       long ifSeqNo,
                                                       long ifPrimaryTerm,
                                                       long autoGeneratedTimestamp,
                                                       boolean isRetry)
    throws IOException {
    return applyIndexOperation(getEngine(), UNASSIGNED_SEQ_NO, operationPrimaryTerm, version, versionType, ifSeqNo,
                               ifPrimaryTerm, autoGeneratedTimestamp, isRetry, Engine.Operation.Origin.PRIMARY, sourceToParse);
}
 
Example #22
Source File: RestGetAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
    getRequest.operationThreaded(true);
    getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
    getRequest.routing(request.param("routing"));  // order is important, set it after routing, so it will set the routing
    getRequest.parent(request.param("parent"));
    getRequest.preference(request.param("preference"));
    getRequest.realtime(request.paramAsBoolean("realtime", null));
    getRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));

    String sField = request.param("fields");
    if (sField != null) {
        String[] sFields = Strings.splitStringByCommaToArray(sField);
        if (sFields != null) {
            getRequest.fields(sFields);
        }
    }

    getRequest.version(RestActions.parseVersion(request));
    getRequest.versionType(VersionType.fromString(request.param("version_type"), getRequest.versionType()));

    getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));

    client.get(getRequest, new RestBuilderListener<GetResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            response.toXContent(builder, request);
            builder.endObject();
            if (!response.isExists()) {
                return new BytesRestResponse(NOT_FOUND, builder);
            } else {
                return new BytesRestResponse(OK, builder);
            }
        }
    });
}
 
Example #23
Source File: Engine.java    From crate with Apache License 2.0 5 votes vote down vote up
public Delete(String type, String id, Term uid, long seqNo, long primaryTerm, long version, VersionType versionType,
              Origin origin, long startTime, long ifSeqNo, long ifPrimaryTerm) {
    super(uid, seqNo, primaryTerm, version, versionType, origin, startTime);
    assert (origin == Origin.PRIMARY) == (versionType != null) : "invalid version_type=" + versionType + " for origin=" + origin;
    assert ifPrimaryTerm >= 0 : "ifPrimaryTerm [" + ifPrimaryTerm + "] must be non negative";
    assert ifSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO || ifSeqNo >= 0 :
        "ifSeqNo [" + ifSeqNo + "] must be non negative or unset";
    assert (origin == Origin.PRIMARY) || (ifSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO && ifPrimaryTerm == 0) :
        "cas operations are only allowed if origin is primary. get [" + origin + "]";
    this.type = Objects.requireNonNull(type);
    this.id = Objects.requireNonNull(id);
    this.ifSeqNo = ifSeqNo;
    this.ifPrimaryTerm = ifPrimaryTerm;
}
 
Example #24
Source File: TransportShardDeleteAction.java    From crate with Apache License 2.0 5 votes vote down vote up
private Engine.DeleteResult shardDeleteOperationOnPrimary(ShardDeleteRequest.Item item, IndexShard indexShard) throws IOException {
    Engine.DeleteResult deleteResult = indexShard.applyDeleteOperationOnPrimary(
        item.version(), Constants.DEFAULT_MAPPING_TYPE, item.id(), VersionType.INTERNAL, item.seqNo(), item.primaryTerm());

    // set version and sequence number for replica
    item.version(deleteResult.getVersion());
    item.seqNo(deleteResult.getSeqNo());

    return deleteResult;
}
 
Example #25
Source File: GetIndexedScriptRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    scriptLang = in.readString();
    id = in.readString();
    this.versionType = VersionType.fromValue(in.readByte());
    this.version = in.readLong();
}
 
Example #26
Source File: MappingMetaData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public ParsedVersion(String path, String versionType) {
    this.path = path;
    if (path == null) {
        this.pathElements = Strings.EMPTY_ARRAY;
        this.versionType = VersionType.INTERNAL;
    } else {
        this.versionType = VersionType.fromString(versionType);
        this.pathElements = Strings.delimitedListToStringArray(path, ".");
    }
}
 
Example #27
Source File: DeleteRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    type = in.readString();
    id = in.readString();
    routing = in.readOptionalString();
    refresh = in.readBoolean();
    version = in.readLong();
    versionType = VersionType.fromValue(in.readByte());
}
 
Example #28
Source File: MappingMetaData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public MappingMetaData(DocumentMapper docMapper, long mappingVersion) {
    this.type = docMapper.type();
    this.source = docMapper.mappingSource();
    this.id = new Id(docMapper.idFieldMapper().path());
    this.routing = new Routing(docMapper.routingFieldMapper().required(), docMapper.routingFieldMapper().path());
    this.timestamp = new Timestamp(docMapper.timestampFieldMapper().enabled(), docMapper.timestampFieldMapper().path(),
            docMapper.timestampFieldMapper().fieldType().dateTimeFormatter().format(), docMapper.timestampFieldMapper().defaultTimestamp(),
            docMapper.timestampFieldMapper().ignoreMissing());
    this.version = new ParsedVersion(docMapper.versionFieldMapper().path(), docMapper.versionFieldMapper().VersionType());
    this.hasParentField = docMapper.parentFieldMapper().active();
    this.mappingVersion = mappingVersion;
}
 
Example #29
Source File: MappingMetaData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public MappingMetaData readFrom(StreamInput in) throws IOException {
    String type = in.readString();
    CompressedXContent source = CompressedXContent.readCompressedString(in);
    // id
    Id id = new Id(in.readBoolean() ? in.readString() : null);
    // routing
    Routing routing = new Routing(in.readBoolean(), in.readBoolean() ? in.readString() : null);
    // timestamp

    boolean enabled = in.readBoolean();
    String path = in.readOptionalString();
    String format = in.readString();
    String defaultTimestamp = in.readOptionalString();
    Boolean ignoreMissing = null;

    ignoreMissing = in.readOptionalBoolean();

    final Timestamp timestamp = new Timestamp(enabled, path, format, defaultTimestamp, ignoreMissing);
    final boolean hasParentField = in.readBoolean();
    final long mappingVersion = in.readLong();

    ParsedVersion version = new ParsedVersion(null, VersionType.INTERNAL);
    boolean hasVersionPath = in.readBoolean();
    if (hasVersionPath) {
        String versionPath = in.readString();
        VersionType versionType = VersionType.fromValue(in.readByte());
        version = new ParsedVersion(versionPath, versionType);
    }
    return new MappingMetaData(type, source, id, routing, timestamp, hasParentField, version, mappingVersion);
}
 
Example #30
Source File: PKLookupOperation.java    From crate with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Doc lookupDoc(IndexShard shard, String id, long version, VersionType versionType, long seqNo, long primaryTerm) {
    Term uidTerm = new Term(IdFieldMapper.NAME, Uid.encodeId(id));
    Engine.Get get = new Engine.Get(id, uidTerm)
        .version(version)
        .versionType(versionType)
        .setIfSeqNo(seqNo)
        .setIfPrimaryTerm(primaryTerm);

    try (Engine.GetResult getResult = shard.get(get)) {
        var docIdAndVersion = getResult.docIdAndVersion();
        if (docIdAndVersion == null) {
            return null;
        }
        SourceFieldVisitor visitor = new SourceFieldVisitor();
        try {
            docIdAndVersion.reader.document(docIdAndVersion.docId, visitor);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
        return new Doc(
            docIdAndVersion.docId,
            shard.shardId().getIndexName(),
            id,
            docIdAndVersion.version,
            docIdAndVersion.seqNo,
            docIdAndVersion.primaryTerm,
            XContentHelper.toMap(visitor.source(), XContentType.JSON),
            () -> visitor.source().utf8ToString()
        );
    }
}