bring back boost mapping support when building mapping source

This commit is contained in:
kimchy 2010-02-21 23:37:48 +02:00
parent 6d52065db3
commit 8c16840fd7
3 changed files with 19 additions and 3 deletions

View File

@ -172,6 +172,11 @@ public class JsonBoostFieldMapper extends JsonNumberFieldMapper<Float> implement
} }
@Override public void toJson(JsonBuilder builder, Params params) throws IOException { @Override public void toJson(JsonBuilder builder, Params params) throws IOException {
// for now, don't output it at all builder.startObject(jsonType());
builder.field("name", name());
if (nullValue != null) {
builder.field("nullValue", nullValue);
}
builder.endObject();
} }
} }

View File

@ -380,6 +380,7 @@ public class JsonObjectMapper implements JsonMapper {
builder.field("dynamic", dynamic); builder.field("dynamic", dynamic);
builder.field("enabled", enabled); builder.field("enabled", enabled);
builder.field("pathType", pathType.name().toLowerCase()); builder.field("pathType", pathType.name().toLowerCase());
if (dateTimeFormatters.length > 0) { if (dateTimeFormatters.length > 0) {
builder.startArray("dateFormats"); builder.startArray("dateFormats");
for (FormatDateTimeFormatter dateTimeFormatter : dateTimeFormatters) { for (FormatDateTimeFormatter dateTimeFormatter : dateTimeFormatters) {
@ -387,10 +388,20 @@ public class JsonObjectMapper implements JsonMapper {
} }
builder.endArray(); builder.endArray();
} }
// check internal mappers first (this is only relevant for root object)
for (JsonMapper mapper : mappers.values()) {
if (mapper instanceof InternalMapper) {
mapper.toJson(builder, params);
}
}
if (!mappers.isEmpty()) { if (!mappers.isEmpty()) {
builder.startObject("properties"); builder.startObject("properties");
for (JsonMapper mapper : mappers.values()) { for (JsonMapper mapper : mappers.values()) {
mapper.toJson(builder, params); if (!(mapper instanceof InternalMapper)) {
mapper.toJson(builder, params);
}
} }
builder.endObject(); builder.endObject();
} }

View File

@ -62,7 +62,7 @@ public class SimpleJsonMapperTests {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/json/simple/test-mapping.json"); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/json/simple/test-mapping.json");
JsonDocumentMapper docMapper = (JsonDocumentMapper) new JsonDocumentMapperParser(new AnalysisService(new Index("test"))).parse(mapping); JsonDocumentMapper docMapper = (JsonDocumentMapper) new JsonDocumentMapperParser(new AnalysisService(new Index("test"))).parse(mapping);
String builtMapping = docMapper.buildSource(); String builtMapping = docMapper.buildSource();
System.out.println(builtMapping); // System.out.println(builtMapping);
// reparse it // reparse it
JsonDocumentMapper builtDocMapper = (JsonDocumentMapper) new JsonDocumentMapperParser(new AnalysisService(new Index("test"))).parse(builtMapping); JsonDocumentMapper builtDocMapper = (JsonDocumentMapper) new JsonDocumentMapperParser(new AnalysisService(new Index("test"))).parse(builtMapping);
String json = copyToStringFromClasspath("/org/elasticsearch/index/mapper/json/simple/test1.json"); String json = copyToStringFromClasspath("/org/elasticsearch/index/mapper/json/simple/test1.json");