Fix bug in DateFieldMapper where format is serialized instead of locale
This fix adds a default serialization step in the SimpleDateMappingTests that parses the mapping, builds the mapper, serializes the mapper and rebuilds the actual mapper from the serialization result. The contained information must be equivalent to the original mapping. The fixed bug has no issue assigned to is since the code is unreleased yet.
This commit is contained in:
parent
bb9871bcb5
commit
841c2d1e14
|
@ -449,7 +449,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
builder.field("numeric_resolution", timeUnit.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
if (dateTimeFormatter.locale() != null) {
|
||||
builder.field("locale", dateTimeFormatter.format());
|
||||
builder.field("locale", dateTimeFormatter.locale());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,10 @@ import org.apache.lucene.search.NumericRangeFilter;
|
|||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
|
@ -60,7 +63,7 @@ public class SimpleDateMappingTests {
|
|||
.startObject("properties").endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
DocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||
DocumentMapper defaultMapper = mapper(mapping);
|
||||
|
||||
defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
|
@ -124,8 +127,7 @@ public class SimpleDateMappingTests {
|
|||
.endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
DocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||
|
||||
DocumentMapper defaultMapper = mapper(mapping);
|
||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("date_field_en", "Wed, 06 Dec 2000 02:55:00 -0800")
|
||||
|
@ -137,6 +139,17 @@ public class SimpleDateMappingTests {
|
|||
assertNumericTokensEqual(doc, defaultMapper, "date_field_en", "date_field_default");
|
||||
}
|
||||
|
||||
private DocumentMapper mapper(String mapping) throws IOException {
|
||||
// we serialize and deserialize the mapping to make sure serialization works just fine
|
||||
DocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||
builder.startObject();
|
||||
defaultMapper.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
String rebuildMapping = builder.string();
|
||||
return MapperTests.newParser().parse(rebuildMapping);
|
||||
}
|
||||
|
||||
private void assertNumericTokensEqual(ParsedDocument doc, DocumentMapper defaultMapper, String fieldA, String fieldB) throws IOException {
|
||||
assertThat(doc.rootDoc().getField(fieldA).tokenStream(defaultMapper.indexAnalyzer()), notNullValue());
|
||||
assertThat(doc.rootDoc().getField(fieldB).tokenStream(defaultMapper.indexAnalyzer()), notNullValue());
|
||||
|
@ -165,7 +178,7 @@ public class SimpleDateMappingTests {
|
|||
.startObject("properties").startObject("date_field").field("type", "date").endObject().endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
DocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||
DocumentMapper defaultMapper = mapper(mapping);
|
||||
|
||||
long value = System.currentTimeMillis();
|
||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
|
@ -184,7 +197,7 @@ public class SimpleDateMappingTests {
|
|||
.startObject("properties").startObject("date_field").field("type", "date").endObject().endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
DocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||
DocumentMapper defaultMapper = mapper(mapping);
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
|
@ -204,7 +217,7 @@ public class SimpleDateMappingTests {
|
|||
.startObject("properties").startObject("date_field").field("type", "date").field("format", "HH:mm:ss").endObject().endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
DocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||
DocumentMapper defaultMapper = mapper(mapping);
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
|
@ -230,7 +243,7 @@ public class SimpleDateMappingTests {
|
|||
.endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
DocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||
DocumentMapper defaultMapper = mapper(mapping);
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
|
|
Loading…
Reference in New Issue