java + elasticsearch highlevel rest api
참고) java는 잘 모릅니다. ㅋㅋㅋ



High level 또는 Low level을 구별짓는데 난 무슨 차이인지 아직은 명확히 모르겠다.

pom.xml 파일에 <dependencies> 안에 값? 을 넣어준다.


-> 일반적으로 자바에서 클래스 이름의 앞 머리는 대문자로 쓰는 것을 약속한다. (관습)
-> public EsTestClient() : 이부분은 생성자로써 instance 생성시 호출되면 반환타입이 없다.
--> RestClient.builder ( new HttpHost("localhost", 9200, "http") )
--> cluster의 node가 x개이면 x개 만큼 기술해주면 된다.
--> localhost : node 주소
--> 9200 : node의 tcp port 주소
--> http : elasticsearch protocol 물론 tls/ssl 설정되면 https로 바뀌어야 함

-> 자바에서 인스턴스 생성시
클래스_이름 인스턴스_이름 = new 클래스_이름();
'언어 > java' 카테고리의 다른 글
java 크롤링 (0) | 2020.05.09 |
---|---|
정올 1523 (9) (0) | 2020.05.06 |
정올 1338번문제 (8일차) (2) | 2020.05.03 |
1314 정올 (7-2) (0) | 2020.05.02 |
1307 정올 7일차 (0) | 2020.05.02 |
logstash jdbc mssql output
input {
elasticsearch {
hosts => "localhost:9200"
index => "server_kimjh"
query => '{ "query": { "match_all": {} } }'
size => 100
scroll => "2m"
}
}
output {
stdout { codec => rubydebug }
jdbc {
connection_string => "jdbc:sqlserver://localhost:1433;databaseName=server_kimjh;user=kimjh;password=P@ssw0rd!"
driver_jar_path => "C:/Users/EZFARM/Desktop/jar_/sqljdbc/sqljdbc4.jar"
driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
unsafe_statement => true
statement => ["INSERT INTO stu_info (stu_name, stu_age) VALUES(?,?)", "%{stu_name}", "%{stu_age}"]
}
}
input 에 의해서 내려오는 결과값은 한개씩 output 으로 던진다.
input 부분
>curl -XGET localhost:9200/server_kimjh/_mapping?pretty { "server_kimjh" : { "mappings" : { "_doc" : { "properties" : { "stu_age" : { "type" : "long" }, "stu_name" : { "type" : "text", "fields" : { "keyword" : { "type" : "keyword", "ignore_above" : 256 } } } } } } } } |
stu_age 의 field 타입은 long
stu_name 의 field 타입은 text
elasticsearch plugin
=> hosts : 노드의 개수에 따라 array로 표현하면 된다. ["https://xxx.xxx.xxx.xxx:9200", "https://xxx.xxx.xxx.xxx:9200","https://xxx.xxx.xxx.xxx:9200"]
=> query : 개인적으로 아쉬운 부분이긴한데 inline의 형태로 string 으로 입력되어야 한다.
=> size : fetch count
=> scroll : 얘는 정확히 아직 모르겠다. (pagination 처리시 필요한 것으로 일단은 파악)
output 부분
jdbc output 플러그인 사용
'ELK > logstash' 카테고리의 다른 글
특정 필드의 값 변경 (0) | 2020.11.30 |
---|---|
logstash ruby 활용법 (0) | 2020.07.07 |
logstash eve_odd (0) | 2020.06.17 |
logstash file json absolute path (0) | 2020.06.17 |
logstash input-plugin (elasticsearch) (0) | 2020.05.12 |
ruby json 파일 읽기

begin
# 예외가 발생할 가능성이 있는 문구
rescue => e
# 적절한 예외 처리
else
# 예외 발생없이 정상 처리
ensure
# 예외 발생과 상관없이 처리
end
======================================================


json 파일을 읽어서 elasticsearch client를 셋업해보자
'언어 > Ruby' 카테고리의 다른 글
logstash ruby filter elasticsearch bulk insert (0) | 2020.07.22 |
---|---|
ruby + elasticsearch indices/ health (0) | 2020.07.02 |
ruby elasticsearch client (0) | 2020.05.26 |
cea(ver3) (0) | 2016.02.27 |
class (0) | 2016.02.27 |