6

I installed debian package

I am able to push data using curl:

curl -XPUT 'http://mybox:9200/blog/user/dilbert' -d '{
  "name": "Dilbert Brown"
}'

And fetch it

curl -XGET 'http://mybox:9200/blog/user/dilbert'

result:

{
  "_index": "blog",
  "_type": "user",
  "_id": "dilbert",
  "_version": 2,
  "exists": true,
  "_source": {
    "name": "Dilbert Brown"
  }
}

And find it with

curl -XGET 'http://mybox:9200/blog/user/_search?q=name:Dilbert+Brown&pretty=True'

I want to push the same record with ttl of 5 seconds and 5 seconds later get 404 http status code when trying to fetch this entry. Also the entry should not be visible in search results.

NOTE: I tried various combinations of search configurations from

None of them helped me out.

Can somebody mention a simple sequence of steps that would let me achieve the targeted outcome?

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
Archibald
  • 1,305
  • 1
  • 14
  • 19
  • What does it tell you when you define `?ttl=5000` in `PUT` and then try `GET`ting it later? – bereal Jun 05 '13 at 07:17

3 Answers3

12

Here is what works for me:

curl -XPUT 'http://localhost:9200/blog/user/_mapping' -d '{"user": {"_ttl": {"enabled": true, "default": 5000}}}'

curl -XPUT 'http://localhost:9200/blog/user/phb' -d '{"name" : "Pointy-Haired Boss"}'

sleep 60  # this is the default deletion interval for the expired documents

curl -XGET http://localhost:9200/blog/user/phb  # 404
bereal
  • 32,519
  • 6
  • 58
  • 104
7

@bereal is right.

For ttl to work, you have to enable it first in mapping (by default, it's disabled), and then set the TTL value when indexing documents.

curl -XPUT 'mybox:9200/blog/user/_mapping?pretty' -d '{
  "user": {
     "_ttl": {"enabled": true}
}'

curl -XPUT 'mybox:9200/blog/user/dilbert' -d '{ "name" : "Dilbert Brown", "_ttl": "3m"}'

curl -XGET 'mybox:9200/blog/user/dilbert?pretty'

For more information, please reference

Michael
  • 1,667
  • 2
  • 17
  • 18
  • 1
    I believe this should be _ttl on the 2nd put. This is according with the 2nd link that you provided. – bwight Jul 18 '14 at 17:20
0

Please take note that you can only setting TTL during create new mapping (type). You cannot enable it after created. I already tried many way to enable it after product release, but cannot. So that I must update code to use the new one which created with TTL enable. For more information, I can see here: http://grokbase.com/t/gg/elasticsearch/132v5y0w11/problem-with-ttl

nhthai
  • 198
  • 2
  • 10