Examples of ParsedDocument


Examples of org.elasticsearch.index.mapper.ParsedDocument

        for (String contentItem : contentItems) {
            int id = idGenerator.incrementAndGet();
            String sId = Integer.toString(id);
            Document doc = doc().add(field("_id", sId))
                    .add(field("content", contentItem)).build();
            ParsedDocument pDoc = new ParsedDocument(sId, sId, "type", null, doc, Lucene.STANDARD_ANALYZER, TRANSLOG_PAYLOAD, false);
            if (create) {
                engine.create(new Engine.Create(null, new Term("_id", sId), pDoc));
            } else {
                engine.index(new Engine.Index(null, new Term("_id", sId), pDoc));
            }
View Full Code Here

Examples of org.elasticsearch.index.mapper.ParsedDocument

                for (int i = 0; i < writerIterations; i++) {
                    int id = idGenerator.incrementAndGet();
                    String sId = Integer.toString(id);
                    Document doc = doc().add(field("_id", sId))
                            .add(field("content", content(id))).build();
                    ParsedDocument pDoc = new ParsedDocument(sId, sId, "type", null, doc, Lucene.STANDARD_ANALYZER, TRANSLOG_PAYLOAD, false);
                    if (create) {
                        engine.create(new Engine.Create(null, new Term("_id", sId), pDoc));
                    } else {
                        engine.index(new Engine.Index(null, new Term("_id", sId), pDoc));
                    }
View Full Code Here

Examples of org.elasticsearch.index.mapper.ParsedDocument

    @Test public void testSegments() throws Exception {
        List<Segment> segments = engine.segments();
        assertThat(segments.isEmpty(), equalTo(true));

        // create a doc and refresh
        ParsedDocument doc = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).add(field("value", "test")).add(field(SourceFieldMapper.NAME, B_1, Field.Store.YES)).build(), Lucene.STANDARD_ANALYZER, B_1, false);
        engine.create(new Engine.Create(null, newUid("1"), doc));

        ParsedDocument doc2 = new ParsedDocument("2", "2", "test", null, doc().add(uidField("2")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_2, false);
        engine.create(new Engine.Create(null, newUid("2"), doc2));
        engine.refresh(new Engine.Refresh(true));

        segments = engine.segments();
        assertThat(segments.size(), equalTo(1));
        assertThat(segments.get(0).committed(), equalTo(false));
        assertThat(segments.get(0).search(), equalTo(true));
        assertThat(segments.get(0).numDocs(), equalTo(2));
        assertThat(segments.get(0).deletedDocs(), equalTo(0));

        engine.flush(new Engine.Flush());

        segments = engine.segments();
        assertThat(segments.size(), equalTo(1));
        assertThat(segments.get(0).committed(), equalTo(true));
        assertThat(segments.get(0).search(), equalTo(true));
        assertThat(segments.get(0).numDocs(), equalTo(2));
        assertThat(segments.get(0).deletedDocs(), equalTo(0));


        ParsedDocument doc3 = new ParsedDocument("3", "3", "test", null, doc().add(uidField("3")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_3, false);
        engine.create(new Engine.Create(null, newUid("3"), doc3));
        engine.refresh(new Engine.Refresh(true));

        segments = engine.segments();
        assertThat(segments.size(), equalTo(2));
View Full Code Here

Examples of org.elasticsearch.index.mapper.ParsedDocument

        Engine.Searcher searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(0));
        searchResult.release();

        // create a document
        ParsedDocument doc = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).add(field("value", "test")).add(field(SourceFieldMapper.NAME, B_1, Field.Store.YES)).build(), Lucene.STANDARD_ANALYZER, B_1, false);
        engine.create(new Engine.Create(null, newUid("1"), doc));

        // its not there...
        searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(0));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0));
        searchResult.release();

        // but, we can still get it (in realtime)
        Engine.GetResult getResult = engine.get(new Engine.Get(true, newUid("1")));
        assertThat(getResult.exists(), equalTo(true));
        assertThat(getResult.source(), equalTo(new BytesHolder(B_1)));
        assertThat(getResult.docIdAndVersion(), nullValue());

        // but, not there non realtime
        getResult = engine.get(new Engine.Get(false, newUid("1")));
        assertThat(getResult.exists(), equalTo(false));

        // refresh and it should be there
        engine.refresh(new Engine.Refresh(true));

        // now its there...
        searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(1));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 1));
        searchResult.release();

        // also in non realtime
        getResult = engine.get(new Engine.Get(false, newUid("1")));
        assertThat(getResult.exists(), equalTo(true));
        assertThat(getResult.docIdAndVersion(), notNullValue());

        // now do an update
        doc = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).add(field("value", "test1")).add(field(SourceFieldMapper.NAME, B_2, Field.Store.YES)).build(), Lucene.STANDARD_ANALYZER, B_2, false);
        engine.index(new Engine.Index(null, newUid("1"), doc));

        // its not updated yet...
        searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(1));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 1));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 0));
        searchResult.release();

        // but, we can still get it (in realtime)
        getResult = engine.get(new Engine.Get(true, newUid("1")));
        assertThat(getResult.exists(), equalTo(true));
        assertThat(getResult.source(), equalTo(new BytesHolder(B_2)));
        assertThat(getResult.docIdAndVersion(), nullValue());

        // refresh and it should be updated
        engine.refresh(new Engine.Refresh(true));

        searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(1));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 1));
        searchResult.release();

        // now delete
        engine.delete(new Engine.Delete("test", "1", newUid("1")));

        // its not deleted yet
        searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(1));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 1));
        searchResult.release();

        // but, get should not see it (in realtime)
        getResult = engine.get(new Engine.Get(true, newUid("1")));
        assertThat(getResult.exists(), equalTo(false));

        // refresh and it should be deleted
        engine.refresh(new Engine.Refresh(true));

        searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(0));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 0));
        searchResult.release();

        // add it back
        doc = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).add(field("value", "test")).add(field(SourceFieldMapper.NAME, B_1, Field.Store.YES)).build(), Lucene.STANDARD_ANALYZER, B_1, false);
        engine.create(new Engine.Create(null, newUid("1"), doc));

        // its not there...
        searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(0));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 0));
        searchResult.release();

        // refresh and it should be there
        engine.refresh(new Engine.Refresh(true));

        // now its there...
        searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(1));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 1));
        assertThat(searchResult, engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 0));
        searchResult.release();

        // now flush
        engine.flush(new Engine.Flush());

        // and, verify get (in real time)
        getResult = engine.get(new Engine.Get(true, newUid("1")));
        assertThat(getResult.exists(), equalTo(true));
        assertThat(getResult.source(), nullValue());
        assertThat(getResult.docIdAndVersion(), notNullValue());


        // make sure we can still work with the engine
        // now do an update
        doc = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).add(field("value", "test1")).build(), Lucene.STANDARD_ANALYZER, B_1, false);
        engine.index(new Engine.Index(null, newUid("1"), doc));

        // its not updated yet...
        searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(1));
