05/09
elastics search
setup docker
真心建議用 docker 安裝,編譯什麼的太累了 QQ
兩個 servcie: elastics search, kibana 視覺化 dashboard
配合 https://github.com/cscolabear/docker-dev
`docker-compose.yml
.
.
.
ELASTICSEARCH:
hostname: docker-es
build:
context: ./Dockerfiles/elasticsearch
image: cscolabear/elasticsearch:latest
environment:
- node.name=es01
- 'discovery.type=single-node'
- cluster.name=es-docker-cluster
- bootstrap.memory_lock=true
- 'http.host=0.0.0.0'
- 'transport.host=127.0.0.1'
- 'ES_JAVA_OPTS=-Xms512m -Xmx512m'
# - 'ES_JAVA_OPTS=-Xms128m -Xmx128m'
- 'xpack.security.enabled=false'
- 'ACCESS_TOKEN=e-D9WyQzxfRbpdFvFdhQ'
ports:
- '9200:9200'
- '9300:9300'
volumes:
- ./Database/elasticsearch/index:/usr/share/elasticsearch/data:delegated
- ./Dockerfiles/elasticsearch/custom-dict.txt:/usr/share/elasticsearch/config/analysis-ik/custom/custom-dict.dic:ro
- ./Dockerfiles/elasticsearch/synonym.txt:/usr/share/elasticsearch/config/analysis/synonym.txt:ro
deploy:
restart_policy:
condition: on-failure
networks:
app_net:
ipv4_address: 172.16.1.90
KIBANA:
image: kibana:7.6.2
hostname: docker-kibana
environment:
SERVER_NAME: kibana-server
ELASTICSEARCH_URL: http://127.0.0.1:9200
depends_on:
- ELASTICSEARCH
ports:
- "5601:5601"
restart: on-failure
networks:
app_net:
ipv4_address: 172.16.1.100
設定 elasticsearch 為 7.6.2,加裝 plugin: analysis-ik 中文斷字詞與 analysis-ik 繁體 config
ps: elasticsearch 大版號都是 break change,注意教學文與版本
dockerfiles
FROM elasticsearch:7.6.2
RUN ./bin/elasticsearch-plugin install -b https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip
RUN curl -fsSL 'https://github.com/sunghau/elasticsearch-analysis-ik-config-traditional-chinese/archive/master.zip' -o ik-tc.zip \
&& unzip ik-tc.zip \
&& rm ik-tc.zip \
&& mkdir -p /usr/share/elasticsearch/config/ik-tc \
&& mv elasticsearch-analysis-ik-config-traditional-chinese-master/config/ik/* /usr/share/elasticsearch/config/ik-tc \
&& rm -rf elasticsearch-analysis-ik-config-traditional-chinese-master \
&& mv /usr/share/elasticsearch/config/analysis-ik /usr/share/elasticsearch/config/analysis-ik-sc \
&& mv /usr/share/elasticsearch/config/ik-tc /usr/share/elasticsearch/config/analysis-ik
RUN rm -rf /tmp/*
USER elasticsearch
自行設定上例中的
custom-dict.txt // 斷詞表
synonym.txt // 同義表
(詳細內容後補)
ps:
自然搜尋,比較重要的是斷詞、分詞、同義字詞
上面的例子選用 IK 分詞,另有 結巴分詞可選
IK: https://github.com/medcl/elasticsearch-analysis-ik
Jieba: https://github.com/sing1ee/elasticsearch-jieba-plugin
Q & A
Q. 為何無法更新己存在的 index 設定? (需要重建)
https://www.elastic.co/blog/changing-mapping-with-zero-downtime
Q. elastics search rest api 列表
https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-apis.html
ref.
https://github.com/jimliu7434/Diary/issues/22
https://medium.com/cw-itgroup/elasticsearch-中文同義詞與自動完成-693410e68b0a
https://www.twblogs.net/a/5c879670bd9eee35fc1459ab
https://whchi.github.io/posts/setup-elasticsearch-synonym/
https://kevintsengtw.blogspot.com/2018/07/docker-compose-elasticsearch-kibana.html
斷詞來源可參考或直接用 ik 提供(初期可以不更新,如果要效果好就需要花點心力)
analysis-ik-config-traditional-chinese 繁中支援 config
簡體中文 斷字詞