'2016/05'에 해당되는 글 3건

  1. 2016.05.31 [Java] 우편번호 DB text 파일 읽기.
  2. 2016.05.24 [Elasticsearch] BoolQueryBuilder + TermsQueryBuilder 사용 시 minimum_should_match와 min_should_match
  3. 2016.05.18 [Logstash] input-http, filter-mutate,grok 샘플 config

[Java] 우편번호 DB text 파일 읽기.

ITWeb/개발일반 2016. 5. 31. 16:33

행자부나 우체국에서 도로명 주소를 제공하고 있습니다.

이 데이터들이 ISO-8859-1 로 인코딩 되어 있기 때문에 파일을 읽을 때 인코딩 타입을 잘 맞춰서 읽으셔야 한글 처리를 하실 수 있습니다.


아래는 행자부와 우체국의 도로명 주소 DB 제공 링크 입니다.


[행정자치부]

http://www.juso.go.kr/support/AddressBuild.do?menu=adrchg


[우체국]

http://www.epost.go.kr/search/zipcode/areacdAddressDown.jsp



아래는 prototype code 입니다.


[Read jibun_busan.txt]

String src = "/dump/address/jibun/201604/jibun_busan.txt";
BufferedReader br;
String line;

try {
br = new BufferedReader(
new InputStreamReader(
new FileInputStream(src), "ISO-8859-1"));

while ((line = br.readLine()) != null) {
LOG.debug("{}", new String(line.getBytes("ISO-8859-1"), "MS949"));
}

br.close();
} catch (IOException e) {
e.printStackTrace();
}


:

[Elasticsearch] BoolQueryBuilder + TermsQueryBuilder 사용 시 minimum_should_match와 min_should_match

Elastic/Elasticsearch 2016. 5. 24. 18:11

이게 또 언제 변수명이 바뀌었을까요?

버전 릴리즈 될때마다 소스코드를 다 따라 갈수가 없다 보니 이런 오류를 경험하게 되내요.


주의) min_should_match 는 java api 를 이용해서는 사용 할 수 없습니다.


[Terms Query]

이 쿼리는 field 에 여러개의 term 을 넣어서 질의 할 수 있도록 해줍니다.

그래서 기본 or 검색을 지원하고 있구요. 여기서 and 연산을 하고 싶으면 terms query 에 아래 변수 값을 지정 하셔야 합니다.


min_should_match:TERM_SIZE


OR)

curl -XGET "http://localhost:9200/_search?pretty" -d'

{

    "size": 10,

    "query" : {

        "terms": {

           "title": [

              "포니",

              "이펙트"

           ],

           "min_should_match": 1

        }                

    }

}'



AND)

curl -XGET "http://localhost:9200/_search?pretty" -d'

{

    "size": 10,

    "query" : {

        "terms": {

           "title": [

              "포니",

              "이펙트"

           ],

           "min_should_match": 2

        }                

    }

}'


[Bool Query + Terms Query]

이 쿼리는 compound query 작성을 위해 많이 사용하는 것입니다.

bool query 안에 terms query 를 섞어 사용하는 것이구요. 좀 더 and, or 연산을 다양하게 할 수 있게 해줍니다.

여기서는 miminum_should_match 를 통해서 and, or 연산을 해야 하는데 terms query 에서의 min_should_match 를 사용하지 않게 되면 정상적인 결과를 얻을 수 없게 됩니다. (아무래도 2.3.3 에서 5.0 으로 넘어가는 과도기라 그런게 아닌가 싶습니다.)

should 를 여러개 사용할 경우 miminum_should_match 설정을 하셔야 합니다.


OR)

curl -XGET "http://localhost:9200/_search?pretty" -d'

{

    "size": 10,

    "query" : {

        "bool" : {

            "should": [

               {

                   "terms": {

                      "title": [

                         "포니",

                         "이펙트"

                      ],

                      "min_should_match": "1"

                   }

               }

            ]

        }

    }

}'


AND)

curl -XGET "http://localhost:9200/_search?pretty" -d'

{

    "size": 10,

    "query" : {

        "bool" : {

            "should": [

               {

                   "terms": {

                      "title": [

                         "포니",

                         "이펙트"

                      ],

                      "min_should_match": "2"

                   }

               }

            ]

        }

    }

}'


:

[Logstash] input-http, filter-mutate,grok 샘플 config

Elastic/Logstash 2016. 5. 18. 17:48

그냥 올려봅니다.


[logstash config]

input {

  http {

    codec => json {

    }

  }

}


filter {

  mutate {

    add_filed => { "request_uri" => "%{headers[request_uri]}" }

    replace => { "message" => "input http 사용 시 headers 내부 변수 접근(nested variables)" }

  }


  grok {

    match => { "request_uri" => "%{URIPARAM:request}" }

  }

}


output {

  stdout { codec => rubydebug }

}


뭐 정말 별거 아닌고 모니터링 시스템 설계 하다가 prototype 구현을 해봐야 겠다 싶어서 대충 돌려보다 grok 에러가 발생해서 기록해 본겁니다.


[logstash http input 사용 시 출력 결과]

{

       "message" => "",

      "@version" => "1",

    "@timestamp" => "2016-05-18T07:19:36.140Z",

          "host" => "127.0.0.1",

       "headers" => {

         "request_method" => "GET",

           "request_path" => "/",

            "request_uri" => "/?message=test",

  1 input {

           "http_version" => "HTTP/1.1",

              "http_host" => "127.0.0.1:8080",

        "http_user_agent" => "curl/7.43.0",

            "http_accept" => "*/*"

    },

          "tags" => [

        [0] "_grokparsefailure"

    ]

}


: