정올 1291 : 구구단 문제
package java_01;
import java.util.Scanner;
public class GuGuDan {
public static int[] dan = new int[2];
public static boolean checkNumber = false;
public static void main(String[] args) {
try (Scanner input = new Scanner(System.in)) {
while (true) {
for (int i = 0; i < dan.length; i++) {
dan[i] = input.nextInt();
}
if (checkFunc(dan)) {
break;
}
System.out.println("INPUT ERROR!");
}
}
printGuGuDan(dan);
} // end of main function
public static boolean checkFunc(int dan[]) {
boolean flag = false;
for (int i = 0; i < dan.length; i++) {
if (2 <= dan[i] && dan[i] <= 9) {
flag = true;
} else {
flag = false;
}
}
return flag;
} // end of checkFunc function
public static void printGuGuDan(int dan[]) {
for (int i = 1; i <= 9; i++) {
for (int j = 0; j < dan.length; j++) {
System.out.printf("%d * %d = %d", dan[j], i, dan[j]*i);
if ( j != dan.length-1) {
System.out.print("\t");
} else {
System.out.println();
}
}
}
} // end of printGuGuDan function
}
'언어 > java' 카테고리의 다른 글
정올 1856 (d+3) (1) | 2020.04.22 |
---|---|
정올 1303 문제 풀이 (자바) (0) | 2020.04.21 |
정올 587번 문제 (0) | 2020.04.06 |
변수 [ Java의 정석 ] (0) | 2020.04.06 |
elasticsearch + java + index 삭제 (0) | 2019.12.14 |
'한줄 일기' 카테고리의 다른 글
자전거 여행 (중동 => 선유도 => 중동) (0) | 2020.07.19 |
---|---|
어느 주말 (0) | 2020.04.18 |
오늘 배운 내용 (0) | 2020.04.17 |
자바 스터디 (0) | 2018.10.30 |
오늘 임시 - python flask (0) | 2018.10.25 |
'한줄 일기' 카테고리의 다른 글
자전거 여행 (중동 => 선유도 => 중동) (0) | 2020.07.19 |
---|---|
청계천 (0) | 2020.04.18 |
오늘 배운 내용 (0) | 2020.04.17 |
자바 스터디 (0) | 2018.10.30 |
오늘 임시 - python flask (0) | 2018.10.25 |
elasticsearch index mapping 에 관한 생각
보통 인덱스를 생성할 때 반드시 인덱스 매핑을 먼저 정의할 것을 권유한다. 매핑 정의서가 있어야 유지 보수가 용이하기 때문이다.
매핑 타입에 맞지 않는 document 를 insert 할 시 어떤 일이 발생하는지 확인해보겠다.
1] 인덱스 정의
#!/bin/bash curl -X PUT 'http://:9200/kim?pretty' -H 'Content-Type: application/json' -d' { "settings" : { "number_of_shards" : 3, "number_of_replicas" : 1 }, "mappings" : { "properties" : { "x" : {"type" : "integer"} } } }' |
2] 데이터 타입에 맞는 doc를 넣는 경우
#!/bin/bash curl -X POST 'http://:9200/kim/_doc/1' -H 'Content-Type: application/json' -d' { "x": 10 }' |
{"_index":"kim","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":0,"_primary_term":1}
|
3] 데이터 타입에 맞지 않는 doc를 넣는 경우
#!/bin/bash curl -X POST 'http://:9200/kim/_doc/2' -H 'Content-Type: application/json' -d' { "x": "hello world" }' |
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [x] of type [integer] in document with id '2'"}],"type":"mapper_parsing_exception","reason":"failed to parse field [x] of type [integer] in document with id '2'","caused_by":{"type":"number_format_exception","reason":"For input string: \"hello world\""}},"status":400} |
4] 결론 : 인덱스를 생성하기 전에 매핑을 정의하는 것이 정신건강에 좋을 꺼라 생각한다.
'ELK > elasticsearch' 카테고리의 다른 글
elasticsearch term query (0) | 2020.12.22 |
---|---|
3노드 클러스터 엘라스틱서치 ( elasticsearch 3node) (0) | 2020.05.09 |
logstash ruby syntax (0) | 2020.04.14 |
logstash file stdin (0) | 2020.04.14 |
보안 적용된 elasticsearch에 쿼리 (0) | 2020.03.22 |
[+] 개발기와 운영기는 거울에 비친 것 처럼 주석하나까지도 똑같이 맞춰야 한다.
[+] 내일 할일에 대한 목록을 미리 가지고 있어라
'한줄 일기' 카테고리의 다른 글
청계천 (0) | 2020.04.18 |
---|---|
어느 주말 (0) | 2020.04.18 |
자바 스터디 (0) | 2018.10.30 |
오늘 임시 - python flask (0) | 2018.10.25 |
2018_10_23 공부 내용 (0) | 2018.10.23 |
21대 국회의원 선거 크롤링
https://search.naver.com/search.naver?where=nexearch&sm=tab_etc&query=%ED%88%AC%ED%91%9C%EC%9C%A8
import requests
import urllib
import json
from bs4 import BeautifulSoup
import time
from elasticsearch import Elasticsearch
class Poll():
def __init__(self):
self._url = "https://search.naver.com/search.naver"
self._params = {"sm": "top_hty", "fbm": 0, "ie": "utf8"}
self._cllect_time = time.strftime("%Y%m%d%H%M%S", time.localtime())
self._total_data = list()
self._es = Elasticsearch (hosts=["http://", "http://", "http://"])
def url_req(self):
param_encode = urllib.parse.urlencode (self._params) +"&query={}".format("이시각 투표율")
url = self._url + "?" + param_encode
print (url)
session = requests.Session()
try:
html = session.get(url)
except:
print("요청 에러{}".format(self.total_data))
pass
else:
if html.status_code == 200 and html.ok:
bs_obj = BeautifulSoup(html.text, "html.parser")
print(bs_obj.title.string)
graph_view = bs_obj.select_one("ul.graph_view")
v2_list = graph_view.select("li.v2 > a")
for v in v2_list:
locals_name = v.select_one("strong.num_standard").string
percentages = v.select_one("span.graph_bar > span.num > span.num_data2").text
d = {"name": locals_name, "value": percentages[:-1], "cllct": self._cllect_time}
self._total_data.append(d)
if len(self._total_data) != 0:
#
# 데이터 파일 생성
#
self.mk_ndjson()
def mk_ndjson(self):
with open("/home/elastic/Desktop/nd_json_data/polling_{}.json".format(self._cllect_time), "a", encoding="utf-8") as f:
for i in range(0, len(self._total_data)):
f.write(json.dumps(self._total_data[i], ensure_ascii=False))
if i != len(self._total_data)-1:
f.write("\n")
f.close()
def __del__(self):
print("=============================================")
print("끝 : {}".format(time.strftime("%Y%m%d %H:%M:%S")))
if __name__ == "__main__":
print("=============================================")
print("시작 : {}".format(time.strftime("%Y%m%d %H:%M:%S")))
p = Poll()
p.url_req()
'언어 > python' 카테고리의 다른 글
코로나 데이터 수집 (파이썬) (0) | 2020.07.18 |
---|---|
네이버 python 지식인 답변 (0) | 2020.06.06 |
pdf 변환 (0) | 2019.12.18 |
python으로 pdf 파일 read (0) | 2019.12.08 |
백준 2108 (0) | 2019.12.08 |
logstash plugin install
logstash 에 내가 필요한 플러그인을 추가해보자
우선 내가 찾는 플러그인이 있는지 먼저 search
경로 : /bin $ ./logstash-plugin list elastic logstash-filter-elasticsearch logstash-input-elasticsearch logstash-output-elastic_app_search logstash-output-elasticsearch |
플러그인을 찾았으면 설치를 진행한다.
$ ./logstash-plugin install logstash-output-elasticsearch Validating logstash-output-elasticsearch Installing logstash-output-elasticsearch Installation successful |
체크
./logstash-plugin list |
테스트
input { stdin { codec => "json" } }
output { elasticsearch { hosts => ["http://192.168.42.11:9200", "http://192.168.42.11:9201", "http://192.168.42.11:9202"] index => "kim_1" } } |
'ELK > logstash' 카테고리의 다른 글
logstash file json absolute path (0) | 2020.06.17 |
---|---|
logstash input-plugin (elasticsearch) (0) | 2020.05.12 |
logstash + app-search (0) | 2019.12.10 |
logstash + python (0) | 2019.01.12 |
logstash - mysql - elasticsearch 연동 (0) | 2019.01.06 |
linux 환경변수
매번 해당 실행 프로그램의 경로를 절대 경로로 잡아서 실행하기 귀찮을 때가 있다. 환경변수를 잡아주면 해당 프로그램을 편하게 사용할 수 있다.
경로
vi ~/.bashrc |
내용
export PATH="/opt/logstash-7.0.0/bin:$PATH" |
적용
source ~/.bashrc |
logstash ruby syntax
logstash conf 파일 안쪽에서 프로그래밍 언어 처럼 조건문을 넣어야 할 경우가 있다 그럴 경우 ruby 문법을 사용하여 넣으면 된다.
[ logstash conf 파일 ]
input { stdin { codec => "json" } }
filter { mutate { remove_field => ["host", "@timestamp", "@version"] } }
output { if [name] == "kimjunhyeon" { stdout {} } } |
[ json 파일 ]
{"name": "kimjunhyeon"} {"name": "LeeJung"} |
[ 실행 ]
$ logstash -f basic_02.conf < test.json |
[ 결과 ]
'ELK > elasticsearch' 카테고리의 다른 글
3노드 클러스터 엘라스틱서치 ( elasticsearch 3node) (0) | 2020.05.09 |
---|---|
elasticsearch index mapping 에 관한 생각 (0) | 2020.04.17 |
logstash file stdin (0) | 2020.04.14 |
보안 적용된 elasticsearch에 쿼리 (0) | 2020.03.22 |
reindex query shellscript array (0) | 2020.02.03 |
logstash file stdin
logstash -f xxxx.conf 로 실행을 하면 언제 업무를 끝마쳤는지 알기 쉽지 않다. 그럴경우 파일을 stdin 의 redirect 값으로 던져주면 수행을 마치면 자동적으로 내려가게 된다. 구조는 다음과 같다.
logstash -f xxx.conf < yyy.json |
ㄱ] logstash conf 파일
input { stdin { codec => "json" } }
output { stdout { codec => rubydebug } } |
ㄴ] json 파일
{"name": "kimjunhyeon"} {"name": "LeeJung" |
ㄷ] 실행
$ logstash -f basic_01.conf < test.json |
'ELK > elasticsearch' 카테고리의 다른 글
elasticsearch index mapping 에 관한 생각 (0) | 2020.04.17 |
---|---|
logstash ruby syntax (0) | 2020.04.14 |
보안 적용된 elasticsearch에 쿼리 (0) | 2020.03.22 |
reindex query shellscript array (0) | 2020.02.03 |
대상 인덱스의 field 모두를 fielddata true로 변환하는 방법 (0) | 2020.01.17 |