Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock down _ttl field #9914

Merged
merged 1 commit into from
Feb 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rest-api-spec/test/index/75_ttl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
test:
_ttl:
enabled: 1
store: yes
default: 10s
- do:
cluster.health:
Expand Down
1 change: 0 additions & 1 deletion rest-api-spec/test/update/75_ttl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
test:
_ttl:
enabled: 1
store: yes
default: 10s
- do:
cluster.health:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
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 {

Expand Down Expand Up @@ -103,7 +102,6 @@ public static class TypeParser implements Mapper.TypeParser {
@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -83,16 +86,17 @@ public void testDefaultValues() throws Exception {


@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
Expand All @@ -103,7 +107,7 @@ public void testThatEnablingTTLFieldOnMergeWorks() throws Exception {

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();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/elasticsearch/ttl/SimpleTTLTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public void testSimpleTTL() throws Exception {
.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");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/elasticsearch/update/UpdateTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void createTestIndex() throws Exception {
.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()));
}
Expand Down Expand Up @@ -474,7 +474,7 @@ public void testContextVariables() throws Exception {
.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();
Expand Down Expand Up @@ -624,7 +624,7 @@ public void stressUpdateDeleteConcurrency() throws Exception {
.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)));
Expand Down