반응형
상황
@Document 어노테이션 indexName 에 datePattern 넣는 방법
해결
@Document(indexName = "test-index-#{@elasticsearchIndexPattern.getToday()}", createIndex = false)
public class TestLog {
@Id
private String id;
@Field(type= FieldType.Text)
private String title;
@Field(type= FieldType.Ip)
private String ip;
@Field(type= FieldType.Keyword)
private String data;
}
위 코드에 @다음 부분에 아래 component 와 함수 호출을 넣어주면 된다.
@Component
public class ElasticsearchIndexPattern {
public String getToday() {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = new Date();
return dateFormat.format(date);
}
}
추가 의문
getToday() 함수는 언제언제 호출 될까?
-> ES operation 이 작동할 때마다 호출이 돼서 날짜가 바로바로 반영이 된다.
반응형
'elastic search' 카테고리의 다른 글
[elastic search][search] 필드 이름에 와일드 카드로 검색 (0) | 2020.03.13 |
---|---|
[Elastic Search][elastalert] Line Alert (0) | 2020.01.22 |
[Elastic Search] logstash - kafka 연동 (0) | 2020.01.09 |
[Elastic Search] logstash - 설치 (0) | 2020.01.09 |