I am new to elastic search, I want to expire the documents indexed in the elastic search with jest API from the application. I found that there is a parameter called as TTL for that. But I am facing problem to set the parameter as enabled and true from the jest client. Please let me know how to accomplish this. Thanks in advance!
Asked
Active
Viewed 1,326 times
1
-
I advise against the use of TTL, but rather think about your data if it can be structured so that you can delete an entire index after the data "expired". It's much more efficient this way than using TTL. – Andrei Stefan Apr 27 '16 at 12:33
-
Can you please elaborate how to delete only the indexes which have expired data – sweety Apr 28 '16 at 11:28
-
Use the tool called Curator to delete `indices` `--OLDER-THAN integer_value`: https://www.elastic.co/guide/en/elasticsearch/client/curator/current/indices-subcommand.html – Andrei Stefan Apr 28 '16 at 11:45
1 Answers
1
This seemed to work for me:
final String index = "myindex";
final String type = "mytype";
final String id = "myid";
final PutMapping putMapping = new PutMapping.Builder(index, type, "{ \"_ttl\" : { \"enabled\" : true } }").build();
client.execute(putMapping);
final Map<String, String> documentToIndex = new HashMap<String, String>();
documentToIndex.put("name", "Fred");
documentToIndex.put("phoneNumber", "1234");
documentToIndex.put("_ttl", "30s"); // Set the TTL
final String jsonDocument = gson.toJson(documentToIndex);
final JestResult result = client.execute(new Index.Builder(jsonDocument).index(index).type(type).id(id).build());

Alex Spurling
- 54,094
- 23
- 70
- 76