无法在 ElasticSearch 上加载和使用 synonym.txt 文件
Cannot load and use synonym.txt file on ElasticSearch
我正在使用以下 docker-compose.yml 创建 ElasticSearch 集群:
version: '3.3'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
container_name: elasticsearch1
environment:
...
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
- ${PWD}/data/thesaurus/output:/usr/share/elasticsearch/config/extra
ports:
- 9200:9200
networks:
- elastic
elasticsearch2:
...
volumes:
data01:
driver: local
data02:
driver: local
networks:
elastic:
driver: bridge
我的索引包含:
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1,
"index" : {
"analysis" : {
"filter" : {
"synonym" : {
"type" : "synonym",
"synonyms_path" : "extra/synonym.txt"
}
},
"analyzer" : {
"synonym" : {
"tokenizer" : "standard",
"filter" : ["lowercase", "synonym"]
}
}
}
}
当我尝试 PUT
我的数据时,我得到:
{'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'failed to build synonyms'}], 'type': 'illegal_argument_exception', 'reason': 'failed to build synonyms', 'caused_by': {'type': 'i_o_exception', 'reason': 'Is a directory'}}, 'status': 400}
有趣的是,当我 运行: docker exec elasticsearch1 cat config/extra/synonym.txt
, 我得到错误: cat: config/extra/synonym.txt: Is a directory
如何加载和使用 synonym.txt 文件?
如弹性文档中所写 - here:
The above configures a synonym filter, with a path of
analysis/synonym.txt (relative to the config location). The synonym
analyzer is then configured with the filter.
所以你替换 synonyms_path
:
"synonyms_path" : "/extra/synonym.txt"
在:
"synonyms_path" : "extra/synonym.txt"
事实证明这是 WSL 的问题 - 请参阅此处:github。com/docker/for-win/issues/2151
作为解决方法,我将 synonym.txt 放在 Windows 目录中,然后链接到它,如下所示:
volumes:
- data01:/usr/share/elasticsearch/data
- /c/QAMaker:/usr/share/elasticsearch/config/extra
注意: 我的 Windows 文件系统安装在 Windows 的 Docker 和 [=11 的 WSL 发行版上=]...如果在我的发行版中 Windows 文件系统安装在默认 /mnt/c
上,我不确定这是否可行
我正在使用以下 docker-compose.yml 创建 ElasticSearch 集群:
version: '3.3'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
container_name: elasticsearch1
environment:
...
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
- ${PWD}/data/thesaurus/output:/usr/share/elasticsearch/config/extra
ports:
- 9200:9200
networks:
- elastic
elasticsearch2:
...
volumes:
data01:
driver: local
data02:
driver: local
networks:
elastic:
driver: bridge
我的索引包含:
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1,
"index" : {
"analysis" : {
"filter" : {
"synonym" : {
"type" : "synonym",
"synonyms_path" : "extra/synonym.txt"
}
},
"analyzer" : {
"synonym" : {
"tokenizer" : "standard",
"filter" : ["lowercase", "synonym"]
}
}
}
}
当我尝试 PUT
我的数据时,我得到:
{'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'failed to build synonyms'}], 'type': 'illegal_argument_exception', 'reason': 'failed to build synonyms', 'caused_by': {'type': 'i_o_exception', 'reason': 'Is a directory'}}, 'status': 400}
有趣的是,当我 运行: docker exec elasticsearch1 cat config/extra/synonym.txt
, 我得到错误: cat: config/extra/synonym.txt: Is a directory
如何加载和使用 synonym.txt 文件?
如弹性文档中所写 - here:
The above configures a synonym filter, with a path of analysis/synonym.txt (relative to the config location). The synonym analyzer is then configured with the filter.
所以你替换 synonyms_path
:
"synonyms_path" : "/extra/synonym.txt"
在:
"synonyms_path" : "extra/synonym.txt"
事实证明这是 WSL 的问题 - 请参阅此处:github。com/docker/for-win/issues/2151
作为解决方法,我将 synonym.txt 放在 Windows 目录中,然后链接到它,如下所示:
volumes:
- data01:/usr/share/elasticsearch/data
- /c/QAMaker:/usr/share/elasticsearch/config/extra
注意: 我的 Windows 文件系统安装在 Windows 的 Docker 和 [=11 的 WSL 发行版上=]...如果在我的发行版中 Windows 文件系统安装在默认 /mnt/c