검색결과 리스트
프로그래밍/검색에 해당되는 글 29건
- 2019.09.30 elasticsearch 7.3 설치하기
- 2019.03.23 네이버 뉴스 검색 API
- 2018.12.18 elasticsearch 색인 오류 : type":"illegal_argument_exception","reason":"unknown setting [index.mapping._doc.properties.building_type.type]
- 2018.11.12 elasticsearch 6.2 mapping 하기 (1)
- 2018.10.03 elasticsearch 6.3.2 bulk 색인하기 - 색인에러 : Rejecting mapping update to [index name ] as the final mapping would have more than 1 type (2)
- 2018.10.03 elastic search 6.3.2 bulk 색인하기 - 에러 메세지 없이 종료되는 이슈
- 2017.08.14 elasticsearch - high disk watermark exceeded on one or more nodes, rerouting shards
- 2017.08.01 kibana 5 query sample (1)
- 2017.05.22 kibana 5.1.2 discover /visualize 탭에서 전체 필드가 보이지 않을 때
- 2017.05.21 elasticsearch 5.1 관련 설정 변경 - max file descriptors, max_map_count
글
elasticsearch 7.3 설치하기
elasticsearch 7.3 설치하기
이 포스팅에는 주기적으로 elasticsearch 설치하기 포스팅이 올라온다.
가끔씩 검색 엔진 사용할 일이 있는데 그때마자 버전이 몇 개씩이나 올라가 있어서 결국 새로 설치하기 때문이다;;
일단 7 버전의 주요 변화는 한국어 형태분석기가 내장되었다고 하면서
기존에 썼던 은전 한잎 플러그인이 더이상 호환이 안된다고 한다.
그럼 일단 다운로드 받아서 실행해보자.
버전별로 다운로드 받기
https://www.elastic.co/kr/downloads/past-releases
문서 : https://www.elastic.co/guide/en/elasticsearch/reference/7.3/targz.html
wget "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz"
tar zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz
wget "https://artifacts.elastic.co/downloads/kibana/kibana-7.3.2-linux-x86_64.tar.gz"
tar zxvf kibana-7.3.2-linux-x86_64.tar.gz
jvm.options
#-Xms1g
#-Xmx1g
-Xms10g
-Xmx10g
./elasticsearch 를 실행시키자 아래와 같은 오류가 나온다.
이번엔 설정 방법도 달라졌나보다;;
[2019-09-30T20:12:48,973][INFO ][o.e.b.BootstrapChecks ] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes 셋 중에 하나는 세팅하라고 해서
가이드 문서를 따라 seed_hosts 를 아래와 같이 설정해봤다.
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
그렇지만 이제 warning 메세지가 ㅠㅠ
[2019-09-30T20:39:00,499][WARN ][o.e.c.c.ClusterFormationFailureHelper] [dd] master not discovered yet, this node has not previously joined a bootstrapped (v7+) cluster, and [cluster.initial_master_nodes] is empty on this node: have discovered [{dd}{FI-RklyNRN-xTlMDTDBgSA}{m592KpzdSTiLMt9RkycrdA}{ ... ; discovery will continue using [127.0.0.1:9300, [::1]:9300] from hosts providers and .... {121.78.145.40}{121.78.145.40:9300}{dim}{ml.machine_memory=135097606144, xpack.installed=true, ml.max_open_jobs=20}] from last-known cluster state; node term 0, last-accepted version 0 in term 0
결국 검색해서 initial_master_nodes 까지 설정한 후에야 제대로 시작할 수 있었다.
참고: https://linuxacademy.com/community/show/36639-elasticsearch-yml-changes-70/
node.name: master1
참고: https://linuxacademy.com/community/show/36639-elasticsearch-yml-changes-70/
# curl 'localhost:9200'
{
"name" : "master1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "EgSc9q3mSC2URKZWBZC4FQ",
"version" : {
"number" : "7.3.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "1c1faf1",
"build_date" : "2019-09-06T14:40:30.409026Z",
"build_snapshot" : false,
"lucene_version" : "8.1.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
https://www.elastic.co/guide/en/elasticsearch/reference/7.3/discovery-settings.html
nori :
https://www.elastic.co/guide/en/elasticsearch/plugins/6.4/analysis-nori.html
설정
트랙백
댓글
글
네이버 뉴스 검색 API
네이버에서 제공하는 뉴스 검색 API 기본 정보를 저장해보았습니다.
https://developers.naver.com/docs/search/news/
하루에 25000건 까지 사용이 가능합니다.
간단하게 작성했던 포스팅인데 지금도 가끔씩 검색 유입이 있어서
예전에 뉴스 검색 crawler 작성해서 github에 올려두었던 것 추가합니다.
php로 작성했고 json으로 받은 결과를 csv 형태로 변환해서 저장하는 예제입니다.
https://github.com/roboreport/doc2vec-api/blob/master/data/crawler/cron_news.php
설정
트랙백
댓글
글
elasticsearch 색인 오류 : type":"illegal_argument_exception","reason":"unknown setting [index.mapping._doc.properties.building_type.type]
elasticsearch 색인 오류
색인할 때 다음과 같은 에러가 발생해서 한참 삽질 했는데
mapping 파일에서 mappings 가 아니라 mapping이라 써서 그런 거였다 ㅠㅠ
"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"unknown setting [index.mapping._doc.properties.building_type.type]
please check that any required plugins are installed, or check the breaking changes documentation for removed settings"}],
....
직접 매핑 파일을 작성 안하고 키바나에서 매핑을 복사해서
중간에 타입만 바꿔서 했더니 이런 소소한 오류가 ㅠㅠ
나중에 혹시 같은 실수를 할 까 기록해둔다.
설정
트랙백
댓글
글
elasticsearch 6.2 mapping 하기
참고: 날짜 타입 https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html
bulk 색인하기 https://www.elastic.co/guide/en/elasticsearch/guide/2.x/bulk.html
index 확인방법 https://www.elastic.co/guide/en/elasticsearch/reference/current/_exploring_your_data.html
관련 포스팅 : http://yookeun.github.io/elasticsearch/2018/03/09/elastic-mapping/
elastic search 는 dynamic mapping 또는 explicit mapping 이 있다.
dynamic mapping은 json 파일을 입력하면 자동으로 mapping type이 정해지는것이고
explicit mapping 은 필드마다 매핑 타입을 따로 지정해주는 것이다. (문서 참조)
dynamic mapping 이후 mapping 결과 확인하기
curl -XGET 'http://localhost:9200/indexname/_mapping/?pretty'
명시적 매핑 하기 (예시)
curl -v -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/indexname' --data-binary @mapping_indexname.json
명시적 매핑을 할 때 일일이 필드 이름 타이핑 하기 귀찮아서
일단 bulk index로 dynamic mapping을 한 후 위 방법으로 mapping을 확인하거나
kibana에서 mapping을 받아와서 수정하고 싶은 부분만 수정하고 있다.
dynamic mapping을 할 경우 대부분 아래 예시와 같이 text로 매핑되어있을 경우가 많은데
숫자라면 short, integer, float 등을 사용하고 키바나에서 분류를 쉽게 보고 싶으면 keyword로 해주는 것이 좋다.
숫자 타입 링크 : https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html
{
"mappings": {
"_doc": {
"properties": {
"address_jibun": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"address_road": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"anniversary": {
"type": "date"
},
"arts_ratio": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"budget_per_student": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
...
,
"student_per_teacher": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
mapping 파일 예시
{
"mappings" : {
"_doc" : {
"properties" : {
"area1" : {
"type" : "text"
},
"area2" : {
"type" : "text"
},
"areacode" : {
"type" : "keyword"
},
"area3 : {
"type" : "text"
},
"constructionyear" : {
"type" : "short"
},
"date" : {
"type" : "date"
},
"deposit" : {
"type" : "date"
}
"exclusiveusearea" : {
"type" : "float"
},
"floor" : {
"type" : "short"
},
"name" : {
"type" : "text"
},
"price" : {
"type" : "integer"
}
}
}
}
}
설정
트랙백
댓글
글
elasticsearch 6.3.2 bulk 색인하기 - 색인에러 : Rejecting mapping update to [index name ] as the final mapping would have more than 1 type
elasticsearch 6.3.2 bulk 색인하기
색인에러 : Rejecting mapping update to [index name ] as the final mapping would have more than 1 type
# curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary "@newdata.json"
{
"took" : 458,
"errors" : true,
"items" : [
{
"index" : {
"_index" : "인덱스이름",
"_type" : "28260",
"_id" : "XR1KOGYBkPZvewAAPeNi",
"status" : 400,
"error" : {
"type" : "illegal_argument_exception",
"reason" : "Rejecting mapping update to [apt] as the final mapping would have more than 1 type: [28260, 27260]"
}
}
},
에러 메세지를 문자 그대로 해석하면 mapping 이 여러개의 타입을 가지고 있어서
mapping 업데이트를 거절했다고 하는데
?????
보는 순간 이해가 안되었다.
이전 버전에는 인덱스별로 다수의 타입을 사용할 수 있었기 때문이다.
검색해보니 여기 토론에서 elasticsearch 6.0 버전에서는
index 가 multiple mapping type을 지원하지 않는다고 한다.
아래 6.0 버전의 변화에서도 아래와 같이 설명이 되고 있다.
Multiple mapping types are not supported in indices created in 6.0
The ability to have multiple mapping types per index has been removed in 6.0. New indices will be restricted to a single type. This is the first step in the plan to remove mapping types altogether. Indices created in 5.x will continue to support multiple mapping types.
참고: https://www.elastic.co/guide/en/elasticsearch/reference/6.0/breaking-changes-6.0.html
이번 포스팅에서는 이유를 좀 더 설명하고 있긴 하지만
결론은 이제 하나의 index 는 하나의 타입만 가진다는 것이다.
"new indices will only allow a single type"
참고: https://www.elastic.co/blog/index-type-parent-child-join-now-future-in-elasticsearch
설정
트랙백
댓글
글
elastic search 6.3.2 bulk 색인하기 - 에러 메세지 없이 종료되는 이슈
elasticsearch 6.3 버전을 새로 받아 설치 완료하고 bulk index 준비를 하였다.
기존 버전과 좀 차이가 있는 것 같아 아래 문서를 참고로 하였다.
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
-H 로 content type을 명시해주는 것이 예전 bulk 색인과 차이점이 있는 것 같았다.
curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary "@check"
터미널에 실행을 했는데 아무 메세지가 나오지 않고 그대로 종료된다.
???
색인이 되고 있는지 확인하기 위해 아래 명령어로 index를 확인해보니
추가된 index가 제대로 나오지 않는다 -_-;
# curl "localhost:9200/_cat/indices?v"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .kibana hc-a2DLVSPWDNUsA0NobNA 1 0 1 0 4kb 4kb
문서를 확인해보니 ^M 문자가 처음에 포함되어 있다.
그게 원인인가 싶어 dos2unix 와 sed 로 빈 문자열로 정리하고
다시 색인을 하니 제대로 작동하였다.
# dos2unix check
# sed -i '/^$/d' check
# curl -H 'Content-Type: application/json' -XPOST 'http://localhost:9200/_bulk' --data-binary @check
# curl "localhost:9200/_cat/indices?v"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open hindex UK5ypE_JSWKgtJ0Ab7-9nw 5 1 49 0 82.1kb 82.1kb
green open .kibana hc-a2DLVSPWDNUsA0NobNA 1 0 1 0 4kb 4kb
경제 지표 인덱스를 시험적으로 생성했으니
이제 다른 데이터도 색인을 하려고 했는데 처음 보는 에러가 발생했다.
1년만에 엘라스틱 검색을 사용하니 많은 것들이 변한 것 같다 ; - ;
그 문제는 다음 포스팅에 이어서...
설정
트랙백
댓글
글
elasticsearch - high disk watermark exceeded on one or more nodes, rerouting shards
어느날 elasticsearch 로그를 보고 있는데 아래와 같은 로그가 찍히고 있었다.
[2016-08-02 00:42:52,125][INFO ][cluster.routing.allocation.decider] [Fateball] high disk watermark exceeded on one or more nodes, rerouting shards
[2016-08-02 00:43:22,125][WARN ][cluster.routing.allocation.decider] [Fateball] high disk watermark [90%] exceeded on [Fateball] free: 33gb[7%], shards will be relocated away from this node
elasticsearch는 shard를 node에 배치할 때 (재배치 포함) 디스크 여유 공간을 검사하는데
그 때 미리 정해놓은 여유공간이 부족하면 이 node에 더이상 새 shard 를 배치하고 않고 위와 같은 경고 메세지를 찍는다고 한다.
이 기준을 watermark(수위)라고 표시 하는데 low 와 high로 따로 설정할 수 있다.
홍수가 났을 때 low watermark 부터 넘어가고 high watermark에 도달하는 것을 생각하면 된다.
참고로 low disk watermark 에러 메세지
[2017-08-14T15:45:31,688][INFO ][o.e.c.r.a.DiskThresholdMonitor] [BydL6N7] low disk watermark [85%] exceeded on [BydL6N7iRhu4YisM75Lirw][BydL6N7][/home/elasticsearch-5.1.1/data/nodes/0] free: 59.2gb[14.9%], replicas will not be assigned to this node
참고로 low watermark 기본 설정은 85%, high watermark 기본 설정은 90%이다.
즉 서버 디스크가 90% 차있는 상황 OTL
이런 경고가 뜨면 상황에 따라 설정을 변경하거나 node를 늘리거나 디스크를 정리하라고 가이드 하고 있는데
일단 디스크를 정리해야 겠다 -_-;
참고로 설정 변경 방법은 아래와 같다.
PUT /_cluster/settings
{
"transient": {
"cluster.routing.allocation.disk.watermark.low": "80%",
"cluster.routing.allocation.disk.watermark.high": "50gb",
"cluster.info.update.interval": "1m"
}
}
참고: https://www.elastic.co/guide/en/elasticsearch/reference/current/disk-allocator.html
https://books.google.co.kr/books?id=oV4dDAAAQBAJ&pg=PA191&lpg=PA191&dq=high+disk+watermark+exceeded+on+one+or+more+nodes&source=bl&ots=NO8bB2bcR2&sig=cq17f8TFQ6W43cXLuyZQNoDyYpE&hl=ko&sa=X&ved=0ahUKEwi27NHg_KHOAhULl5QKHYKsAWw4HhDoAQghMAE#v=onepage&q=high%20disk%20watermark%20exceeded%20on%20one%20or%20more%20nodes&f=false
설정
트랙백
댓글
글
kibana 5 query sample
기본적으로 kinana Discover탭의 query 창에서 검색어를 입력하면
모든 필드에 대해 검색을 수행하게 됩니다.
필드에 대한 검색을 하고 싶다면 필드:검색어 를 입력을 하면 됩니다.
아래는 필드 검색 질의에 대한 예시들 모음입니다.
영어 사용하는 사람 검색
lang:en
언어가 e로 시작되는 사람 검색
lang: e*
나이가 20이 아닌 사람 검색
-age:20
20살부터 30살까지 나이인 사람 검색
age: [20 TO 30]
1살이거나 2살인 사람 검색
age: [1 2]
나이가 10살 이상이면서 20미만인 사람 검색
age: [>=10 AND < 20]
2014년도에서 2017년 사이의 거래이면서
가격은 10000 이하이거나 20000 이상 에서 30000 이하.
year:[2014 TO 2107 ] AND ( price:[* TO 10000 ] OR price:[20000 TO 30000] )
- DATE 타입인 필드들 검색-
2012년 1월 1일 이전에 태어난 사람 검색
date: [* TO 2012-01-01]
2012-01-01에서 2012-12-31일 사이에 태어난 사람 검색
date: [2012-01-01 TO 2012-12-31]
필드 검색어 사이에 Boolean 수식 (AND OR NOT )을 사용하는 것도 역시 가능합니다.
status:[400 TO 499] AND (extension:php OR extension:html).
Boolean 수식을 입력하지 않고 검색어를 나열하면
기본적인 OR 검색으로 검색이 수행됩니다.
대문자가 아닌 소문자를 사용하면
수식으로 인식이 되지 않으니 유의합시다!
참고: https://www.elastic.co/guide/en/kibana/current/search.html
설정
트랙백
댓글
글
kibana 5.1.2 discover /visualize 탭에서 전체 필드가 보이지 않을 때
kibana 5.1 설치하고 discover 탭을 열어서 설정하려고 하니
전체 필드 이름이 보이지 않는다 왜 -_-?
검색해보니 키바나 기본 설정이 문서에 존재하는 필드만 보인다고 한다.
아래 톱니바퀴에서 Hide Missing Fields 옵션의 체크를 풀어주면 전체 필드가 보인다.
그런데 필드 값을 클릭해도 옆에 데이터가 나오지 않는다 ( ... )
왜 특정 필드들만 인덱싱 된 결과에 없는지 확인을 해보기 위해 Management 탭으로 이동을 해보았다.
나타나지 않는 필드들은 aggregatable 속성에 표시가 되지 않고 있었다.
문서를 참조해보니 fielddata 옵션이 설정이 되어있어야
aggregatable 속성이 표시되면서 kibana에서 visualize 기능을 사용할 수 있다고 한다.
...
"title" : {
"type" : "string",
"fielddata": true
},
"body" : {
"type" : "string",
"fielddata": true
},
...
매핑 파일을 바꾸고 다시 색인을 해보니 아래와 같이 속성이 변경되고
예전과 같이 kibana의 탭에서 해당 속성에 대한 통계 기능을 사용할 수 있게 되었다 : )
설정
트랙백
댓글
글
elasticsearch 5.1 관련 설정 변경 - max file descriptors, max_map_count
elasticsearch를 시작하고 로그를 확인하니 아래 경고 메세지가 있어
관련 부분을 수정하고 기록으로 남겨둔다.
[2017-05-21T15:55:37,569][WARN ][o.e.b.BootstrapCheck ] [BydL6N7] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2017-05-21T15:55:37,569][WARN ][o.e.b.BootstrapCheck ] [BydL6N7] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
max file descriptors 변경
/etc/security/limits.conf 파일의 내용을 수정해야 한다.
nofile은 해당 사용자(그룹)이 오픈할 수 있는 최대 파일 개수를 의미한다.
/etc/security/limits.conf 값은 새로운 session 부터 영향을 끼치기 때문에
파일 설정을 변경하고 재로그인을하거나 새로운 세션으로 다시 접속하면
해당 설정이 변경된 것을 확인할 수 있다.
참고로 root user 는 * wildcard 에 속하지 않으니
root user 는 따로 설정해줘야한다.
# 전체 user에게 같은 설정을 하려면 * 을 사용한다
* hard nofile 70000
* soft nofile 70000
root hard nofile 70000
root soft nofile 70000
# 특정 user (예: mysql)에기만 설정을 하려면
mysql hard nofile 70000
mysql soft nofile 70000
만약 설정을 변경하였는데 ulimit -a 해도 동일한 결과가 나온다면
/etc/pam.d/su 의 아래 라인을 코멘트 아웃해야한다.
limits.conf 는 pam_limits.so가 사용하는 설정값이라
/etc/pam.d/su에서 사용되도록 설정되었는지 확인해야한다.
# Sets up user limits, please uncomment and read /etc/security/limits.conf
# to enable this functionality.
# (Replaces the use of /etc/limits in old login)
session required pam_limits.so
vc.max_map_count 설정 변경
/etc/sysctl.conf에서 vm.max_map_count=262144 라인을 추가한다.
현재 로그인된 시스템에서 설정을 변경하려면 아래 명령어를 사용한다.
sysctl -w vm.max_map_count=262144
The vm_map_max_count setting should be set permanently in /etc/sysctl.conf:
vi /etc/sysctl.conf
vm.max_map_count=262144
-----
sysctl -w vm.max_map_count=262144