@Test
  public void testDefaultMappingAndWithMappingOverrideWithMapperService() throws Exception {
    String defaultMapping =
        XContentFactory.jsonBuilder()
            .startObject()
            .startObject(MapperService.DEFAULT_MAPPING)
            .startObject("_source")
            .field("enabled", false)
            .endObject()
            .endObject()
            .endObject()
            .string();

    MapperService mapperService = MapperTests.newMapperService();
    mapperService.add(MapperService.DEFAULT_MAPPING, defaultMapping);

    String mapping =
        XContentFactory.jsonBuilder()
            .startObject()
            .startObject("type")
            .startObject("_source")
            .field("enabled", true)
            .endObject()
            .endObject()
            .endObject()
            .string();
    mapperService.add("my_type", mapping);

    DocumentMapper mapper = mapperService.documentMapper("my_type");
    assertThat(mapper.type(), equalTo("my_type"));
    assertThat(mapper.sourceMapper().enabled(), equalTo(true));
  }
Пример #2
0
 public void add(String type, String mappingSource) {
   if (DEFAULT_MAPPING.equals(type)) {
     // verify we can parse it
     DocumentMapper mapper = documentParser.parse(type, mappingSource);
     // still add it as a document mapper so we have it registered and, for example, persisted back
     // into
     // the cluster meta data if needed, or checked for existence
     synchronized (mutex) {
       mappers = newMapBuilder(mappers).put(type, mapper).map();
     }
     defaultMappingSource = mappingSource;
   } else {
     add(parse(type, mappingSource));
   }
 }
Пример #3
0
 public DocumentMapper documentMapperWithAutoCreate(String type) {
   DocumentMapper mapper = mappers.get(type);
   if (mapper != null) {
     return mapper;
   }
   if (!dynamic) {
     throw new TypeMissingException(
         index, type, "trying to auto create mapping, but dynamic mapping is disabled");
   }
   // go ahead and dynamically create it
   synchronized (mutex) {
     mapper = mappers.get(type);
     if (mapper != null) {
       return mapper;
     }
     add(type, null);
     return mappers.get(type);
   }
 }