Returning configuration of root field mappers toXContent method only if they are enabled
This commit is contained in:
parent
fbdf89c636
commit
4f96b36376
|
@ -192,7 +192,7 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
builder.startObject(CONTENT_TYPE);
|
builder.startObject(CONTENT_TYPE);
|
||||||
if (fieldType().stored() != Defaults.FIELD_TYPE.stored()) {
|
if (fieldType().stored() != Defaults.FIELD_TYPE.stored() && enabledState.enabled) {
|
||||||
builder.field("store", fieldType().stored());
|
builder.field("store", fieldType().stored());
|
||||||
}
|
}
|
||||||
if (enabledState != Defaults.ENABLED_STATE) {
|
if (enabledState != Defaults.ENABLED_STATE) {
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
|
||||||
if (enabledState != Defaults.ENABLED_STATE) {
|
if (enabledState != Defaults.ENABLED_STATE) {
|
||||||
builder.field("enabled", enabledState.enabled);
|
builder.field("enabled", enabledState.enabled);
|
||||||
}
|
}
|
||||||
if (fieldType().stored() != Defaults.SIZE_FIELD_TYPE.stored()) {
|
if (fieldType().stored() != Defaults.SIZE_FIELD_TYPE.stored() && enabledState.enabled) {
|
||||||
builder.field("store", fieldType().stored());
|
builder.field("store", fieldType().stored());
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
|
@ -221,7 +221,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
|
||||||
if (enabledState != Defaults.ENABLED_STATE) {
|
if (enabledState != Defaults.ENABLED_STATE) {
|
||||||
builder.field("enabled", enabledState.enabled);
|
builder.field("enabled", enabledState.enabled);
|
||||||
}
|
}
|
||||||
if (defaultTTL != Defaults.DEFAULT) {
|
if (defaultTTL != Defaults.DEFAULT && enabledState.enabled) {
|
||||||
builder.field("default", defaultTTL);
|
builder.field("default", defaultTTL);
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
|
@ -221,20 +221,22 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
builder.startObject(CONTENT_TYPE);
|
builder.startObject(CONTENT_TYPE);
|
||||||
if (fieldType.indexed() != Defaults.FIELD_TYPE.indexed()) {
|
|
||||||
builder.field("index", fieldType.indexed());
|
|
||||||
}
|
|
||||||
if (fieldType.stored() != Defaults.FIELD_TYPE.stored()) {
|
|
||||||
builder.field("store", fieldType.stored());
|
|
||||||
}
|
|
||||||
if (enabledState != Defaults.ENABLED) {
|
if (enabledState != Defaults.ENABLED) {
|
||||||
builder.field("enabled", enabledState.enabled);
|
builder.field("enabled", enabledState.enabled);
|
||||||
}
|
}
|
||||||
if (path != Defaults.PATH) {
|
if (enabledState.enabled) {
|
||||||
builder.field("path", path);
|
if (fieldType.indexed() != Defaults.FIELD_TYPE.indexed()) {
|
||||||
}
|
builder.field("index", fieldType.indexed());
|
||||||
if (!dateTimeFormatter.format().equals(Defaults.DATE_TIME_FORMATTER.format())) {
|
}
|
||||||
builder.field("format", dateTimeFormatter.format());
|
if (fieldType.stored() != Defaults.FIELD_TYPE.stored()) {
|
||||||
|
builder.field("store", fieldType.stored());
|
||||||
|
}
|
||||||
|
if (path != Defaults.PATH) {
|
||||||
|
builder.field("path", path);
|
||||||
|
}
|
||||||
|
if (!dateTimeFormatter.format().equals(Defaults.DATE_TIME_FORMATTER.format())) {
|
||||||
|
builder.field("format", dateTimeFormatter.format());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.test.unit.index.mapper.timestamp;
|
package org.elasticsearch.test.unit.index.mapper.timestamp;
|
||||||
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||||
|
@ -113,4 +114,20 @@ public class TimestampMappingTests {
|
||||||
|
|
||||||
assertThat(enabledMapper.timestampFieldMapper().enabled(), is(false));
|
assertThat(enabledMapper.timestampFieldMapper().enabled(), is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testThatDisablingFieldMapperDoesNotReturnAnyUselessInfo() throws Exception {
|
||||||
|
boolean inversedStoreSetting = !TimestampFieldMapper.Defaults.FIELD_TYPE.stored();
|
||||||
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
|
.startObject("_timestamp").field("enabled", false).field("store", inversedStoreSetting).endObject()
|
||||||
|
.endObject().endObject().string();
|
||||||
|
|
||||||
|
DocumentMapper mapper = MapperTests.newParser().parse(mapping);
|
||||||
|
|
||||||
|
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
|
||||||
|
mapper.timestampFieldMapper().toXContent(builder, null);
|
||||||
|
builder.endObject();
|
||||||
|
|
||||||
|
assertThat(builder.string(), is(String.format("{\"%s\":{}}", TimestampFieldMapper.NAME)));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue