Mappings: Lock down _ttl field

While the parser allowed changing field type settings, these would never
have been serialized.  So this change simply removes parsing using
parseField. Backcompat will still work if a user uploads old settings
(they just would never have worked anyways, so we continue ignoring
them with 1.x, and 2.x will now error).

see #8143
closes #9914
This commit is contained in:
Ryan Ernst 2015-02-26 15:32:06 -08:00
parent 9d708e20a0
commit dd0084de83
6 changed files with 15 additions and 15 deletions

View File

@ -11,7 +11,6 @@
test:
_ttl:
enabled: 1
store: yes
default: 10s
- do:
cluster.health:

View File

@ -12,7 +12,6 @@
test:
_ttl:
enabled: 1
store: yes
default: 10s
- do:
cluster.health:

View File

@ -51,7 +51,6 @@ import java.util.Map;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeTimeValue;
import static org.elasticsearch.index.mapper.MapperBuilders.ttl;
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, RootMapper {
@ -103,7 +102,6 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
TTLFieldMapper.Builder builder = ttl();
parseField(builder, builder.name, node, parserContext);
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, Object> entry = iterator.next();
String fieldName = Strings.toUnderscoreCase(entry.getKey());

View File

@ -20,10 +20,13 @@
package org.elasticsearch.index.mapper.ttl;
import org.apache.lucene.index.IndexOptions;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.compress.CompressedString;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.*;
@ -83,16 +86,17 @@ public class TTLMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testSetValues() throws Exception {
public void testSetValuesBackcompat() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_ttl")
.field("enabled", "yes").field("store", "no").field("index", "no")
.field("enabled", "yes").field("store", "no")
.endObject()
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
Settings indexSettings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
DocumentMapper docMapper = createIndex("test", indexSettings).mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.TTLFieldMapper().enabled(), equalTo(true));
assertThat(docMapper.TTLFieldMapper().fieldType().stored(), equalTo(false));
assertEquals(IndexOptions.NONE, docMapper.TTLFieldMapper().fieldType().indexOptions());
assertThat(docMapper.TTLFieldMapper().fieldType().stored(), equalTo(true)); // store was never serialized, so it was always lost
}
@Test
@ -103,7 +107,7 @@ public class TTLMappingTests extends ElasticsearchSingleNodeTest {
String mappingWithTtl = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_ttl")
.field("enabled", "yes").field("store", "no").field("index", "no")
.field("enabled", "yes")
.endObject()
.startObject("properties").field("field").startObject().field("type", "string").endObject().endObject()
.endObject().endObject().string();

View File

@ -71,14 +71,14 @@ public class SimpleTTLTests extends ElasticsearchIntegrationTest {
.startObject()
.startObject("type1")
.startObject("_timestamp").field("enabled", true).field("store", "yes").endObject()
.startObject("_ttl").field("enabled", true).field("store", "yes").endObject()
.startObject("_ttl").field("enabled", true).endObject()
.endObject()
.endObject())
.addMapping("type2", XContentFactory.jsonBuilder()
.startObject()
.startObject("type2")
.startObject("_timestamp").field("enabled", true).field("store", "yes").endObject()
.startObject("_ttl").field("enabled", true).field("store", "yes").field("default", "1d").endObject()
.startObject("_ttl").field("enabled", true).field("default", "1d").endObject()
.endObject()
.endObject()));
ensureYellow("test");

View File

@ -73,7 +73,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest {
.startObject()
.startObject("type1")
.startObject("_timestamp").field("enabled", true).field("store", "yes").endObject()
.startObject("_ttl").field("enabled", true).field("store", "yes").endObject()
.startObject("_ttl").field("enabled", true).endObject()
.endObject()
.endObject()));
}
@ -474,7 +474,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest {
.startObject("subtype1")
.startObject("_parent").field("type", "type1").endObject()
.startObject("_timestamp").field("enabled", true).field("store", "yes").endObject()
.startObject("_ttl").field("enabled", true).field("store", "yes").endObject()
.startObject("_ttl").field("enabled", true).endObject()
.endObject()
.endObject())
.execute().actionGet();
@ -624,7 +624,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest {
.startObject()
.startObject("type1")
.startObject("_timestamp").field("enabled", true).field("store", "yes").endObject()
.startObject("_ttl").field("enabled", true).field("store", "yes").endObject()
.startObject("_ttl").field("enabled", true).endObject()
.endObject()
.endObject())
.setSettings(ImmutableSettings.builder().put(MergePolicyModule.MERGE_POLICY_TYPE_KEY, NoMergePolicyProvider.class)));