Package org.elasticsearch.index.mapper

Examples of org.elasticsearch.index.mapper.DocumentMapperParser


public class SimpleAttachmentMapperTests {

    private DocumentMapperParser mapperParser;

    @BeforeClass public void setupMapperParser() {
        mapperParser = new DocumentMapperParser(new Index("test"), new AnalysisService(new Index("test")));
        mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
    }
View Full Code Here


        assertThat(f.name(), equalTo("object1.multi1.string"));
        assertThat(f.stringValue(), equalTo("2010-01-01"));
    }

    @Test public void testBuildThenParse() throws Exception {
        DocumentMapperParser mapperParser = MapperTests.newParser();

        DocumentMapper builderDocMapper = doc("test", rootObject("person").add(
                multiField("name")
                        .add(stringField("name").store(Field.Store.YES))
                        .add(stringField("indexed").index(Field.Index.ANALYZED))
                        .add(stringField("not_indexed").index(Field.Index.NO).store(Field.Store.YES))
        )).build(mapperParser);
        builderDocMapper.refreshSource();

        String builtMapping = builderDocMapper.mappingSource().string();
//        System.out.println(builtMapping);
        // reparse it
        DocumentMapper docMapper = mapperParser.parse(builtMapping);


        byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json");
        Document doc = docMapper.parse(json).rootDoc();
View Full Code Here

@Test
public class JavaMultiFieldMergeTests {

    @Test public void testMergeMultiField() throws Exception {
        String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping1.json");
        DocumentMapperParser parser = MapperTests.newParser();

        DocumentMapper docMapper = parser.parse(mapping);

        assertThat(docMapper.mappers().fullName("name").mapper().indexed(), equalTo(true));
        assertThat(docMapper.mappers().fullName("name.indexed"), nullValue());

        byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-data.json");
        Document doc = docMapper.parse(json).rootDoc();
        Fieldable f = doc.getFieldable("name");
        assertThat(f, notNullValue());
        f = doc.getFieldable("name.indexed");
        assertThat(f, nullValue());


        mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping2.json");
        DocumentMapper docMapper2 = parser.parse(mapping);

        DocumentMapper.MergeResult mergeResult = docMapper.merge(docMapper2, mergeFlags().simulate(true));
        assertThat(Arrays.toString(mergeResult.conflicts()), mergeResult.hasConflicts(), equalTo(false));

        docMapper.merge(docMapper2, mergeFlags().simulate(false));

        assertThat(docMapper.mappers().name("name").mapper().indexed(), equalTo(true));

        assertThat(docMapper.mappers().fullName("name").mapper().indexed(), equalTo(true));
        assertThat(docMapper.mappers().fullName("name.indexed").mapper(), notNullValue());
        assertThat(docMapper.mappers().fullName("name.not_indexed").mapper(), notNullValue());
        assertThat(docMapper.mappers().fullName("name.not_indexed2"), nullValue());
        assertThat(docMapper.mappers().fullName("name.not_indexed3"), nullValue());

        json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-data.json");
        doc = docMapper.parse(json).rootDoc();
        f = doc.getFieldable("name");
        assertThat(f, notNullValue());
        f = doc.getFieldable("name.indexed");
        assertThat(f, notNullValue());

        mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping3.json");
        DocumentMapper docMapper3 = parser.parse(mapping);

        mergeResult = docMapper.merge(docMapper3, mergeFlags().simulate(true));
        assertThat(Arrays.toString(mergeResult.conflicts()), mergeResult.hasConflicts(), equalTo(false));

        docMapper.merge(docMapper3, mergeFlags().simulate(false));

        assertThat(docMapper.mappers().name("name").mapper().indexed(), equalTo(true));

        assertThat(docMapper.mappers().fullName("name").mapper().indexed(), equalTo(true));
        assertThat(docMapper.mappers().fullName("name.indexed").mapper(), notNullValue());
        assertThat(docMapper.mappers().fullName("name.not_indexed").mapper(), notNullValue());
        assertThat(docMapper.mappers().fullName("name.not_indexed2").mapper(), notNullValue());
        assertThat(docMapper.mappers().fullName("name.not_indexed3"), nullValue());


        mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping4.json");
        DocumentMapper docMapper4 = parser.parse(mapping);

        mergeResult = docMapper.merge(docMapper4, mergeFlags().simulate(true));
        assertThat(Arrays.toString(mergeResult.conflicts()), mergeResult.hasConflicts(), equalTo(false));

        docMapper.merge(docMapper4, mergeFlags().simulate(false));
View Full Code Here

* @author kimchy
*/
public class SimpleMapperTests {

    @Test public void testSimpleMapper() throws Exception {
        DocumentMapperParser mapperParser = MapperTests.newParser();
        DocumentMapper docMapper = doc("test",
                rootObject("person")
                        .add(object("name").add(stringField("first").store(YES).index(Field.Index.NO)))
        ).sourceField(source()).build(mapperParser);

View Full Code Here

* Test for https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/38
*/
public class MetadataMapperTest extends ElasticsearchTestCase {

    protected void checkMeta(String filename, Settings settings, Long expectedDate, Long expectedLength) throws IOException {
        DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(settings);
        mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());

        String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
        DocumentMapper docMapper = mapperParser.parse(mapping);
        byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/" + filename);

        BytesReference json = jsonBuilder()
                .startObject()
                    .field("_id", 1)
View Full Code Here

    public static DocumentMapperParser newMapperParser(Settings settings) {
        Settings forcedSettings = ImmutableSettings.builder()
                .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
                .put(settings)
                .build();
        return new DocumentMapperParser(new Index("test"), forcedSettings, MapperTestUtils.newAnalysisService(forcedSettings), null, null, null, null);
    }
View Full Code Here

    public void setupMapperParser() throws IOException {
        setupMapperParser(true);
    }

    public void setupMapperParser(boolean langDetect) throws IOException {
        DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(
                ImmutableSettings.settingsBuilder().put("index.mapping.attachment.detect_language", langDetect).build());
        mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
        String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/language/language-mapping.json");
        docMapper = mapperParser.parse(mapping);

        assertThat(docMapper.mappers().fullName("file.language").mapper(), instanceOf(StringFieldMapper.class));
    }
View Full Code Here

        protected TikaTest(Terminal terminal, String url, Integer size, String base64text) throws IOException {
            super(terminal);
            this.size = size;
            this.url = url;
            this.base64text = base64text;
            DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
            mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());

            String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
            docMapper = mapperParser.parse(mapping);
        }
View Full Code Here

*/
public class EncryptedDocMapperTest extends ElasticsearchTestCase {

    @Test
    public void testMultipleDocsEncryptedLast() throws IOException {
        DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
        mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());

        String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
        DocumentMapper docMapper = mapperParser.parse(mapping);
        byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/htmlWithValidDateMeta.html");
        byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/encrypted.pdf");

        BytesReference json = jsonBuilder()
                .startObject()
View Full Code Here

        assertThat(doc.getField(docMapper.mappers().smartName("file2.content_length").mapper().names().indexName()), nullValue());
    }

    @Test
    public void testMultipleDocsEncryptedFirst() throws IOException {
        DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
        mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());

        String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
        DocumentMapper docMapper = mapperParser.parse(mapping);
        byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/htmlWithValidDateMeta.html");
        byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/encrypted.pdf");

        BytesReference json = jsonBuilder()
                .startObject()
View Full Code Here

TOP

Related Classes of org.elasticsearch.index.mapper.DocumentMapperParser

Copyright © 2018 www.massapicom. 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.