diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java index 941c5068001..a1d28d55b72 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TTLFieldMapper.java @@ -190,7 +190,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R @Override protected Field innerParseCreateField(ParseContext context) throws IOException, AlreadyExpiredException { - if (enabledState.enabled) { + if (enabledState.enabled && !context.sourceToParse().flyweight()) { long ttl = context.sourceToParse().ttl(); if (ttl <= 0 && defaultTTL > 0) { // no ttl provided so we use the default value ttl = defaultTTL; diff --git a/src/test/java/org/elasticsearch/test/integration/percolator/SimplePercolatorTests.java b/src/test/java/org/elasticsearch/test/integration/percolator/SimplePercolatorTests.java index 847aed7075d..863b576c086 100644 --- a/src/test/java/org/elasticsearch/test/integration/percolator/SimplePercolatorTests.java +++ b/src/test/java/org/elasticsearch/test/integration/percolator/SimplePercolatorTests.java @@ -486,4 +486,47 @@ public class SimplePercolatorTests extends AbstractNodesTests { assertThat(percolate.getMatches(), hasItem("kuku")); } + @Test + public void testThatPercolatingWithTimeToLiveWorks() throws Exception { + try { + client.admin().indices().prepareDelete("test").execute().actionGet(); + } catch (Exception e) { + // ignore + } + try { + client.admin().indices().prepareDelete("_percolator").execute().actionGet(); + } catch (Exception e) { + // ignore + } + + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1") + .startObject("_ttl").field("enabled", true).field("default", "60d").endObject() + .startObject("_timestamp").field("enabled", true).endObject() + .endObject().endObject().string(); + + client.admin().indices().prepareCreate("test") + .setSettings(settingsBuilder().put("index.number_of_shards", 2)) + .addMapping("type1", mapping) + .execute().actionGet(); + client.admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); + + client.prepareIndex("_percolator", "test", "kuku").setSource(jsonBuilder() + .startObject() + .startObject("query") + .startObject("term") + .field("field1", "value1") + .endObject() + .endObject() + .endObject() + ).execute().actionGet(); + + PercolateResponse percolateResponse = client.preparePercolate("test", "type1").setSource(jsonBuilder() + .startObject() + .startObject("doc") + .field("field1", "value1") + .endObject() + .endObject() + ).execute().actionGet(); + assertThat(percolateResponse.getMatches(), hasItem("kuku")); + } }