private void doTestDefaultFloatingPointMappings(DocumentMapper mapper, XContentBuilder builder) throws IOException { BytesReference source = builder .startObject() .field("foo", 3.2f) // float .field("bar", 3.2d) // double .field("baz", (double) 3.2f) // double that can be accurately represented as a float .field("quux", "3.2") // float detected through numeric detection .endObject() .bytes(); ParsedDocument parsedDocument = mapper.parse("index", "type", "id", source); Mapping update = parsedDocument.dynamicMappingsUpdate(); assertNotNull(update); assertThat( ((FieldMapper) update.root().getMapper("foo")).fieldType().typeName(), equalTo("float")); assertThat( ((FieldMapper) update.root().getMapper("bar")).fieldType().typeName(), equalTo("float")); assertThat( ((FieldMapper) update.root().getMapper("baz")).fieldType().typeName(), equalTo("float")); assertThat( ((FieldMapper) update.root().getMapper("quux")).fieldType().typeName(), equalTo("float")); }
private Mapper parse(DocumentMapper mapper, DocumentMapperParser parser, XContentBuilder builder) throws Exception { Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); ParseContext.InternalParseContext ctx = new ParseContext.InternalParseContext(settings, parser, mapper, new ContentPath(0)); SourceToParse source = SourceToParse.source(builder.bytes()); ctx.reset(XContentHelper.createParser(source.source()), new ParseContext.Document(), source); assertEquals(XContentParser.Token.START_OBJECT, ctx.parser().nextToken()); ctx.parser().nextToken(); DocumentParser.parseObjectOrNested(ctx, mapper.root(), true); Mapping mapping = DocumentParser.createDynamicUpdate(mapper.mapping(), mapper, ctx.getDynamicMappers()); return mapping == null ? null : mapping.root(); }