Fixing percolation of documents with TTL set
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 #2975
This commit is contained in:
parent
6e366bae34
commit
2e4d18b519
|
@ -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;
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue