ruby + elasticsearch indices/ health

1. elasticsearch cluster 의 health 체크
: esClient.cluster.health => 응답으로 받은 데이터는 hash 형태의 리턴값
{"cluster_name"=>"elasticsearch", "status"=>"yellow", "timed_out"=>false, "number_of_nodes"=>1, "number_of_data_nodes"=>1, "active_primary_shards"=>15, "active_shards"=>15, "relocating_shards"=>0, "initializing_shards"=>0, "unassigned_shards"=>15, "delayed_unassigned_shards"=>0, "number_of_pending_tasks"=>0, "number_of_in_flight_fetch"=>0, "task_max_waiting_in_queue_millis"=>0, "active_shards_percent_as_number"=>50.0}
2. 전체 인덱스 확인
: esClient.cat.indices => 응답으로 받은 데이터는 string 형태의 리턴값

: shell 로 코드를 구성한다면 다음과 같다.
#!/bin/bash curl -XGET localhost:9200/_cat/indices?pretty |
3. document indexing

: shell 로 코드를 구성한다면 다음과 같다.
#!/bin/bash curl -X POST "localhost:9200/index_data" -H "Content-Type: application/json" -d' { "name": "KimJunHyeon" }' |
4. delete_by_query

: 인덱스의 껍데기 (mapping)을 유지한 상태에서 모든 document를 지워야할 경우가 생긴다. 그럴경우
delete_by_query 문을 사용한다.
: shell 로 코드를 구성한다면 다음과 같다.
#!/bin/bash curl -X POST "localhost:9200/index_data/_delete_by_query" -H "Content-Type: application/json" -d' { "query": { "match_all": {} } }' |
'언어 > Ruby' 카테고리의 다른 글
logstash ruby filter elasticsearch bulk insert (0) | 2020.07.22 |
---|---|
ruby json 파일 읽기 (0) | 2020.07.02 |
ruby elasticsearch client (0) | 2020.05.26 |
cea(ver3) (0) | 2016.02.27 |
class (0) | 2016.02.27 |
logstash eve_odd
json file ==============================================================
{"num": 11}
{"num": 12}
{"num": 13}
{"num": 14}
{"num": 15}
{"num": 16}
ruby file ==============================================================
def register( params )
#empty
end
def filter( event )
remainder = event.get("remainder")
if remainder == 0
event.set("num_result", "even_number")
return [ event ]
else
event.set("num_result", "odd_number" )
return [ event ]
end
end
logstash conf ==============================================================
input {
file {
path => "/home/kimjh/Desktop/ruby_proj/stu_01.dir/1050.json"
codec => "json"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
ruby {
code => 'remainder = event.get("num")%2;
event.set("remainder", remainder)'
}
ruby {
path => "/home/kimjh/Desktop/ruby_proj/stu_01.dir/1050.rb"
}
mutate {
remove_field => ["@timestamp", "@version", "host", "path", "remainder"]
}
}
output {
stdout {
codec => rubydebug
}
}
결과 ==============================================================

'ELK > logstash' 카테고리의 다른 글
logstash ruby 활용법 (0) | 2020.07.07 |
---|---|
logstash jdbc mssql output (0) | 2020.07.04 |
logstash file json absolute path (0) | 2020.06.17 |
logstash input-plugin (elasticsearch) (0) | 2020.05.12 |
logstash plugin install (0) | 2020.04.15 |
logstash file json absolute path
input {
file {
path => "/home/kimjh/Desktop/ela.dir/query_/n.json"
type => "json"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
ruby {
code => 'event.set("numCheck", "numberGood")'
}
}
output {
stdout {
codec => rubydebug
}
}
'ELK > logstash' 카테고리의 다른 글
logstash jdbc mssql output (0) | 2020.07.04 |
---|---|
logstash eve_odd (0) | 2020.06.17 |
logstash input-plugin (elasticsearch) (0) | 2020.05.12 |
logstash plugin install (0) | 2020.04.15 |
logstash + app-search (0) | 2019.12.10 |