4,563,266 th visitor since 2017.2.1 ( Today : 160 )
Programming
No. 704
Name. swindler
Subject. [ElasticSearch] TTL (Time-To-Live)
Main Cate. 기타 DB
Sub Cate.
Date. 2013-03-25 10:54
Hit. 2725 (211.36.27.3)
File.
TTL 기능을 사용하기 위해서는 Mapping에
_ttl, _timestamp가 세팅되어 있어야 한다.


_timestamp: {
enabled: true
}
_ttl: {
enabled: true
default: 86400000
}


아래와 같이 IndexRequestBuilder에서 세팅이 가능하다.

IndexRequestBuilder.setTimestamp(DateUtil.getTimestampStr());
IndexRequestBuilder.setTTL(TimeValue.timeValueHours(TTL_MESSAGE).millis());

    public static String getTimestamp(long longdate){
        Date date = new Date(longdate);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        df.setTimeZone(TimeZone.getTimeZone("GMT"));
        return df.format(date);
    }

참고로 IndexRequestBuilder에서 setTimestamp는 String 형태로만 가능하다.


Timestamp와 ttl도 ctx._ttl와 ctx._timestamp를 통해 업데이트 가능하다.


[바로가기 링크] : http://coolx.net/cboard/develop/704



Name
Password
Comment
Copyright © 1999-2017, swindler. All rights reserved. 367,611 visitor ( 1999.1.8-2004.5.26 ), 2,405,771 ( -2017.01.31)

  2HLAB   2HLAB_Blog   RedToolBox   Omil   Omil_Blog