Search in sources :

Example 6 with NumericDocValuesField

use of org.apache.lucene.document.NumericDocValuesField in project elasticsearch by elastic.

the class VersionsTests method testNestedDocuments.

public void testNestedDocuments() throws IOException {
    Directory dir = newDirectory();
    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Lucene.STANDARD_ANALYZER));
    List<Document> docs = new ArrayList<>();
    for (int i = 0; i < 4; ++i) {
        // Nested
        Document doc = new Document();
        doc.add(new Field(UidFieldMapper.NAME, "1", UidFieldMapper.Defaults.NESTED_FIELD_TYPE));
        docs.add(doc);
    }
    // Root
    Document doc = new Document();
    doc.add(new Field(UidFieldMapper.NAME, "1", UidFieldMapper.Defaults.FIELD_TYPE));
    NumericDocValuesField version = new NumericDocValuesField(VersionFieldMapper.NAME, 5L);
    doc.add(version);
    docs.add(doc);
    writer.updateDocuments(new Term(UidFieldMapper.NAME, "1"), docs);
    DirectoryReader directoryReader = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(writer), new ShardId("foo", "_na_", 1));
    assertThat(Versions.loadVersion(directoryReader, new Term(UidFieldMapper.NAME, "1")), equalTo(5L));
    assertThat(Versions.loadDocIdAndVersion(directoryReader, new Term(UidFieldMapper.NAME, "1")).version, equalTo(5L));
    version.setLongValue(6L);
    writer.updateDocuments(new Term(UidFieldMapper.NAME, "1"), docs);
    version.setLongValue(7L);
    writer.updateDocuments(new Term(UidFieldMapper.NAME, "1"), docs);
    directoryReader = reopen(directoryReader);
    assertThat(Versions.loadVersion(directoryReader, new Term(UidFieldMapper.NAME, "1")), equalTo(7L));
    assertThat(Versions.loadDocIdAndVersion(directoryReader, new Term(UidFieldMapper.NAME, "1")).version, equalTo(7L));
    writer.deleteDocuments(new Term(UidFieldMapper.NAME, "1"));
    directoryReader = reopen(directoryReader);
    assertThat(Versions.loadVersion(directoryReader, new Term(UidFieldMapper.NAME, "1")), equalTo(Versions.NOT_FOUND));
    assertThat(Versions.loadDocIdAndVersion(directoryReader, new Term(UidFieldMapper.NAME, "1")), nullValue());
    directoryReader.close();
    writer.close();
    dir.close();
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) Field(org.apache.lucene.document.Field) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) IndexWriter(org.apache.lucene.index.IndexWriter) DirectoryReader(org.apache.lucene.index.DirectoryReader) ElasticsearchDirectoryReader(org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader) ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 7 with NumericDocValuesField

use of org.apache.lucene.document.NumericDocValuesField in project elasticsearch by elastic.

the class ShadowEngineTests method testParsedDocument.

private ParsedDocument testParsedDocument(String id, String type, String routing, ParseContext.Document document, BytesReference source, Mapping mappingsUpdate) {
    Field uidField = new Field("_uid", Uid.createUid(type, id), UidFieldMapper.Defaults.FIELD_TYPE);
    Field versionField = new NumericDocValuesField("_version", 0);
    SeqNoFieldMapper.SequenceID seqID = SeqNoFieldMapper.SequenceID.emptySeqID();
    document.add(uidField);
    document.add(versionField);
    document.add(seqID.seqNo);
    document.add(seqID.seqNoDocValue);
    document.add(seqID.primaryTerm);
    // so that points report memory/disk usage
    document.add(new LongPoint("point_field", 42));
    return new ParsedDocument(versionField, seqID, id, type, routing, Arrays.asList(document), source, XContentType.JSON, mappingsUpdate);
}
Also used : SeqNoFieldMapper(org.elasticsearch.index.mapper.SeqNoFieldMapper) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) LongPoint(org.apache.lucene.document.LongPoint)

Example 8 with NumericDocValuesField

use of org.apache.lucene.document.NumericDocValuesField in project elasticsearch by elastic.

the class InternalEngineTests method testParsedDocument.

private static ParsedDocument testParsedDocument(String id, String type, String routing, Document document, BytesReference source, Mapping mappingUpdate) {
    Field uidField = new Field("_uid", Uid.createUid(type, id), UidFieldMapper.Defaults.FIELD_TYPE);
    Field versionField = new NumericDocValuesField("_version", 0);
    SeqNoFieldMapper.SequenceID seqID = SeqNoFieldMapper.SequenceID.emptySeqID();
    document.add(uidField);
    document.add(versionField);
    document.add(seqID.seqNo);
    document.add(seqID.seqNoDocValue);
    document.add(seqID.primaryTerm);
    return new ParsedDocument(versionField, seqID, id, type, routing, Arrays.asList(document), source, XContentType.JSON, mappingUpdate);
}
Also used : SeqNoFieldMapper(org.elasticsearch.index.mapper.SeqNoFieldMapper) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) TextField(org.apache.lucene.document.TextField) IndexableField(org.apache.lucene.index.IndexableField) StoredField(org.apache.lucene.document.StoredField) Field(org.apache.lucene.document.Field) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument)

Example 9 with NumericDocValuesField

use of org.apache.lucene.document.NumericDocValuesField in project elasticsearch by elastic.

the class RefreshListenersTests method index.

