반응형

상황

@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 이 작동할 때마다 호출이 돼서 날짜가 바로바로 반영이 된다.

 

https://stackoverflow.com/questions/24333327/rolling-index-dynamic-index-name-in-spring-data-elasticsearch

반응형
반응형

요구사항

필드 a_1, a_2 ... 이런 식으로 동적인 필드가 있을 때, a_* 로 검색하려면 어떻게 해야할까?

 

해결

 

POST 
http://elastic_host/INDEX_NAME/_search
{
"query": {
        "query_string" : {
            "query" : "(anyfield_\\*:anyvalue)"
        }
    }
}

 

반응형
반응형

elastalert 기능을 보면 line notify 기능이 있다.

 

https://elastalert.readthedocs.io/en/latest/ruletypes.html#line-notify

 

그러나 작동을 안함.

 

확인해보니, loaders.py 에

 

alerts_mapping 에  'linenotify': alerts.LineNotifyAlerter 이 빠져 있음

 

 alerts_mapping = {
		 ...
        'linenotify': alerts.LineNotifyAlerter,
         ...
    }

 

고쳐서, 발송해보니 발송 됨.

 

Rule 파일

#line_notify_rule.yaml

...

alert: linenotify
linenotify_access_token: "TOKEN"

 

위의 TOKEN 발급은

 

https://notify-bot.line.me/my/

 

반응형
반응형

kafka plugin 설치

 

bin/logstash-plugin install logstash-input-kafka

 

logstash config 설정

 

input {
    kafka {
        bootstrap_servers =>  "1.1.1.1:9092,2.2.2.2:9092"
        group_id => "logstash-group-name"
        topics => ["kafka-topic-name"]
        consumer_threads => 1
    }
}

filter {
}

output {
    stdout {
        codec => rubydebug
    }    
    elasticsearch {
        hosts => "http://localhost:9200"
        index => "kafka-test-%{+YYYY-MM-dd}"
        document_type => "_document_type"
    }
}

 

반응형
반응형

binary 다운 받아서 설치하는 방법

 

elastic 라이센스와 oss 버전이 있는데, oss는 apache 라이센스 이다.

 

https://www.elastic.co/kr/downloads/past-releases#logstash-oss

 

버젼 별 다운로드 url 찾아서,

wget https://artifacts.elastic.co/downloads/logstash/logstash-oss-6.8.6.tar.gz
tar zxvf logstash-oss-6.8.6.tar.gz

 

 

 

 

 

 

 

반응형

+ Recent posts