Java Code Examples for org.elasticsearch.index.VersionType#INTERNAL

The following examples show how to use org.elasticsearch.index.VersionType#INTERNAL . 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: TransportDeleteAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static void resolveAndValidateRouting(final MetaData metaData, String concreteIndex, DeleteRequest request) {
    request.routing(metaData.resolveIndexRouting(request.routing(), request.index()));
    if (metaData.hasIndex(concreteIndex)) {
        // check if routing is required, if so, throw error if routing wasn't specified
        MappingMetaData mappingMd = metaData.index(concreteIndex).mappingOrDefault(request.type());
        if (mappingMd != null && mappingMd.routing().required()) {
            if (request.routing() == null) {
                if (request.versionType() != VersionType.INTERNAL) {
                    // TODO: implement this feature
                    throw new IllegalArgumentException("routing value is required for deleting documents of type [" + request.type()
                        + "] while using version_type [" + request.versionType() + "]");
                }
                throw new RoutingMissingException(concreteIndex, request.type(), request.id());
            }
        }
    }
}
 
Example 2
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 3
Source File: MoreLikeThisQueryBuilder.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    if (this.index != null) {
        builder.field(Field.INDEX.getPreferredName(), this.index);
    }
    if (this.type != null) {
        builder.field(Field.TYPE.getPreferredName(), this.type);
    }
    if (this.id != null && this.doc == null) {
        builder.field(Field.ID.getPreferredName(), this.id);
    }
    if (this.doc != null) {
        XContentType contentType = XContentFactory.xContentType(this.doc);
        if (contentType == builder.contentType()) {
            builder.rawField(Field.DOC.getPreferredName(), this.doc);
        } else {
            XContentParser parser = XContentFactory.xContent(contentType).createParser(this.doc);
            parser.nextToken();
            builder.field(Field.DOC.getPreferredName());
            builder.copyCurrentStructure(parser);
        }
    }
    if (this.fields != null) {
        builder.array(Field.FIELDS.getPreferredName(), this.fields);
    }
    if (this.perFieldAnalyzer != null) {
        builder.field(Field.PER_FIELD_ANALYZER.getPreferredName(), this.perFieldAnalyzer);
    }
    if (this.routing != null) {
        builder.field(Field.ROUTING.getPreferredName(), this.routing);
    }
    if (this.version != Versions.MATCH_ANY) {
        builder.field(Field.VERSION.getPreferredName(), this.version);
    }
    if (this.versionType != VersionType.INTERNAL) {
        builder.field(Field.VERSION_TYPE.getPreferredName(), this.versionType.toString().toLowerCase(Locale.ROOT));
    }
    return builder.endObject();
}
 
Example 4
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 5
Source File: MappingMetaData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public ParsedVersion(String path, VersionType versionType) {
    this.path = path;
    if (path == null) {
        this.pathElements = Strings.EMPTY_ARRAY;
        this.versionType = VersionType.INTERNAL;
    } else {
        this.versionType = versionType;
        this.pathElements = Strings.delimitedListToStringArray(path, ".");
    }
}
 
Example 6
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 7
Source File: UpdateRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    ActionRequestValidationException validationException = super.validate();
    if (type == null) {
        validationException = addValidationError("type is missing", validationException);
    }
    if (id == null) {
        validationException = addValidationError("id is missing", validationException);
    }

    if (!(versionType == VersionType.INTERNAL || versionType == VersionType.FORCE)) {
        validationException = addValidationError("version type [" + versionType + "] is not supported by the update API", validationException);
    } else {

        if (version != Versions.MATCH_ANY && retryOnConflict > 0) {
            validationException = addValidationError("can't provide both retry_on_conflict and a specific version", validationException);
        }

        if (!versionType.validateVersionForWrites(version)) {
            validationException = addValidationError("illegal version value [" + version + "] for version type [" + versionType.name() + "]", validationException);
        }
    }

    if (script == null && doc == null) {
        validationException = addValidationError("script or doc is missing", validationException);
    }
    if (script != null && doc != null) {
        validationException = addValidationError("can't provide both script and doc", validationException);
    }
    if (doc == null && docAsUpsert) {
        validationException = addValidationError("doc must be specified if doc_as_upsert is enabled", validationException);
    }
    return validationException;
}
 
Example 8
Source File: Engine.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public IndexingOperation(Term uid, ParsedDocument doc) {
    this(uid, doc, Versions.MATCH_ANY, VersionType.INTERNAL, Origin.PRIMARY, System.nanoTime(), true);
}
 
Example 9
Source File: Engine.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public Delete(String type, String id, Term uid) {
    this(type, id, uid, Versions.MATCH_ANY, VersionType.INTERNAL, Origin.PRIMARY, System.nanoTime(), false);
}
 
Example 10
Source File: EngineTestCase.java    From crate with Apache License 2.0 4 votes vote down vote up
protected Engine.Index indexForDoc(ParsedDocument doc) {
    return new Engine.Index(
        newUid(doc), doc, UNASSIGNED_SEQ_NO, primaryTerm.get(),
        Versions.MATCH_ANY, VersionType.INTERNAL, Engine.Operation.Origin.PRIMARY,
        System.nanoTime(), -1, false, UNASSIGNED_SEQ_NO, 0);
}