elasticsearch8.14.3 加分词
<p>elasticsearch8.14.3 加分词
目录</p>
<pre><code>├── Dockerfile
├── config
│ ├── analysis-ik
│ │ └── IKAnalyzer.cfg.xml
│ └── synonym.dic
├── data
└── docker-compose.yml</code></pre>
<p>DockerFile
主要分词下载工具地址
<code>https://release.infinilabs.com/analysis-pinyin/stable/</code></p>
<pre><code>FROM docker.elastic.co/elasticsearch/elasticsearch:8.14.3
# 安装 IK 分词器 (官方推荐方式)
RUN bin/elasticsearch-plugin install --batch \
https://get.infini.cloud/elasticsearch/analysis-ik/8.14.3
# 安装 Pinyin 分词器
RUN bin/elasticsearch-plugin install --batch \
https://release.infinilabs.com/analysis-pinyin/stable/elasticsearch-analysis-pinyin-8.14.3.zip
# 创建配置目录
RUN mkdir -p /usr/share/elasticsearch/config/analysis-ik
# 复制配置文件
COPY ./config/synonym.dic /usr/share/elasticsearch/config/
COPY ./config/analysis-ik/ /usr/share/elasticsearch/config/analysis-ik/</code></pre>
<p>docker-compose.yml</p>
<pre><code>version: &quot;3.8&quot;
services:
elasticsearch:
build: .
container_name: elasticsearch-8.14.3
environment:
- discovery.type=single-node
- ES_JAVA_OPTS=-Xms2g -Xmx2g
- ELASTIC_PASSWORD=youpassword
- xpack.security.enabled=true
ulimits:
memlock:
soft: -1
hard: -1
ports:
- &quot;9200:9200&quot;
- &quot;9300:9300&quot;
volumes:
- ./data:/usr/share/elasticsearch/data
networks:
- es_net
healthcheck:
test:
[
&quot;CMD-SHELL&quot;,
&quot;curl --silent --fail -u elastic:yourpassword http://localhost:9200/_cluster/health || exit 1&quot;,
]
interval: 30s
timeout: 10s
retries: 3
networks:
es_net:
driver: bridge
volumes:
data:
driver: local
</code></pre>
<p>vim config/analysis-ik/IKAnalyzer.cfg.xml</p>
<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE properties SYSTEM &quot;http://java.sun.com/dtd/properties.dtd&quot;&gt;
&lt;properties&gt;
&lt;comment&gt;IK Analyzer 扩展配置&lt;/comment&gt;
&lt;entry key=&quot;ext_dict&quot;&gt;&lt;/entry&gt;
&lt;entry key=&quot;ext_stopwords&quot;&gt;&lt;/entry&gt;
&lt;entry key=&quot;remote_ext_dict&quot;&gt;&lt;/entry&gt;
&lt;entry key=&quot;remote_ext_stopwords&quot;&gt;&lt;/entry&gt;
&lt;entry key=&quot;synonyms_path&quot;&gt;synonym.dic&lt;/entry&gt;
&lt;/properties&gt;</code></pre>
<p>vim config/synonym.dic</p>
<pre><code>北京, 北京市, 北平
中国, 中华人民共和国</code></pre>