Mapping: Rename _attributes to _meta, closes #518.
This commit is contained in:
parent
b8b4cbbb46
commit
8a8a6d5547
|
@ -45,7 +45,7 @@ public interface DocumentMapper {
|
|||
/**
|
||||
* Attributes of this type mappings.
|
||||
*/
|
||||
ImmutableMap<String, Object> attributes();
|
||||
ImmutableMap<String, Object> meta();
|
||||
|
||||
/**
|
||||
* Generates the source of the mapper based on the current mappings.
|
||||
|
|
|
@ -70,7 +70,7 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent {
|
|||
|
||||
private final RootObjectMapper rootObjectMapper;
|
||||
|
||||
private ImmutableMap<String, Object> attributes = ImmutableMap.of();
|
||||
private ImmutableMap<String, Object> meta = ImmutableMap.of();
|
||||
|
||||
private XContentMapper.BuilderContext builderContext = new XContentMapper.BuilderContext(new ContentPath(1));
|
||||
|
||||
|
@ -79,8 +79,8 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent {
|
|||
this.rootObjectMapper = builder.build(builderContext);
|
||||
}
|
||||
|
||||
public Builder attributes(ImmutableMap<String, Object> attributes) {
|
||||
this.attributes = attributes;
|
||||
public Builder meta(ImmutableMap<String, Object> meta) {
|
||||
this.meta = meta;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent {
|
|||
|
||||
public XContentDocumentMapper build(XContentDocumentMapperParser docMapperParser) {
|
||||
Preconditions.checkNotNull(rootObjectMapper, "Mapper builder must have the root object mapper set");
|
||||
return new XContentDocumentMapper(index, docMapperParser, rootObjectMapper, attributes, uidFieldMapper, idFieldMapper, typeFieldMapper, indexFieldMapper,
|
||||
return new XContentDocumentMapper(index, docMapperParser, rootObjectMapper, meta, uidFieldMapper, idFieldMapper, typeFieldMapper, indexFieldMapper,
|
||||
sourceFieldMapper, routingFieldMapper, allFieldMapper, analyzerMapper, indexAnalyzer, searchAnalyzer, boostFieldMapper);
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent {
|
|||
|
||||
private final XContentDocumentMapperParser docMapperParser;
|
||||
|
||||
private volatile ImmutableMap<String, Object> attributes;
|
||||
private volatile ImmutableMap<String, Object> meta;
|
||||
|
||||
private volatile CompressedString mappingSource;
|
||||
|
||||
|
@ -205,7 +205,7 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent {
|
|||
|
||||
public XContentDocumentMapper(String index, XContentDocumentMapperParser docMapperParser,
|
||||
RootObjectMapper rootObjectMapper,
|
||||
ImmutableMap<String, Object> attributes,
|
||||
ImmutableMap<String, Object> meta,
|
||||
UidFieldMapper uidFieldMapper,
|
||||
IdFieldMapper idFieldMapper,
|
||||
TypeFieldMapper typeFieldMapper,
|
||||
|
@ -219,7 +219,7 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent {
|
|||
this.index = index;
|
||||
this.type = rootObjectMapper.name();
|
||||
this.docMapperParser = docMapperParser;
|
||||
this.attributes = attributes;
|
||||
this.meta = meta;
|
||||
this.rootObjectMapper = rootObjectMapper;
|
||||
this.uidFieldMapper = uidFieldMapper;
|
||||
this.idFieldMapper = idFieldMapper;
|
||||
|
@ -272,8 +272,8 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent {
|
|||
return this.type;
|
||||
}
|
||||
|
||||
@Override public ImmutableMap<String, Object> attributes() {
|
||||
return this.attributes;
|
||||
@Override public ImmutableMap<String, Object> meta() {
|
||||
return this.meta;
|
||||
}
|
||||
|
||||
@Override public CompressedString mappingSource() {
|
||||
|
@ -448,7 +448,7 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent {
|
|||
rootObjectMapper.merge(xContentMergeWith.rootObjectMapper, mergeContext);
|
||||
if (!mergeFlags.simulate()) {
|
||||
// let the merge with attributes to override the attributes
|
||||
attributes = mergeWith.attributes();
|
||||
meta = mergeWith.meta();
|
||||
// update the source of the merged one
|
||||
refreshSource();
|
||||
}
|
||||
|
@ -488,8 +488,8 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent {
|
|||
}
|
||||
}
|
||||
|
||||
if (attributes != null && !attributes.isEmpty()) {
|
||||
builder.field("_attributes", attributes());
|
||||
if (meta != null && !meta.isEmpty()) {
|
||||
builder.field("_meta", meta());
|
||||
}
|
||||
}
|
||||
// no need to pass here id and boost, since they are added to the root object mapper
|
||||
|
|
|
@ -172,10 +172,10 @@ public class XContentDocumentMapperParser extends AbstractIndexComponent impleme
|
|||
}
|
||||
|
||||
ImmutableMap<String, Object> attributes = ImmutableMap.of();
|
||||
if (mapping.containsKey("_attributes")) {
|
||||
attributes = ImmutableMap.copyOf((Map<String, Object>) mapping.get("_attributes"));
|
||||
if (mapping.containsKey("_meta")) {
|
||||
attributes = ImmutableMap.copyOf((Map<String, Object>) mapping.get("_meta"));
|
||||
}
|
||||
docBuilder.attributes(attributes);
|
||||
docBuilder.meta(attributes);
|
||||
|
||||
XContentDocumentMapper documentMapper = docBuilder.build(this);
|
||||
// update the source with the generated one
|
||||
|
|
|
@ -79,7 +79,7 @@ public class SimpleMapperTests {
|
|||
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"));
|
||||
assertThat((String) docMapper.meta().get("param1"), equalTo("value1"));
|
||||
|
||||
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/simple/test1.json");
|
||||
Document doc = docMapper.parse(json).doc();
|
||||
|
@ -108,10 +108,10 @@ public class SimpleMapperTests {
|
|||
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"));
|
||||
assertThat((String) docMapper.meta().get("param1"), equalTo("value1"));
|
||||
|
||||
String builtMapping = docMapper.mappingSource().string();
|
||||
XContentDocumentMapper builtDocMapper = MapperTests.newParser().parse(builtMapping);
|
||||
assertThat((String) builtDocMapper.attributes().get("param1"), equalTo("value1"));
|
||||
assertThat((String) builtDocMapper.meta().get("param1"), equalTo("value1"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
person : {
|
||||
"_attributes" : {
|
||||
"_meta" : {
|
||||
"param1" : "value1"
|
||||
},
|
||||
date_formats : ["yyyy-MM-dd", "dd-MM-yyyy"],
|
||||
|
|
Loading…
Reference in New Issue