当前位置: 首页>>代码示例>>Java>>正文


Java Document类代码示例

本文整理汇总了Java中org.elasticsearch.index.mapper.ParseContext.Document的典型用法代码示例。如果您正苦于以下问题:Java Document类的具体用法?Java Document怎么用?Java Document使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Document类属于org.elasticsearch.index.mapper.ParseContext包,在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ParsedDocument

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
public ParsedDocument(Field version,
                      SeqNoFieldMapper.SequenceID seqID,
                      String id,
                      String type,
                      String routing,
                      List<Document> documents,
                      BytesReference source,
                      XContentType xContentType,
                      Mapping dynamicMappingsUpdate) {
    this.version = version;
    this.seqID = seqID;
    this.id = id;
    this.type = type;
    this.uid = Uid.createUidAsBytes(type, id);
    this.routing = routing;
    this.documents = documents;
    this.source = source;
    this.dynamicMappingsUpdate = dynamicMappingsUpdate;
    this.xContentType = xContentType;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:ParsedDocument.java

示例2: parseContext

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
@Override
public Set<CharSequence> parseContext(Document document) {
    Set<CharSequence> values = null;
    if (fieldName != null) {
        IndexableField[] fields = document.getFields(fieldName);
        values = new HashSet<>(fields.length);
        for (IndexableField field : fields) {
            values.add(field.stringValue());
        }
    }
    return (values == null) ? Collections.<CharSequence>emptySet() : values;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:CategoryContextMapping.java

示例3: postParse

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
@Override
public void postParse(ParseContext context) throws IOException {
    // In the case of nested docs, let's fill nested docs with version=1 so that Lucene doesn't write a Bitset for documents
    // that don't have the field. This is consistent with the default value for efficiency.
    for (int i = 1; i < context.docs().size(); i++) {
        final Document doc = context.docs().get(i);
        doc.add(new NumericDocValuesField(NAME, 1L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:VersionFieldMapper.java

示例4: postParse

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
@Override
public void postParse(ParseContext context) throws IOException {
    // In the case of nested docs, let's fill nested docs with seqNo=1 and
    // primaryTerm=0 so that Lucene doesn't write a Bitset for documents
    // that don't have the field. This is consistent with the default value
    // for efficiency.
    for (int i = 1; i < context.docs().size(); i++) {
        final Document doc = context.docs().get(i);
        doc.add(new LongPoint(NAME, 1));
        doc.add(new SortedNumericDocValuesField(NAME, 1L));
        doc.add(new NumericDocValuesField(PRIMARY_TERM_NAME, 0L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:SeqNoFieldMapper.java

示例5: testParsedDocument

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:InternalEngineTests.java

示例6: testCopyToFieldsInnerObjectParsing

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
public void testCopyToFieldsInnerObjectParsing() throws Exception {
    String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties")

            .startObject("copy_test")
            .field("type", "text")
            .field("copy_to", "very.inner.field")
            .endObject()

            .startObject("very")
            .field("type", "object")
            .startObject("properties")
            .startObject("inner")
            .field("type", "object")
            .endObject()
            .endObject()
            .endObject()

            .endObject().endObject().endObject().string();

    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));

    BytesReference json = jsonBuilder().startObject()
            .field("copy_test", "foo")
            .startObject("foo").startObject("bar").field("baz", "zoo").endObject().endObject()
            .endObject().bytes();

    ParseContext.Document doc = docMapper.parse("test", "type1", "1", json).rootDoc();
    assertThat(doc.getFields("copy_test").length, equalTo(1));
    assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo"));

    assertThat(doc.getFields("very.inner.field").length, equalTo(1));
    assertThat(doc.getFields("very.inner.field")[0].stringValue(), equalTo("foo"));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:CopyToMapperTests.java

示例7: testCopyToDynamicInnerObjectParsing

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
public void testCopyToDynamicInnerObjectParsing() throws Exception {
    String mapping = jsonBuilder().startObject().startObject("type1")
        .startObject("properties")
            .startObject("copy_test")
                .field("type", "text")
                .field("copy_to", "very.inner.field")
            .endObject()
        .endObject()
        .endObject().endObject().string();

    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));

    BytesReference json = jsonBuilder().startObject()
            .field("copy_test", "foo")
            .field("new_field", "bar")
            .endObject().bytes();

    ParseContext.Document doc = docMapper.parse("test", "type1", "1", json).rootDoc();
    assertThat(doc.getFields("copy_test").length, equalTo(1));
    assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo"));

    assertThat(doc.getFields("very.inner.field").length, equalTo(1));
    assertThat(doc.getFields("very.inner.field")[0].stringValue(), equalTo("foo"));

    assertThat(doc.getFields("new_field").length, equalTo(1));
    assertThat(doc.getFields("new_field")[0].stringValue(), equalTo("bar"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:CopyToMapperTests.java

示例8: testCopyToDynamicInnerInnerObjectParsing

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
public void testCopyToDynamicInnerInnerObjectParsing() throws Exception {
    String mapping = jsonBuilder().startObject().startObject("type1")
        .startObject("properties")
            .startObject("copy_test")
                .field("type", "text")
                .field("copy_to", "very.far.inner.field")
            .endObject()
            .startObject("very")
                .field("type", "object")
                .startObject("properties")
                    .startObject("far")
                        .field("type", "object")
                    .endObject()
                .endObject()
            .endObject()
        .endObject()
        .endObject().endObject().string();

    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));

    BytesReference json = jsonBuilder().startObject()
        .field("copy_test", "foo")
        .field("new_field", "bar")
        .endObject().bytes();

    ParseContext.Document doc = docMapper.parse("test", "type1", "1", json).rootDoc();
    assertThat(doc.getFields("copy_test").length, equalTo(1));
    assertThat(doc.getFields("copy_test")[0].stringValue(), equalTo("foo"));

    assertThat(doc.getFields("very.far.inner.field").length, equalTo(1));
    assertThat(doc.getFields("very.far.inner.field")[0].stringValue(), equalTo("foo"));

    assertThat(doc.getFields("new_field").length, equalTo(1));
    assertThat(doc.getFields("new_field")[0].stringValue(), equalTo("bar"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:CopyToMapperTests.java

示例9: assertFieldValue

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
private void assertFieldValue(Document doc, String field, Number... expected) {
    IndexableField[] values = doc.getFields(field);
    if (values == null) {
        values = new IndexableField[0];
    }
    Number[] actual = new Number[values.length];
    for (int i = 0; i < values.length; ++i) {
        actual[i] = values[i].numericValue();
    }
    assertArrayEquals(expected, actual);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:CopyToMapperTests.java

示例10: testIsFieldWithinQuery

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
public void testIsFieldWithinQuery() throws IOException {
    Directory dir = newDirectory();
    IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null));
    long instant1 = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().parseDateTime("2015-10-12").getMillis();
    long instant2 = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().parseDateTime("2016-04-03").getMillis();
    Document doc = new Document();
    LongPoint field = new LongPoint("my_date", instant1);
    doc.add(field);
    w.addDocument(doc);
    field.setLongValue(instant2);
    w.addDocument(doc);
    DirectoryReader reader = DirectoryReader.open(w);
    DateFieldType ft = new DateFieldType();
    ft.setName("my_date");
    DateMathParser alternateFormat = new DateMathParser(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER);
    doTestIsFieldWithinQuery(ft, reader, null, null);
    doTestIsFieldWithinQuery(ft, reader, null, alternateFormat);
    doTestIsFieldWithinQuery(ft, reader, DateTimeZone.UTC, null);
    doTestIsFieldWithinQuery(ft, reader, DateTimeZone.UTC, alternateFormat);

    // Fields with no value indexed.
    DateFieldType ft2 = new DateFieldType();
    ft2.setName("my_date2");

    QueryRewriteContext context = new QueryRewriteContext(null, null, null, xContentRegistry(), null, null,
            () -> nowInMillis);
    assertEquals(Relation.DISJOINT, ft2.isFieldWithinQuery(reader, "2015-10-09", "2016-01-02", false, false, null, null, context));
    IOUtils.close(reader, w, dir);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:DateFieldTypeTests.java

示例11: testSimple

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
public void testSimple() throws Exception {
    String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-mapping.json");
    IndexService index = createIndex("test");
    client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get();
    DocumentMapper docMapper = index.mapperService().documentMapper("person");
    byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-data.json");
    ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", new BytesArray(json));
    client().admin().indices().preparePutMapping("test").setType("person")
        .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
    docMapper = index.mapperService().documentMapper("person");
    Document doc = parsedDoc.rootDoc();

    IndexableField f = doc.getField("name");
    assertThat(f.name(), equalTo("name"));
    assertThat(f.stringValue(), equalTo("top_level"));
    assertThat(f.fieldType().stored(), equalTo(false));

    FieldMapper fieldMapper = docMapper.mappers().getMapper("name");
    assertThat(fieldMapper.fieldType().stored(), equalTo(false));

    f = doc.getField("obj1.name");
    assertThat(f.name(), equalTo("obj1.name"));
    assertThat(f.fieldType().stored(), equalTo(true));

    fieldMapper = docMapper.mappers().getMapper("obj1.name");
    assertThat(fieldMapper.fieldType().stored(), equalTo(true));

    f = doc.getField("obj1.obj2.name");
    assertThat(f.name(), equalTo("obj1.obj2.name"));
    assertThat(f.fieldType().stored(), equalTo(false));

    fieldMapper = docMapper.mappers().getMapper("obj1.obj2.name");
    assertThat(fieldMapper.fieldType().stored(), equalTo(false));

    // verify more complex path_match expressions

    fieldMapper = docMapper.mappers().getMapper("obj3.obj4.prop1");
    assertNotNull(fieldMapper);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:PathMatchDynamicTemplateTests.java

示例12: testSimpleMapper

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
public void testSimpleMapper() throws Exception {
    IndexService indexService = createIndex("test");
    DocumentMapper docMapper = new DocumentMapper.Builder(
            new RootObjectMapper.Builder("person")
                    .add(new ObjectMapper.Builder("name").add(new TextFieldMapper.Builder("first").store(true).index(false))),
        indexService.mapperService()).build(indexService.mapperService());

    BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
    Document doc = docMapper.parse("test", "person", "1", json).rootDoc();

    assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay"));
    doc = docMapper.parse("test", "person", "1", json).rootDoc();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:DocumentParserTests.java

示例13: testParseToJsonAndParse

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
public void testParseToJsonAndParse() throws Exception {
    String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
    DocumentMapper docMapper = parser.parse("person", new CompressedXContent(mapping));
    String builtMapping = docMapper.mappingSource().string();
    // reparse it
    DocumentMapper builtDocMapper = parser.parse("person", new CompressedXContent(builtMapping));
    BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
    Document doc = builtDocMapper.parse("test", "person", "1", json).rootDoc();
    assertThat(doc.get(docMapper.uidMapper().fieldType().name()), equalTo(Uid.createUid("person", "1")));
    assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:DocumentParserTests.java

示例14: testSimpleParser

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
public void testSimpleParser() throws Exception {
    String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping));

    assertThat((String) docMapper.meta().get("param1"), equalTo("value1"));

    BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
    Document doc = docMapper.parse("test", "person", "1", json).rootDoc();
    assertThat(doc.get(docMapper.uidMapper().fieldType().name()), equalTo(Uid.createUid("person", "1")));
    assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:DocumentParserTests.java

示例15: testSimpleParserNoTypeNoId

import org.elasticsearch.index.mapper.ParseContext.Document; //导入依赖的package包/类
public void testSimpleParserNoTypeNoId() throws Exception {
    String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping));
    BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1-notype-noid.json"));
    Document doc = docMapper.parse("test", "person", "1", json).rootDoc();
    assertThat(doc.get(docMapper.uidMapper().fieldType().name()), equalTo(Uid.createUid("person", "1")));
    assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:DocumentParserTests.java


注:本文中的org.elasticsearch.index.mapper.ParseContext.Document类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。