Mapping: serialize doc values settings for _timestamp

This change fixes _timestamp's serialization method to write out
`doc_values` and `doc_values_format`, which could already be set,
but would not be written out.

closes #8893
closes #8967
This commit is contained in:
Ryan Ernst 2014-12-15 13:15:42 -08:00
parent 15d46988dc
commit 7d5a15e461
3 changed files with 28 additions and 2 deletions

View File

@ -282,7 +282,7 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T> {
protected final Names names;
protected float boost;
protected FieldType fieldType;
private final boolean docValues;
protected final boolean docValues;
protected final NamedAnalyzer indexAnalyzer;
protected NamedAnalyzer searchAnalyzer;
protected PostingsFormatProvider postingsFormat;

View File

@ -32,11 +32,13 @@ import org.elasticsearch.common.joda.Joda;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.codec.docvaluesformat.DocValuesFormatProvider;
import org.elasticsearch.index.codec.docvaluesformat.DocValuesFormatService;
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.core.DateFieldMapper;
import org.elasticsearch.index.mapper.core.LongFieldMapper;
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
import org.elasticsearch.index.mapper.core.TypeParsers;
import java.io.IOException;
import java.util.Iterator;
@ -264,7 +266,8 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
if (!includeDefaults && indexed == indexedDefault && customFieldDataSettings == null &&
fieldType.stored() == Defaults.FIELD_TYPE.stored() && enabledState == Defaults.ENABLED && path == Defaults.PATH
&& dateTimeFormatter.format().equals(Defaults.DATE_TIME_FORMATTER.format())
&& Defaults.DEFAULT_TIMESTAMP.equals(defaultTimestamp)) {
&& Defaults.DEFAULT_TIMESTAMP.equals(defaultTimestamp)
&& Defaults.DOC_VALUES == hasDocValues()) {
return builder;
}
builder.startObject(CONTENT_TYPE);
@ -277,6 +280,9 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
if (includeDefaults || fieldType.stored() != Defaults.FIELD_TYPE.stored()) {
builder.field("store", fieldType.stored());
}
if (includeDefaults || hasDocValues() != Defaults.DOC_VALUES) {
builder.field(TypeParsers.DOC_VALUES, docValues);
}
if (includeDefaults || path != Defaults.PATH) {
builder.field("path", path);
}
@ -292,6 +298,18 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
builder.field("fielddata", (Map) fieldDataType.getSettings().getAsMap());
}
if (docValuesFormat != null) {
if (includeDefaults || !docValuesFormat.name().equals(defaultDocValuesFormat())) {
builder.field(DOC_VALUES_FORMAT, docValuesFormat.name());
}
} else if (includeDefaults) {
String format = defaultDocValuesFormat();
if (format == null) {
format = DocValuesFormatService.DEFAULT_FORMAT;
}
builder.field(DOC_VALUES_FORMAT, format);
}
builder.endObject();
return builder;
}

View File

@ -32,11 +32,13 @@ import org.elasticsearch.common.compress.CompressedString;
import org.elasticsearch.common.io.stream.BytesStreamInput;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.joda.Joda;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.codec.docvaluesformat.DocValuesFormatService;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.FieldMapper;
@ -111,6 +113,8 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest {
assertThat(docMapper.timestampFieldMapper().fieldType().indexOptions(), equalTo(TimestampFieldMapper.Defaults.FIELD_TYPE.indexOptions()));
assertThat(docMapper.timestampFieldMapper().path(), equalTo(TimestampFieldMapper.Defaults.PATH));
assertThat(docMapper.timestampFieldMapper().dateTimeFormatter().format(), equalTo(TimestampFieldMapper.DEFAULT_DATE_TIME_FORMAT));
assertThat(docMapper.timestampFieldMapper().hasDocValues(), equalTo(false));
assertThat(docMapper.timestampFieldMapper().docValuesFormatProvider(), equalTo(null));
assertAcked(client().admin().indices().prepareDelete("test").execute().get());
}
}
@ -123,6 +127,8 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest {
.startObject("_timestamp")
.field("enabled", "yes").field("store", "no").field("index", "no")
.field("path", "timestamp").field("format", "year")
.field("doc_values", true)
.field("doc_values_format", Lucene.LATEST_DOC_VALUES_FORMAT)
.endObject()
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
@ -131,6 +137,8 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest {
assertEquals(IndexOptions.NONE, docMapper.timestampFieldMapper().fieldType().indexOptions());
assertThat(docMapper.timestampFieldMapper().path(), equalTo("timestamp"));
assertThat(docMapper.timestampFieldMapper().dateTimeFormatter().format(), equalTo("year"));
assertThat(docMapper.timestampFieldMapper().hasDocValues(), equalTo(true));
assertThat(docMapper.timestampFieldMapper().docValuesFormatProvider().name(), equalTo(Lucene.LATEST_DOC_VALUES_FORMAT));
}
@Test