Package org.elasticsearch.index.mapper

Examples of org.elasticsearch.index.mapper.DocumentMapperParser


        }
    }
   
    @Test
    public void testLevelDefaults() throws IOException {
        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
        {
            String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                    .startObject("properties").startObject("location")
                        .field("type", "geo_shape")
                        .field("tree", "quadtree")
                        .field("distance_error_pct", "0.5")
                    .endObject().endObject()
                    .endObject().endObject().string();

           
            DocumentMapper defaultMapper = parser.parse(mapping);
            FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
            assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

            GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
            PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

            assertThat(strategy.getDistErrPct(), equalTo(0.5));
            assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
            /* 50m is default */
            assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(50d)));
        }
       
        {
            String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                    .startObject("properties").startObject("location")
                        .field("type", "geo_shape")
                        .field("tree", "geohash")
                        .field("distance_error_pct", "0.5")
                    .endObject().endObject()
                    .endObject().endObject().string();

            DocumentMapper defaultMapper = parser.parse(mapping);
            FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
            assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

            GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
            PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();
View Full Code Here


*/
public class AnalyzerMapperTests extends ElasticsearchSingleNodeTest {

    @Test
    public void testAnalyzerMapping() throws Exception {
        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();

        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
                .startObject("_analyzer").field("path", "field_analyzer").endObject()
                .startObject("properties")
                .startObject("field1").field("type", "string").endObject()
                .startObject("field2").field("type", "string").field("analyzer", "simple").endObject()
                .endObject()
                .endObject().endObject().string();

        DocumentMapper documentMapper = parser.parse(mapping);

        ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
                .field("field_analyzer", "whitespace")
                .field("field1", "value1")
                .field("field2", "value2")
                .endObject().bytes());

        FieldNameAnalyzer analyzer = (FieldNameAnalyzer) doc.analyzer();
        assertThat(((NamedAnalyzer) analyzer.defaultAnalyzer()).name(), equalTo("whitespace"));
        assertThat(((NamedAnalyzer) analyzer.analyzers().get("field1")), nullValue());
        assertThat(((NamedAnalyzer) analyzer.analyzers().get("field2")).name(), equalTo("simple"));

        // check that it serializes and de-serializes correctly

        DocumentMapper reparsedMapper = parser.parse(documentMapper.mappingSource().string());

        doc = reparsedMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
                .field("field_analyzer", "whitespace")
                .field("field1", "value1")
                .field("field2", "value2")
View Full Code Here

    }


    @Test
    public void testAnalyzerMappingExplicit() throws Exception {
        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();

        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
                .startObject("_analyzer").field("path", "field_analyzer").endObject()
                .startObject("properties")
                .startObject("field_analyzer").field("type", "string").endObject()
                .startObject("field1").field("type", "string").endObject()
                .startObject("field2").field("type", "string").field("analyzer", "simple").endObject()
                .endObject()
                .endObject().endObject().string();

        DocumentMapper documentMapper = parser.parse(mapping);

        ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
                .field("field_analyzer", "whitespace")
                .field("field1", "value1")
                .field("field2", "value2")
                .endObject().bytes());

        FieldNameAnalyzer analyzer = (FieldNameAnalyzer) doc.analyzer();
        assertThat(((NamedAnalyzer) analyzer.defaultAnalyzer()).name(), equalTo("whitespace"));
        assertThat(((NamedAnalyzer) analyzer.analyzers().get("field1")), nullValue());
        assertThat(((NamedAnalyzer) analyzer.analyzers().get("field2")).name(), equalTo("simple"));

        // check that it serializes and de-serializes correctly

        DocumentMapper reparsedMapper = parser.parse(documentMapper.mappingSource().string());

        doc = reparsedMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
                .field("field_analyzer", "whitespace")
                .field("field1", "value1")
                .field("field2", "value2")
View Full Code Here

    public void testTypeLevel() throws Exception {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
                .startObject("_source").field("enabled", false).endObject()
                .endObject().endObject().string();

        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
        DocumentMapper mapper = parser.parse("type", mapping);
        assertThat(mapper.type(), equalTo("type"));
        assertThat(mapper.sourceMapper().enabled(), equalTo(false));

        mapper = parser.parse(mapping);
        assertThat(mapper.type(), equalTo("type"));
        assertThat(mapper.sourceMapper().enabled(), equalTo(false));
    }
View Full Code Here

        assertThat(((NamedAnalyzer) analyzer.analyzers().get("field2")).name(), equalTo("simple"));
    }

    @Test
    public void testAnalyzerMappingNotIndexedNorStored() throws Exception {
        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();

        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
                .startObject("_analyzer").field("path", "field_analyzer").endObject()
                .startObject("properties")
                .startObject("field_analyzer").field("type", "string").field("index", "no").field("store", "no").endObject()
                .startObject("field1").field("type", "string").endObject()
                .startObject("field2").field("type", "string").field("analyzer", "simple").endObject()
                .endObject()
                .endObject().endObject().string();

        DocumentMapper documentMapper = parser.parse(mapping);

        ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
                .field("field_analyzer", "whitespace")
                .field("field1", "value1")
                .field("field2", "value2")
                .endObject().bytes());

        FieldNameAnalyzer analyzer = (FieldNameAnalyzer) doc.analyzer();
        assertThat(((NamedAnalyzer) analyzer.defaultAnalyzer()).name(), equalTo("whitespace"));
        assertThat(((NamedAnalyzer) analyzer.analyzers().get("field1")), nullValue());
        assertThat(((NamedAnalyzer) analyzer.analyzers().get("field2")).name(), equalTo("simple"));

        // check that it serializes and de-serializes correctly

        DocumentMapper reparsedMapper = parser.parse(documentMapper.mappingSource().string());

        doc = reparsedMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
                .field("field_analyzer", "whitespace")
                .field("field1", "value1")
                .field("field2", "value2")