private Engine.IndexResult index(String id, String testFieldValue) throws IOException {
    String type = "test";
    String uid = type + ":" + id;
    Document document = new Document();
    document.add(new TextField("test", testFieldValue, Field.Store.YES));
    Field uidField = new Field("_uid", Uid.createUid(type, id), UidFieldMapper.Defaults.FIELD_TYPE);
    Field versionField = new NumericDocValuesField("_version", Versions.MATCH_ANY);
    SeqNoFieldMapper.SequenceID seqID = SeqNoFieldMapper.SequenceID.emptySeqID();
    document.add(uidField);
    document.add(versionField);
    document.add(seqID.seqNo);
    document.add(seqID.seqNoDocValue);
    document.add(seqID.primaryTerm);
    BytesReference source = new BytesArray(new byte[] { 1 });
    ParsedDocument doc = new ParsedDocument(versionField, seqID, id, type, null, Arrays.asList(document), source, XContentType.JSON, null);
    Engine.Index index = new Engine.Index(new Term("_uid", doc.uid()), doc);
    return engine.index(index);
}
Also used : SeqNoFieldMapper(org.elasticsearch.index.mapper.SeqNoFieldMapper) BytesReference(org.elasticsearch.common.bytes.BytesReference) BytesArray(org.elasticsearch.common.bytes.BytesArray) Index(org.elasticsearch.index.Index) Term(org.apache.lucene.index.Term) Document(org.elasticsearch.index.mapper.ParseContext.Document) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) TextField(org.apache.lucene.document.TextField) Engine(org.elasticsearch.index.engine.Engine) InternalEngine(org.elasticsearch.index.engine.InternalEngine)

Example 10 with NumericDocValuesField

use of org.apache.lucene.document.NumericDocValuesField in project elasticsearch by elastic.

the class TranslogTests method testTranslogOpSerialization.

public void testTranslogOpSerialization() throws Exception {
    BytesReference B_1 = new BytesArray(new byte[] { 1 });
    SeqNoFieldMapper.SequenceID seqID = SeqNoFieldMapper.SequenceID.emptySeqID();
    assert Version.CURRENT.major <= 6 : "Using UNASSIGNED_SEQ_NO can be removed in 7.0, because 6.0+ nodes have actual sequence numbers";
    long randomSeqNum = randomBoolean() ? SequenceNumbersService.UNASSIGNED_SEQ_NO : randomNonNegativeLong();
    long randomPrimaryTerm = randomBoolean() ? 0 : randomNonNegativeLong();
    seqID.seqNo.setLongValue(randomSeqNum);
    seqID.seqNoDocValue.setLongValue(randomSeqNum);
    seqID.primaryTerm.setLongValue(randomPrimaryTerm);
    Field uidField = new Field("_uid", Uid.createUid("test", "1"), UidFieldMapper.Defaults.FIELD_TYPE);
    Field versionField = new NumericDocValuesField("_version", 1);
    Document document = new Document();
    document.add(new TextField("value", "test", Field.Store.YES));
    document.add(uidField);
    document.add(versionField);
    document.add(seqID.seqNo);
    document.add(seqID.seqNoDocValue);
    document.add(seqID.primaryTerm);
    ParsedDocument doc = new ParsedDocument(versionField, seqID, "1", "type", null, Arrays.asList(document), B_1, XContentType.JSON, null);
    Engine.Index eIndex = new Engine.Index(newUid(doc), doc, randomSeqNum, randomPrimaryTerm, 1, VersionType.INTERNAL, Origin.PRIMARY, 0, 0, false);
    Engine.IndexResult eIndexResult = new Engine.IndexResult(1, randomSeqNum, true);
    Translog.Index index = new Translog.Index(eIndex, eIndexResult);
    BytesStreamOutput out = new BytesStreamOutput();
    index.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    Translog.Index serializedIndex = new Translog.Index(in);
    assertEquals(index, serializedIndex);
    Engine.Delete eDelete = new Engine.Delete(doc.type(), doc.id(), newUid(doc), randomSeqNum, randomPrimaryTerm, 2, VersionType.INTERNAL, Origin.PRIMARY, 0);
    Engine.DeleteResult eDeleteResult = new Engine.DeleteResult(2, randomSeqNum, true);
    Translog.Delete delete = new Translog.Delete(eDelete, eDeleteResult);
    out = new BytesStreamOutput();
    delete.writeTo(out);
    in = out.bytes().streamInput();
    Translog.Delete serializedDelete = new Translog.Delete(in);
    assertEquals(delete, serializedDelete);
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) SeqNoFieldMapper(org.elasticsearch.index.mapper.SeqNoFieldMapper) BytesArray(org.elasticsearch.common.bytes.BytesArray) Document(org.elasticsearch.index.mapper.ParseContext.Document) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TextField(org.apache.lucene.document.TextField) Engine(org.elasticsearch.index.engine.Engine)

Aggregations

NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)296 Document (org.apache.lucene.document.Document)268 Directory (org.apache.lucene.store.Directory)206 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)132 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)103 StringField (org.apache.lucene.document.StringField)92 BytesRef (org.apache.lucene.util.BytesRef)85 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)75 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)69 IndexReader (org.apache.lucene.index.IndexReader)54 Field (org.apache.lucene.document.Field)51 IndexSearcher (org.apache.lucene.search.IndexSearcher)49 BinaryDocValuesField (org.apache.lucene.document.BinaryDocValuesField)44 SortField (org.apache.lucene.search.SortField)42 TextField (org.apache.lucene.document.TextField)41 Sort (org.apache.lucene.search.Sort)41 Term (org.apache.lucene.index.Term)38 IntPoint (org.apache.lucene.document.IntPoint)36 SortedNumericSortField (org.apache.lucene.search.SortedNumericSortField)36 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)34