View Full Code Here

Examples of org.elasticsearch.index.mapper.ParsedDocument

        Engine.Searcher searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(0));
        searchResult.release();

        // create a document
        ParsedDocument doc = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_1, false);
        engine.create(new Engine.Create(null, newUid("1"), doc));

        // its not there...
        searchResult = engine.searcher();
        assertThat(searchResult, engineSearcherTotalHits(0));
View Full Code Here

Examples of org.elasticsearch.index.mapper.ParsedDocument

        searchResult.release();
    }

    @Test public void testSimpleSnapshot() throws Exception {
        // create a document
        ParsedDocument doc1 = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_1, false);
        engine.create(new Engine.Create(null, newUid("1"), doc1));

        final ExecutorService executorService = Executors.newCachedThreadPool();

        engine.snapshot(new Engine.SnapshotHandler<Void>() {
            @Override public Void snapshot(final SnapshotIndexCommit snapshotIndexCommit1, final Translog.Snapshot translogSnapshot1) {
                assertThat(snapshotIndexCommit1, snapshotIndexCommitExists());
                assertThat(translogSnapshot1.hasNext(), equalTo(true));
                Translog.Create create1 = (Translog.Create) translogSnapshot1.next();
                assertThat(create1.source(), equalTo(B_1));
                assertThat(translogSnapshot1.hasNext(), equalTo(false));

                Future<Object> future = executorService.submit(new Callable<Object>() {
                    @Override public Object call() throws Exception {
                        engine.flush(new Engine.Flush());
                        ParsedDocument doc2 = new ParsedDocument("2", "2", "test", null, doc().add(uidField("2")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_2, false);
                        engine.create(new Engine.Create(null, newUid("2"), doc2));
                        engine.flush(new Engine.Flush());
                        ParsedDocument doc3 = new ParsedDocument("3", "3", "test", null, doc().add(uidField("3")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_3, false);
                        engine.create(new Engine.Create(null, newUid("3"), doc3));
                        return null;
                    }
                });
View Full Code Here

Examples of org.elasticsearch.index.mapper.ParsedDocument

        engine.close();
    }

    @Test public void testSimpleRecover() throws Exception {
        ParsedDocument doc = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_1, false);
        engine.create(new Engine.Create(null, newUid("1"), doc));
        engine.flush(new Engine.Flush());

        engine.recover(new Engine.RecoveryHandler() {
            @Override public void phase1(SnapshotIndexCommit snapshot) throws EngineException {
View Full Code Here

Examples of org.elasticsearch.index.mapper.ParsedDocument

        engine.flush(new Engine.Flush());
        engine.close();
    }

    @Test public void testRecoverWithOperationsBetweenPhase1AndPhase2() throws Exception {
        ParsedDocument doc1 = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_1, false);
        engine.create(new Engine.Create(null, newUid("1"), doc1));
        engine.flush(new Engine.Flush());
        ParsedDocument doc2 = new ParsedDocument("2", "2", "test", null, doc().add(uidField("2")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_2, false);
        engine.create(new Engine.Create(null, newUid("2"), doc2));

        engine.recover(new Engine.RecoveryHandler() {
            @Override public void phase1(SnapshotIndexCommit snapshot) throws EngineException {
            }
View Full Code Here

Examples of org.elasticsearch.index.mapper.ParsedDocument

        engine.flush(new Engine.Flush());
        engine.close();
    }

    @Test public void testRecoverWithOperationsBetweenPhase1AndPhase2AndPhase3() throws Exception {
        ParsedDocument doc1 = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_1, false);
        engine.create(new Engine.Create(null, newUid("1"), doc1));
        engine.flush(new Engine.Flush());
        ParsedDocument doc2 = new ParsedDocument("2", "2", "test", null, doc().add(uidField("2")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_2, false);
        engine.create(new Engine.Create(null, newUid("2"), doc2));

        engine.recover(new Engine.RecoveryHandler() {
            @Override public void phase1(SnapshotIndexCommit snapshot) throws EngineException {
            }

            @Override public void phase2(Translog.Snapshot snapshot) throws EngineException {
                assertThat(snapshot.hasNext(), equalTo(true));
                Translog.Create create = (Translog.Create) snapshot.next();
                assertThat(snapshot.hasNext(), equalTo(false));
                assertThat(create.source(), equalTo(B_2));

                // add for phase3
                ParsedDocument doc3 = new ParsedDocument("3", "3", "test", null, doc().add(uidField("3")).add(field("value", "test")).build(), Lucene.STANDARD_ANALYZER, B_3, false);
                engine.create(new Engine.Create(null, newUid("3"), doc3));
            }

            @Override public void phase3(Translog.Snapshot snapshot) throws EngineException {
                assertThat(snapshot.hasNext(), equalTo(true));
View Full Code Here

Examples of org.elasticsearch.index.mapper.ParsedDocument

        engine.flush(new Engine.Flush());
        engine.close();
    }

    @Test public void testVersioningNewCreate() {
        ParsedDocument doc = new ParsedDocument("1", "1", "test", null, doc().add(uidField("1")).build(), Lucene.STANDARD_ANALYZER, B_1, false);
        Engine.Create create = new Engine.Create(null, newUid("1"), doc);
        engine.create(create);
        assertThat(create.version(), equalTo(1l));

        create = new Engine.Create(null, newUid("1"), doc).version(create.version()).origin(REPLICA);
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.