View Full Code Here

                            .field("type", "token_count")
                            .field("analyzer", "keyword")
                        .endObject()
                    .endObject()
                .endObject().endObject().string();
        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
        DocumentMapper stage1 = parser.parse(stage1Mapping);

        String stage2Mapping = XContentFactory.jsonBuilder().startObject()
                .startObject("person")
                    .startObject("properties")
                        .startObject("tc")
                            .field("type", "token_count")
                            .field("analyzer", "standard")
                        .endObject()
                    .endObject()
                .endObject().endObject().string();
        DocumentMapper stage2 = parser.parse(stage2Mapping);

        DocumentMapper.MergeResult mergeResult = stage1.merge(stage2, mergeFlags().simulate(true));
        assertThat(mergeResult.hasConflicts(), equalTo(false));
        // Just simulated so merge hasn't happened yet
        assertThat(((TokenCountFieldMapper) stage1.mappers().smartName("tc").mapper()).analyzer(), equalTo("keyword"));
View Full Code Here

    public void test1Merge() throws Exception {

        String stage1Mapping = XContentFactory.jsonBuilder().startObject().startObject("person").startObject("properties")
                .startObject("name").field("type", "string").endObject()
                .endObject().endObject().endObject().string();
        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
        DocumentMapper stage1 = parser.parse(stage1Mapping);
        String stage2Mapping = XContentFactory.jsonBuilder().startObject().startObject("person").startObject("properties")
                .startObject("name").field("type", "string").endObject()
                .startObject("age").field("type", "integer").endObject()
                .startObject("obj1").startObject("properties").startObject("prop1").field("type", "integer").endObject().endObject().endObject()
                .endObject().endObject().endObject().string();
        DocumentMapper stage2 = parser.parse(stage2Mapping);

        DocumentMapper.MergeResult mergeResult = stage1.merge(stage2, mergeFlags().simulate(true));
        assertThat(mergeResult.hasConflicts(), equalTo(false));
        // since we are simulating, we should not have the age mapping
        assertThat(stage1.mappers().smartName("age"), nullValue());
View Full Code Here

        assertThat(stage1.mappers().smartName("obj1.prop1"), notNullValue());
    }

    @Test
    public void testMergeObjectDynamic() throws Exception {
        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
        String objectMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").endObject().endObject().string();
        DocumentMapper mapper = parser.parse(objectMapping);
        assertThat(mapper.root().dynamic(), equalTo(ObjectMapper.Dynamic.TRUE));

        String withDynamicMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").field("dynamic", "false").endObject().endObject().string();
        DocumentMapper withDynamicMapper = parser.parse(withDynamicMapping);
        assertThat(withDynamicMapper.root().dynamic(), equalTo(ObjectMapper.Dynamic.FALSE));

        DocumentMapper.MergeResult mergeResult = mapper.merge(withDynamicMapper, mergeFlags().simulate(false));
        assertThat(mergeResult.hasConflicts(), equalTo(false));
        assertThat(mapper.root().dynamic(), equalTo(ObjectMapper.Dynamic.FALSE));
View Full Code Here

        assertThat(mapper.root().dynamic(), equalTo(ObjectMapper.Dynamic.FALSE));
    }

    @Test
    public void testMergeObjectAndNested() throws Exception {
        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
        String objectMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
                .startObject("obj").field("type", "object").endObject()
                .endObject().endObject().endObject().string();
        DocumentMapper objectMapper = parser.parse(objectMapping);
        String nestedMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
                .startObject("obj").field("type", "nested").endObject()
                .endObject().endObject().endObject().string();
        DocumentMapper nestedMapper = parser.parse(nestedMapping);

        DocumentMapper.MergeResult mergeResult = objectMapper.merge(nestedMapper, mergeFlags().simulate(true));
        assertThat(mergeResult.hasConflicts(), equalTo(true));
        assertThat(mergeResult.conflicts().length, equalTo(1));
        assertThat(mergeResult.conflicts()[0], equalTo("object mapping [obj] can't be changed from non-nested to nested"));
View Full Code Here

        assertThat(mergeResult.conflicts()[0], equalTo("object mapping [obj] can't be changed from nested to non-nested"));
    }

    @Test
    public void testMergeSearchAnalyzer() throws Exception {
        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
        String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type")
                .startObject("properties").startObject("field").field("type", "string").field("search_analyzer", "whitespace").endObject().endObject()
                .endObject().endObject().string();
        String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type")
                .startObject("properties").startObject("field").field("type", "string").field("search_analyzer", "keyword").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper existing = parser.parse(mapping1);
        DocumentMapper changed = parser.parse(mapping2);

        assertThat(((NamedAnalyzer) existing.mappers().name("field").mapper().searchAnalyzer()).name(), equalTo("whitespace"));
        DocumentMapper.MergeResult mergeResult = existing.merge(changed, mergeFlags().simulate(false));

        assertThat(mergeResult.hasConflicts(), equalTo(false));
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.