Skip to content

Commit

Permalink
Fixing percolation of documents with TTL set
Browse files Browse the repository at this point in the history
When a type is configured with a TTL, percolation of documents of this type
was not possible. This fix ignores the TTL for percolation instead of
throwing an exception that the document is already expired.

Closes elastic#2975
  • Loading branch information
spinscale committed May 24, 2013
1 parent c3b05f6 commit f34df49
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public boolean includeInObject() {

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,47 @@ public void percolateWithSizeField() throws Exception {
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"));
}
}

0 comments on commit f34df49

Please sign in to comment.