Examples of UidField


Examples of org.elasticsearch.common.lucene.uid.UidField

        }
        context.uid(Uid.createUid(context.stringBuilder(), context.type(), context.id()));
        // so, caching uid stream and field is fine
        // since we don't do any mapping parsing without immediate indexing
        // and, when percolating, we don't index the uid
        UidField field = fieldCache.get();
        field.setUid(context.uid());
        return field; // version get updated by the engine
    }
View Full Code Here

Examples of org.elasticsearch.common.lucene.uid.UidField

                        throw new MapperParsingException("No id found while parsing the content source");
                    }
                } else {
                    uidFieldMapper.parse(context);
                    if (context.docs().size() > 1) {
                        UidField uidField = (UidField) context.doc().getFieldable(UidFieldMapper.NAME);
                        assert uidField != null;
                        // we need to go over the docs and add it...
                        for (int i = 1; i < context.docs().size(); i++) {
                            // we don't need to add it as a full uid field in nested docs, since we don't need versioning
                            context.docs().get(i).add(new Field(UidFieldMapper.NAME, uidField.uid(), Field.Store.NO, Field.Index.NOT_ANALYZED));
                        }
                    }
                }
            }
            if (context.parsedIdState() != ParseContext.ParsedIdState.PARSED) {
View Full Code Here

Examples of org.elasticsearch.common.lucene.uid.UidField

        }
    }

    private void innerCreate(Create create, IndexWriter writer) throws IOException {
        synchronized (dirtyLock(create.uid())) {
            UidField uidField = create.uidField();
            if (create.origin() == Operation.Origin.RECOVERY) {
                uidField.version(create.version());
                // we use update doc and not addDoc since we might get duplicates when using transient translog
                if (create.docs().size() > 1) {
                    writer.updateDocuments(create.uid(), create.docs(), create.analyzer());
                } else {
                    writer.updateDocument(create.uid(), create.docs().get(0), create.analyzer());
                }
                Translog.Location translogLocation = translog.add(new Translog.Create(create));
                // on recovery, we get the actual version we want to use
                if (create.version() != 0) {
                    versionMap.put(create.uid().text(), new VersionValue(create.version(), false, threadPool.estimatedTimeInMillis(), translogLocation));
                }
            } else {
                long currentVersion;
                VersionValue versionValue = versionMap.get(create.uid().text());
                if (versionValue == null) {
                    currentVersion = loadCurrentVersionFromIndex(create.uid());
                } else {
                    if (versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
                        currentVersion = -1; // deleted, and GC
                    } else {
                        currentVersion = versionValue.version();
                    }
                }

                // same logic as index
                long updatedVersion;
                if (create.origin() == Operation.Origin.PRIMARY) {
                    if (create.versionType() == VersionType.INTERNAL) { // internal version type
                        long expectedVersion = create.version();
                        if (expectedVersion != 0 && currentVersion != -2) { // -2 means we don't have a version, so ignore...
                            // an explicit version is provided, see if there is a conflict
                            // if the current version is -1, means we did not find anything, and
                            // a version is provided, so we do expect to find a doc under that version
                            // this is important, since we don't allow to preset a version in order to handle deletes
                            if (currentVersion == -1) {
                                throw new VersionConflictEngineException(shardId, create.type(), create.id(), -1, expectedVersion);
                            } else if (expectedVersion != currentVersion) {
                                throw new VersionConflictEngineException(shardId, create.type(), create.id(), currentVersion, expectedVersion);
                            }
                        }
                        updatedVersion = currentVersion < 0 ? 1 : currentVersion + 1;
                    } else { // external version type
                        // an external version is provided, just check, if a local version exists, that its higher than it
                        // the actual version checking is one in an external system, and we just want to not index older versions
                        if (currentVersion >= 0) { // we can check!, its there
                            if (currentVersion >= create.version()) {
                                throw new VersionConflictEngineException(shardId, create.type(), create.id(), currentVersion, create.version());
                            }
                        }
                        updatedVersion = create.version();
                    }
                } else { // if (index.origin() == Operation.Origin.REPLICA) {
                    long expectedVersion = create.version();
                    if (currentVersion != -2) { // -2 means we don't have a version, so ignore...
                        // if it does not exists, and its considered the first index operation (replicas are 1 of)
                        // then nothing to do
                        if (!(currentVersion == -1 && create.version() == 1)) {
                            // with replicas, we only check for previous version, we allow to set a future version
                            if (expectedVersion <= currentVersion) {
                                throw new VersionConflictEngineException(shardId, create.type(), create.id(), currentVersion, expectedVersion);
                            }
                        }
                    }
                    // replicas already hold the "future" version
                    updatedVersion = create.version();
                }

                // if the doc does not exists or it exists but not delete
                if (versionValue != null) {
                    if (!versionValue.delete()) {
                        throw new DocumentAlreadyExistsEngineException(shardId, create.type(), create.id());
                    }
                } else if (currentVersion != -1) {
                    // its not deleted, its already there
                    throw new DocumentAlreadyExistsEngineException(shardId, create.type(), create.id());
                }

                uidField.version(updatedVersion);
                create.version(updatedVersion);

                if (create.docs().size() > 1) {
                    writer.addDocuments(create.docs(), create.analyzer());
                } else {
View Full Code Here

Examples of org.elasticsearch.common.lucene.uid.UidField

        }
    }

    private void innerIndex(Index index, IndexWriter writer) throws IOException {
        synchronized (dirtyLock(index.uid())) {
            UidField uidField = index.uidField();
            if (index.origin() == Operation.Origin.RECOVERY) {
                uidField.version(index.version());
                if (index.docs().size() > 1) {
                    writer.updateDocuments(index.uid(), index.docs(), index.analyzer());
                } else {
                    writer.updateDocument(index.uid(), index.docs().get(0), index.analyzer());
                }
                Translog.Location translogLocation = translog.add(new Translog.Index(index));
                // on recovery, we get the actual version we want to use
                if (index.version() != 0) {
                    versionMap.put(index.uid().text(), new VersionValue(index.version(), false, threadPool.estimatedTimeInMillis(), translogLocation));
                }
            } else {
                long currentVersion;
                VersionValue versionValue = versionMap.get(index.uid().text());
                if (versionValue == null) {
                    currentVersion = loadCurrentVersionFromIndex(index.uid());
                } else {
                    if (versionValue.delete() && (threadPool.estimatedTimeInMillis() - versionValue.time()) > gcDeletesInMillis) {
                        currentVersion = -1; // deleted, and GC
                    } else {
                        currentVersion = versionValue.version();
                    }
                }

                long updatedVersion;
                if (index.origin() == Operation.Origin.PRIMARY) {
                    if (index.versionType() == VersionType.INTERNAL) { // internal version type
                        long expectedVersion = index.version();
                        if (expectedVersion != 0 && currentVersion != -2) { // -2 means we don't have a version, so ignore...
                            // an explicit version is provided, see if there is a conflict
                            // if the current version is -1, means we did not find anything, and
                            // a version is provided, so we do expect to find a doc under that version
                            // this is important, since we don't allow to preset a version in order to handle deletes
                            if (currentVersion == -1) {
                                throw new VersionConflictEngineException(shardId, index.type(), index.id(), -1, expectedVersion);
                            } else if (expectedVersion != currentVersion) {
                                throw new VersionConflictEngineException(shardId, index.type(), index.id(), currentVersion, expectedVersion);
                            }
                        }
                        updatedVersion = currentVersion < 0 ? 1 : currentVersion + 1;
                    } else { // external version type
                        // an external version is provided, just check, if a local version exists, that its higher than it
                        // the actual version checking is one in an external system, and we just want to not index older versions
                        if (currentVersion >= 0) { // we can check!, its there
                            if (currentVersion >= index.version()) {
                                throw new VersionConflictEngineException(shardId, index.type(), index.id(), currentVersion, index.version());
                            }
                        }
                        updatedVersion = index.version();
                    }
                } else { // if (index.origin() == Operation.Origin.REPLICA) {
                    long expectedVersion = index.version();
                    if (currentVersion != -2) { // -2 means we don't have a version, so ignore...
                        // if it does not exists, and its considered the first index operation (replicas are 1 of)
                        // then nothing to do
                        if (!(currentVersion == -1 && index.version() == 1)) {
                            // with replicas, we only check for previous version, we allow to set a future version
                            if (expectedVersion <= currentVersion) {
                                throw new VersionConflictEngineException(shardId, index.type(), index.id(), currentVersion, expectedVersion);
                            }
                        }
                    }
                    // replicas already hold the "future" version
                    updatedVersion = index.version();
                }

                uidField.version(updatedVersion);
                index.version(updatedVersion);

                if (currentVersion == -1) {
                    // document does not exists, we can optimize for create
                    if (index.docs().size() > 1) {
View Full Code Here

Examples of org.elasticsearch.common.lucene.uid.UidField

        long LIMIT = startUid + INDEX_COUNT;
        StopWatch watch = new StopWatch().start();
        System.out.println("Indexing " + INDEX_COUNT + " docs...");
        for (long i = startUid; i < LIMIT; i++) {
            Document doc = new Document();
            doc.add(new UidField("_uid", Long.toString(i), i));
            writer.addDocument(doc);
        }
        System.out.println("Done indexing, took " + watch.stop().lastTaskTime());

        final IndexReader reader = IndexReader.open(writer, true);
View Full Code Here

Examples of org.elasticsearch.common.lucene.uid.UidField

    public static Fieldable uidField(String value) {
        return uidField(value, 0);
    }

    public static Fieldable uidField(String value, long version) {
        return new UidField("_uid", value, version);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.