{"id":13698049,"url":"https://github.com/NLPchina/elasticsearch-analysis-ansj","last_synced_at":"2025-05-04T00:31:05.324Z","repository":{"id":11130019,"uuid":"13492366","full_name":"NLPchina/elasticsearch-analysis-ansj","owner":"NLPchina","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-04T12:41:23.000Z","size":15530,"stargazers_count":640,"open_issues_count":31,"forks_count":190,"subscribers_count":56,"default_branch":"master","last_synced_at":"2025-04-14T16:53:25.774Z","etag":null,"topics":["ansj","ansj-elasticsearch","elasticsearch"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NLPchina.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-10-11T07:16:12.000Z","updated_at":"2025-04-04T12:41:27.000Z","dependencies_parsed_at":"2024-01-02T14:48:29.180Z","dependency_job_id":"20ab7fc1-e8ea-4def-97ef-bfac50773f57","html_url":"https://github.com/NLPchina/elasticsearch-analysis-ansj","commit_stats":null,"previous_names":[],"tags_count":203,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NLPchina%2Felasticsearch-analysis-ansj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NLPchina%2Felasticsearch-analysis-ansj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NLPchina%2Felasticsearch-analysis-ansj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NLPchina%2Felasticsearch-analysis-ansj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NLPchina","download_url":"https://codeload.github.com/NLPchina/elasticsearch-analysis-ansj/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252272944,"owners_count":21721831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansj","ansj-elasticsearch","elasticsearch"],"created_at":"2024-08-02T19:00:38.745Z","updated_at":"2025-05-04T00:31:05.310Z","avatar_url":"https://github.com/NLPchina.png","language":"Java","funding_links":[],"categories":["插件","人工智能"],"sub_categories":[],"readme":"# elasticsearch-analysis-ansj: elasticsearch 的中文分词插件\n\n# 前言\nelasticsearch-analysis-ansj 是一个基于 [ansj](https://github.com/NLPchina/ansj_seg) 分词算法 的 elasticsearch 的中文分词插件。\n\n# 编译\n```bash\nmvn package\n```\n编译成功后，将会生成打包好的插件压缩包：`target/releases/elasticsearch-analysis-ansj-\u003c版本号\u003e-release.zip`。\n\n# 安装\n## 安装命令\n在 es 安装目录下执行下面的命令安装插件：\n```bash\n./bin/elasticsearch-plugin install file:///\u003c你的路径\u003e/elasticsearch-analysis-ansj-\u003c版本号\u003e-release.zip\n```\n\n\u003e 安装完成后，会生成一个默认的配置文件： `\u003cES_HOME\u003e/config/elasticsearch-analysis-ansj/ansj.cfg.yml`，根据需要修改此文件即可。\n\n## 测试\n安装完成后，启动 es 集群。通过以下方式测试是否安装正确：  \n**方法一：**  \n通过 `kibana` 执行 `GET /_cat/ansj?text=中国\u0026type=index_ansj` 命令，测试 `index_ansj` 分词器，返回内容如下：\n```json\n{\n  \"result\": [\n    {\n      \"name\": \"中国\",\n      \"nature\": \"ns\",\n      \"offe\": 0,\n      \"realName\": \"中国\",\n      \"synonyms\": null\n    },\n    {\n      \"name\": \"中\",\n      \"nature\": \"f\",\n      \"offe\": 0,\n      \"realName\": \"中\",\n      \"synonyms\": null\n    },\n    {\n      \"name\": \"国\",\n      \"nature\": \"n\",\n      \"offe\": 1,\n      \"realName\": \"国\",\n      \"synonyms\": null\n    }\n  ]\n}\n```\n**方法二：**  \n通过 `kibana` 执行 `GET /_cat/ansj/config` 命令，获取配置文件内容如下：\n```json\n{\n  \"ambiguity\": [\n    \"ambiguity\"\n  ],\n  \"stop\": [\n    \"stop\"\n  ],\n  \"synonyms\": [\n    \"synonyms\"\n  ],\n  \"crf\": [\n    \"crf\"\n  ],\n  \"isQuantifierRecognition\": \"true\",\n  \"isRealName\": \"false\",\n  \"isNumRecognition\": \"true\",\n  \"isNameRecognition\": \"true\",\n  \"dic\": [\n    \"dic\"\n  ]\n}\n```\n\n# 使用\n+ 第一步：创建索引\n```text\nPUT /test_index?pretty\n{\n  \"settings\" : {\n    \"index\" : {\n      \"number_of_shards\" : 16,\n      \"number_of_replicas\" : 1,\n      \"refresh_interval\":\"5s\"\n    }\n  },\n  \"mappings\" : {\n    \"properties\" : {\n      \"test_field\": { \n        \"type\": \"text\",\n        \"analyzer\": \"index_ansj\",\n        \"search_analyzer\": \"query_ansj\"\n      }\n    }\n  }\n}\n```\n\n\u003e **说明：**\n\u003e + `test_index`: 用于测试的索引名称；\n\u003e + `test_field`: 用于测试的字段；\n\u003e + 指定字段的索引分词器为： `index_ansj` ；\n\u003e + 指定字段的搜索分词器为： `query_ansj` ；\n\n测试索引配置是否正确：\n```text\nPOST /test_index/_analyze\n{\n  \"field\": \"test_field\",\n  \"text\": \"中国\"\n}\n```\n\n+ 第二步：添加数据  \n```text\nPUT test_index/_bulk?refresh\n{\"create\":{ }}\n{ \"test_field\" : \"中国\" }\n{\"create\":{ }}\n{ \"test_field\" : \"中华人民共和国\" }\n{\"create\":{ }}\n{ \"test_field\" : \"中国有56个民族\" }\n{\"create\":{ }}\n{ \"test_field\" : \"中国是社会主义国家\" }\n```\n\n+ 第三步：执行搜索  \n```text\nGET test_index/_search\n{\n  \"query\": {\n    \"match\": {\n      \"test_field\": {\n        \"query\": \"中国\"\n      }\n    }\n  }\n}\n```\n\n\u003e **注意：**  \n\u003e + 上述操作语句都是在 `kibana` 的 `dev_tools` 里执行的；\n\u003e + 上述操作语句仅在 es `8.x` 版本上测试过，其它版本请根据实际情况调整。\n\n# 插件功能\n安装插件后，在 es 集群中会增加以下功能：\n\n**三个 analyzer:**\n+ index_ansj (建议索引使用)\n+ query_ansj (建议搜索使用)\n+ dic_ansj\n\n**三个 tokenizer：**\n+ index_ansj (建议索引使用)\n+ query_ansj (建议搜索使用)\n+ dic_ansj\n\n**http 接口：**\n+ /_cat/ansj: 执行分词\n+ /_cat/ansj/config: 显示全部配置\n+ /_ansj/flush/config: 刷新全部配置\n+ /_ansj/flush/dic: 更新全部词典。包括用户自定义词典,停用词典,同义词典,歧义词典,crf\n\n# 配置文件\n## 配置文件格式\n```yaml\nansj:\n  #默认参数配置\n  isNameRecognition: true #开启姓名识别\n  isNumRecognition: true #开启数字识别\n  isQuantifierRecognition: true #是否数字和量词合并\n  isRealName: false #是否保留真实词语,建议保留false\n\n  #用户自定词典配置\n  #dic: default.dic #也可以写成 file://default.dic , 如果未配置dic,则此词典默认加载\n  # http方式加载\n  #dic_d1: http://xxx/xx.dic\n  # jar中文件加载\n  #dic_d2: jar://org.ansj.dic.DicReader|/dic2.dic\n  # 从数据库中加载\n  #dic_d3: jdbc://jdbc:mysql://xxxx:3306/ttt?useUnicode=true\u0026characterEncoding=utf-8\u0026zeroDateTimeBehavior=convertToNull|username|password|select name as name,nature,freq from dic where type=1\n  # 从自定义类中加载,YourClas  extends PathToStream\n  #dic_d3: class://xxx.xxx.YourClas|ohterparam\n\n  #过滤词典配置\n  #stop: http,file,jar,class,jdbc 都支持\n  #stop_key1: ...\n\n  #歧义词典配置\n  #ambiguity: http,file,jar,class,jdbc 都支持\n  #ambiguity_key1: ...\n\n  #同义词词典配置\n  #synonyms: http,file,jar,class,jdbc 都支持\n  #synonyms_key1: ...\n```\n\n## 配置文件示例\n### 使用本地文件词库\n```yaml\nansj:\n  # 开启姓名识别\n  isNameRecognition: false\n  # 开启数字识别\n  isNumRecognition: true\n  # 是否数字和量词合并\n  isQuantifierRecognition: false\n  # 是否保留真实词语\n  isRealName: false\n  # 词典\n  dic: file:///data/elasticsearch-dic/ansj/main.dic\n  # 停词（过滤词）词典\n  stop: file:///data/elasticsearch-dic/ansj/stop.dic\n  # 歧义词词典配置\n  ambiguity: file:///data/elasticsearch-dic/ansj/ambiguity.dic\n  # 同义词词典配置\n  synonyms: file:///data/elasticsearch-dic/ansj/synonyms.dic\n```\n\n### 使用 HTTP 协议加载词库\n```yaml\nansj:\n  # 开启姓名识别\n  isNameRecognition: false\n  # 开启数字识别\n  isNumRecognition: true\n  # 是否数字和量词合并\n  isQuantifierRecognition: false\n  # 是否保留真实词语\n  isRealName: false\n  # 词典\n  dic: http://example.com/elasticsearch-dic/ansj/main.dic\n  # 停词（过滤词）词典\n  stop: http://example.com/elasticsearch-dic/ansj/stop.dic\n  # 歧义词词典配置\n  ambiguity: http://example.com/elasticsearch-dic/ansj/ambiguity.dic\n  # 同义词词典配置\n  synonyms: http://example.com/elasticsearch-dic/ansj/synonyms.dic\n```\n\n# 插件版本与 ES 版本的对应关系\n\n| plugin  |     elasticsearch|\n|---------|       -----:  |\n| 1.0.0   |     0.90.2    |\n| 1.x     |     1.x       |\n| 2.1.1   |     2.1.1     |\n| 2.3.1   |     2.3.1     |\n| 2.3.2   |     2.3.2     |\n| 2.3.3   |     2.3.3     |\n| 2.3.4   |     2.3.4     |\n| 2.3.5   |     2.3.5     |\n| 2.4.0   |     2.4.0     |\n| 2.4.1   |     2.4.1     |\n| 2.4.2   |     2.4.2     |\n| 2.4.3   |     2.4.3     |\n| 2.4.4   |     2.4.4     |\n| 2.4.5   |     2.4.5     |\n| 2.4.6   |     2.4.6     |\n| 5.0.0   |     5.0.0     |\n| 5.0.1   |     5.0.1     |\n| 5.0.2   |     5.0.2     |\n| 5.1.1   |     5.1.1     |\n| 5.1.2   |     5.1.2     |\n| 5.2.0   |     5.2.0     |\n| 5.2.1   |     5.2.1     |\n| 5.2.2   |     5.2.2     |\n| 5.3.0   |     5.3.0     |\n| 5.3.1   |     5.3.1     |\n| 5.3.2   |     5.3.2     |\n| 5.3.3   |     5.3.3     |\n| 5.4.0   |     5.4.0     |\n| 5.4.1   |     5.4.1     |\n| 5.4.2   |     5.4.2     |\n| 5.4.3   |     5.4.3     |\n| 5.5.0   |     5.5.0     |\n| 5.5.1   |     5.5.1     |\n| 5.5.2   |     5.5.2     |\n| 5.5.3   |     5.5.3     |\n| 5.6.0   |     5.6.0     |\n| 5.6.1   |     5.6.1     |\n| 5.6.2   |     5.6.2     |\n| 5.6.3   |     5.6.3     |\n| 5.6.4   |     5.6.4     |\n| 5.6.5   |     5.6.5     |\n| 5.6.6   |     5.6.6     |\n| 5.6.7   |     5.6.7     |\n| 5.6.8   |     5.6.8     |\n| 5.6.9   |     5.6.9     |\n| 5.6.10  |     5.6.10    |\n| 5.6.11  |     5.6.11    |\n| 5.6.12  |     5.6.12    |\n| 5.6.13  |     5.6.13    |\n| 5.6.14  |     5.6.14    |\n| 5.6.15  |     5.6.15    |\n| 5.6.16  |     5.6.16    |\n| 6.0.0   |     6.0.0     |\n| 6.0.1   |     6.0.1     |\n| 6.1.0   |     6.1.0     |\n| 6.1.1   |     6.1.1     |\n| 6.1.2   |     6.1.2     |\n| 6.1.3   |     6.1.3     |\n| 6.1.4   |     6.1.4     |\n| 6.2.0   |     6.2.0     |\n| 6.2.1   |     6.2.1     |\n| 6.2.2   |     6.2.2     |\n| 6.2.3   |     6.2.3     |\n| 6.2.4   |     6.2.4     |\n| 6.3.0   |     6.3.0     |\n| 6.3.1   |     6.3.1     |\n| 6.3.2   |     6.3.2     |\n| 6.4.0   |     6.4.0     |\n| 6.4.1   |     6.4.1     |\n| 6.4.2   |     6.4.2     |\n| 6.4.3   |     6.4.3     |\n| 6.5.0   |     6.5.0     |\n| 6.5.1   |     6.5.1     |\n| 6.5.2   |     6.5.2     |\n| 6.5.3   |     6.5.3     |\n| 6.5.4   |     6.5.4     |\n| 6.6.0   |     6.6.0     |\n| 6.6.1   |     6.6.1     |\n| 6.6.2   |     6.6.2     |\n| 6.7.0   |     6.7.0     |\n| 6.7.1   |     6.7.1     |\n| 6.7.2   |     6.7.2     |\n| 6.8.0   |     6.8.0     |\n| 6.8.1   |     6.8.1     |\n| 6.8.2   |     6.8.2     |\n| 6.8.3   |     6.8.3     |\n| 6.8.4   |     6.8.4     |\n| 6.8.5   |     6.8.5     |\n| 6.8.6   |     6.8.6     |\n| 6.8.7   |     6.8.7     |\n| 6.8.8   |     6.8.8     |\n| 6.8.9   |     6.8.9     |\n| 6.8.10  |     6.8.10    |\n| 6.8.11  |     6.8.11    |\n| 6.8.12  |     6.8.12    |\n| 6.8.13  |     6.8.13    |\n| 6.8.14  |     6.8.14    |\n| 6.8.15  |     6.8.15    |\n| 6.8.16  |     6.8.16    |\n| 6.8.17  |     6.8.17    |\n| 6.8.18  |     6.8.18    |\n| 6.8.19  |     6.8.19    |\n| 6.8.20  |     6.8.20    |\n| 6.8.21  |     6.8.21    |\n| 6.8.22  |     6.8.22    |\n| 6.8.23  |     6.8.23    |\n| 7.0.0   |     7.0.0     |\n| 7.0.1   |     7.0.1     |\n| 7.1.0   |     7.1.0     |\n| 7.1.1   |     7.1.1     |\n| 7.2.0   |     7.2.0     |\n| 7.2.1   |     7.2.1     |\n| 7.3.0   |     7.3.0     |\n| 7.3.1   |     7.3.1     |\n| 7.3.2   |     7.3.2     |\n| 7.4.0   |     7.4.0     |\n| 7.4.1   |     7.4.1     |\n| 7.4.2   |     7.4.2     |\n| 7.5.0   |     7.5.0     |\n| 7.5.1   |     7.5.1     |\n| 7.5.2   |     7.5.2     |\n| 7.6.0   |     7.6.0     |\n| 7.6.1   |     7.6.1     |\n| 7.6.2   |     7.6.2     |\n| 7.7.0   |     7.7.0     |\n| 7.7.1   |     7.7.1     |\n| 7.8.0   |     7.8.0     |\n| 7.8.1   |     7.8.1     |\n| 7.9.0   |     7.9.0     |\n| 7.9.1   |     7.9.1     |\n| 7.9.2   |     7.9.2     |\n| 7.9.3   |     7.9.3     |\n| 7.17.5  |     7.17.5    |\n| 7.17.7  |     7.17.7    |\n| 7.17.8  |     7.17.8    |\n| 7.17.9  |     7.17.9    |\n| 7.17.10 |     7.17.10   |\n| 7.17.11 |     7.17.11   |\n| 7.17.12 |     7.17.12   |\n| 7.17.13 |     7.17.13   |\n| 7.17.14 |     7.17.14   |\n| 7.17.15 |     7.17.15   |\n| 7.17.16 |     7.17.16   |\n| 7.17.17 |     7.17.17   |\n| 7.17.18 |     7.17.18   |\n| 7.17.19 |     7.17.19   |\n| 7.17.20 |     7.17.20   |\n| 7.17.21 |     7.17.21   |\n| 7.17.22 |     7.17.22   |\n| 7.17.23 |     7.17.23   |\n| 7.17.24 |     7.17.24   |\n| 7.17.25 |     7.17.25   |\n| 7.17.26 |     7.17.26   |\n| 7.17.27 |     7.17.27   |\n| 7.17.28 |     7.17.28   |\n| 8.3.3   |     8.3.3     |\n| 8.5.3   |     8.5.3     |\n| 8.6.0   |     8.6.0     |\n| 8.6.1   |     8.6.1     |\n| 8.6.2   |     8.6.2     |\n| 8.7.0   |     8.7.0     |\n| 8.7.1   |     8.7.1     |\n| 8.8.0   |     8.8.0     |\n| 8.8.1   |     8.8.1     |\n| 8.8.2   |     8.8.2     |\n| 8.9.0   |     8.9.0     |\n| 8.9.1   |     8.9.1     |\n| 8.9.2   |     8.9.2     |\n| 8.10.0  |     8.10.0    |\n| 8.10.1  |     8.10.1    |\n| 8.10.2  |     8.10.2    |\n| 8.10.3  |     8.10.3    |\n| 8.10.4  |     8.10.4    |\n| 8.11.0  |     8.11.0    |\n| 8.11.1  |     8.11.1    |\n| 8.11.2  |     8.11.2    |\n| 8.11.3  |     8.11.3    |\n| 8.11.4  |     8.11.4    |\n| 8.12.0  |     8.12.0    |\n| 8.12.1  |     8.12.1    |\n| 8.12.2  |     8.12.2    |\n| 8.13.0  |     8.13.0    |\n| 8.13.1  |     8.13.1    |\n| 8.13.2  |     8.13.2    |\n| 8.13.3  |     8.13.3    |\n| 8.13.4  |     8.13.4    |\n| 8.14.0  |     8.14.0    |\n| 8.14.1  |     8.14.1    |\n| 8.14.2  |     8.14.2    |\n| 8.14.3  |     8.14.3    |\n| 8.15.0  |     8.15.0    |\n| 8.15.1  |     8.15.1    |\n| 8.15.2  |     8.15.2    |\n| 8.15.3  |     8.15.3    |\n| 8.15.4  |     8.15.4    |\n| 8.15.5  |     8.15.5    |\n| 8.16.0  |     8.16.0    |\n| 8.16.1  |     8.16.1    |\n| 8.16.2  |     8.16.2    |\n| 8.16.3  |     8.16.3    |\n| 8.17.0  |     8.17.0    |\n| 8.17.1  |     8.17.1    |\n| 8.17.2  |     8.17.2    |\n| 8.17.3  |     8.17.3    |\n| 8.17.4  |     8.17.4    |\n\n# 版权\n`elasticsearch-analysis-ansj` is licenced under the Apache License Version 2.0. See the [LICENSE](https://github.com/NLPchina/elasticsearch-analysis-ansj/blob/master/LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNLPchina%2Felasticsearch-analysis-ansj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNLPchina%2Felasticsearch-analysis-ansj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNLPchina%2Felasticsearch-analysis-ansj/lists"}