make sure attributes are also serialized across restarts

This commit is contained in:
kimchy 2010-11-07 15:32:37 +02:00
parent 598225f833
commit d77a0c41d0
2 changed files with 15 additions and 0 deletions

View File

@ -456,6 +456,10 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent {
}
}
}
if (attributes != null && !attributes.isEmpty()) {
builder.field("_attributes", attributes());
}
}
}, indexFieldMapper, typeFieldMapper, idFieldMapper, allFieldMapper, sourceFieldMapper);
}

View File

@ -103,4 +103,15 @@ public class SimpleMapperTests {
// System.out.println("Document: " + doc);
// System.out.println("Json: " + docMapper.sourceMapper().value(doc));
}
@Test public void testAttributes() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/simple/test-mapping.json");
XContentDocumentMapper docMapper = MapperTests.newParser().parse(mapping);
assertThat((String) docMapper.attributes().get("param1"), equalTo("value1"));
String builtMapping = docMapper.mappingSource().string();
XContentDocumentMapper builtDocMapper = MapperTests.newParser().parse(builtMapping);
assertThat((String) builtDocMapper.attributes().get("param1"), equalTo("value1"));
}
}