Commit 30f2a10b6af259b8b6b81a2095894006452a7e0e

Authored by tangwang
1 parent ff9efda0

ansj -> ik

docs/ES/ES_8.18/1_ES配置和使用.md
@@ -108,10 +108,10 @@ labelId_by_skuId_essa_* essa商品标签,区域ID标识 @@ -108,10 +108,10 @@ labelId_by_skuId_essa_* essa商品标签,区域ID标识
108 #### 分词相关 108 #### 分词相关
109 ```bash 109 ```bash
110 # 索引分词 110 # 索引分词
111 -GET /_cat/ansj?text=14寸第4代真眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝&type=index_ansj 111 +GET /_cat/ansj?text=14寸第4代真眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝&type=index_ik
112 112
113 # 查询分词 113 # 查询分词
114 -GET /_cat/ansj?text=14寸第4代真眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝&type=query_ansj 114 +GET /_cat/ansj?text=14寸第4代真眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝&type=query_ik
115 115
116 # 查看配置 116 # 查看配置
117 GET /_cat/ansj/config 117 GET /_cat/ansj/config
@@ -128,7 +128,7 @@ GET /goods/_search @@ -128,7 +128,7 @@ GET /goods/_search
128 #### 1. 查看字段分词结果 128 #### 1. 查看字段分词结果
129 ```bash 129 ```bash
130 # 查看中文名称分词结果 130 # 查看中文名称分词结果
131 -GET /_cat/ansj?text=14寸第4代真眼珠实身冰雪公仔带手动大推车&type=index_ansj 131 +GET /_cat/ansj?text=14寸第4代真眼珠实身冰雪公仔带手动大推车&type=index_ik
132 132
133 # 查看英文名称分词结果 133 # 查看英文名称分词结果
134 GET /_cat/ansj?text=14 inch 4th generation real eye snow doll with manual cart&type=standard 134 GET /_cat/ansj?text=14 inch 4th generation real eye snow doll with manual cart&type=standard
docs/ES/ES_8.18/3_ansj分词插件安装.md
@@ -20,14 +20,14 @@ mvn package @@ -20,14 +20,14 @@ mvn package
20 ./bin/elasticsearch-plugin install https://github.com/NLPchina/elasticsearch-analysis-ansj/releases/download/v8.7.0/elasticsearch-analysis-ansj-8.7.0.0-release.zip 20 ./bin/elasticsearch-plugin install https://github.com/NLPchina/elasticsearch-analysis-ansj/releases/download/v8.7.0/elasticsearch-analysis-ansj-8.7.0.0-release.zip
21 21
22 测试: 22 测试:
23 -kibana中 : GET /_cat/ansj?text=中国&type=index_ansj 23 +kibana中 : GET /_cat/ansj?text=中国&type=index_ik
24 或者: 24 或者:
25 -curl -X GET "http://localhost:9200/_cat/ansj?text=中国&type=index_ansj" 25 +curl -X GET "http://localhost:9200/_cat/ansj?text=中国&type=index_ik"
26 26
27 27
28 curl -X GET "http://localhost:9200/_cat/ansj?pretty" -H 'Content-Type: application/json' -d' 28 curl -X GET "http://localhost:9200/_cat/ansj?pretty" -H 'Content-Type: application/json' -d'
29 { 29 {
30 - "type": "index_ansj", 30 + "type": "index_ik",
31 "text": "中国" 31 "text": "中国"
32 }' 32 }'
33 33
docs/ES/ES_8.18/4_索引和查询测试.md
@@ -54,7 +54,7 @@ curl -X GET "http://localhost:9200/goods/_termvectors/[DOC_ID]?fields=*&pretty" @@ -54,7 +54,7 @@ curl -X GET "http://localhost:9200/goods/_termvectors/[DOC_ID]?fields=*&pretty"
54 curl -X GET "http://localhost:9200/goods/_analyze?pretty" -H 'Content-Type: application/json' -d' 54 curl -X GET "http://localhost:9200/goods/_analyze?pretty" -H 'Content-Type: application/json' -d'
55 { 55 {
56 "text": "玩具", 56 "text": "玩具",
57 - "analyzer": "index_ansj" 57 + "analyzer": "index_ik"
58 }' 58 }'
59 59
60 60
docs/ES/ES_8.18/README__ES查询相关.md
@@ -247,22 +247,22 @@ POST spu/_analyze @@ -247,22 +247,22 @@ POST spu/_analyze
247 } 247 }
248 ``` 248 ```
249 249
250 -### query_ansj分词器 250 +### query_ik分词器
251 251
252 ```json 252 ```json
253 POST spu/_analyze 253 POST spu/_analyze
254 { 254 {
255 - "analyzer": "query_ansj", 255 + "analyzer": "query_ik",
256 "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝" 256 "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝"
257 } 257 }
258 ``` 258 ```
259 259
260 -### index_ansj分词器 260 +### index_ik分词器
261 261
262 ```json 262 ```json
263 POST spu_test/_analyze 263 POST spu_test/_analyze
264 { 264 {
265 - "analyzer": "index_ansj", 265 + "analyzer": "index_ik",
266 "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝" 266 "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝"
267 } 267 }
268 ``` 268 ```
docs/ES/ES_8.18/README__分词相关.md
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 工厂搜索 依赖于关键词召回、没有做语义召回和精排,加上语义召回和精排则成本过高,所以对分词效果仍然很依赖。badcase: q=锦鸿 无法召回 锦鸿达 3 工厂搜索 依赖于关键词召回、没有做语义召回和精排,加上语义召回和精排则成本过高,所以对分词效果仍然很依赖。badcase: q=锦鸿 无法召回 锦鸿达
4 1. 虽然商品搜索已经不强依赖于分词效果,但是工厂搜索仍然对分词效果有很大依赖,所以进行了优化。 4 1. 虽然商品搜索已经不强依赖于分词效果,但是工厂搜索仍然对分词效果有很大依赖,所以进行了优化。
5 2. 优化内容: 5 2. 优化内容:
6 - 1) index_ansj + 自定义词典(需要配置自定义词典。 不配置自定义词典的时候,index_ansj分词结果和query_ansj完全一致,配置自定义词典时,index_ansj 将 ) 6 + 1) index_ik + 自定义词典(需要配置自定义词典。 不配置自定义词典的时候,index_ik分词结果和query_ik完全一致,配置自定义词典时,index_ik 将 )
7 2) ansj自定义词典 补充属性词 7 2) ansj自定义词典 补充属性词
8 8
9 9
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 20
21 21
22 22
23 -| Query | query_ansj 分词结果 | index_ansj 分词结果 | 23 +| Query | query_ik 分词结果 | index_ik 分词结果 |
24 |---------|------------------------------------------|--------------------------------------------------| 24 |---------|------------------------------------------|--------------------------------------------------|
25 | 锦鸿达 | 锦, 鸿达 | 锦, 鸿达, 鸿, 达 | 25 | 锦鸿达 | 锦, 鸿达 | 锦, 鸿达, 鸿, 达 |
26 | 锦鸿 | 锦鸿 | 锦鸿, 锦, 鸿 | 26 | 锦鸿 | 锦鸿 | 锦鸿, 锦, 鸿 |
@@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
29 29
30 30
31 ansj 插件自定义词典补充属性词后: 31 ansj 插件自定义词典补充属性词后:
32 -| Query | query_ansj 分词结果 | index_ansj 分词结果 | 32 +| Query | query_ik 分词结果 | index_ik 分词结果 |
33 |---------|------------------------------------------|--------------------------------------------------| 33 |---------|------------------------------------------|--------------------------------------------------|
34 | 锦鸿达 | 锦, 鸿达 | 锦, 鸿达, 鸿, 达 | 34 | 锦鸿达 | 锦, 鸿达 | 锦, 鸿达, 鸿, 达 |
35 | 锦鸿 | 锦鸿 | 锦鸿, 锦, 鸿 | 35 | 锦鸿 | 锦鸿 | 锦鸿, 锦, 鸿 |
@@ -65,8 +65,8 @@ POST spu/_analyze @@ -65,8 +65,8 @@ POST spu/_analyze
65 65
66 ## ansj分词器的问题: 66 ## ansj分词器的问题:
67 67
68 -### 1. index_ansj不符合预期  
69 -index模式(type=index_ansj)不符合预期 :type=index_ansj type=query_ansj 结果永远都是一样的。 68 +### 1. index_ik不符合预期
  69 +index模式(type=index_ik)不符合预期 :type=index_ik type=query_ik 结果永远都是一样的。
70 https://github.com/NLPchina/elasticsearch-analysis-ansj/issues/235 70 https://github.com/NLPchina/elasticsearch-analysis-ansj/issues/235
71 71
72 已解决:需要配置自定义词典 72 已解决:需要配置自定义词典
@@ -75,7 +75,7 @@ https://github.com/NLPchina/elasticsearch-analysis-ansj/issues/235 @@ -75,7 +75,7 @@ https://github.com/NLPchina/elasticsearch-analysis-ansj/issues/235
75 特殊符号(减号)会跟后面的词粘连到一起,导致搜索减号后面的词,无法匹配: 75 特殊符号(减号)会跟后面的词粘连到一起,导致搜索减号后面的词,无法匹配:
76 76
77 ```bash 77 ```bash
78 -GET /_cat/ansj?text=狗狗系列-柴犬积木&type=index_ansj 78 +GET /_cat/ansj?text=狗狗系列-柴犬积木&type=index_ik
79 { 79 {
80 "name": "-柴", 80 "name": "-柴",
81 "nature": "nrf", 81 "nature": "nrf",
@@ -84,7 +84,7 @@ GET /_cat/ansj?text=狗狗系列-柴犬积木&type=index_ansj @@ -84,7 +84,7 @@ GET /_cat/ansj?text=狗狗系列-柴犬积木&type=index_ansj
84 "synonyms": null 84 "synonyms": null
85 }, 85 },
86 86
87 -GET /_cat/ansj?text=狗狗系列-哈士奇犬&type=index_ansj 87 +GET /_cat/ansj?text=狗狗系列-哈士奇犬&type=index_ik
88 { 88 {
89 "name": "-哈士奇", 89 "name": "-哈士奇",
90 "nature": "nrf", 90 "nature": "nrf",
@@ -99,15 +99,15 @@ GET /_cat/ansj?text=狗狗系列-哈士奇犬&type=index_ansj @@ -99,15 +99,15 @@ GET /_cat/ansj?text=狗狗系列-哈士奇犬&type=index_ansj
99 暂时解决办法是: 99 暂时解决办法是:
100 ```json 100 ```json
101 "analyzer": { 101 "analyzer": {
102 - "index_ansj": { 102 + "index_ik": {
103 "type": "custom", 103 "type": "custom",
104 "char_filter": ["hyphen_to_space"], 104 "char_filter": ["hyphen_to_space"],
105 - "tokenizer": "index_ansj" 105 + "tokenizer": "index_ik"
106 }, 106 },
107 - "query_ansj": { 107 + "query_ik": {
108 "type": "custom", 108 "type": "custom",
109 "char_filter": ["hyphen_to_space"], 109 "char_filter": ["hyphen_to_space"],
110 - "tokenizer": "query_ansj" 110 + "tokenizer": "query_ik"
111 } 111 }
112 } 112 }
113 ``` 113 ```
docs/常用查询 - ES.md
@@ -87,12 +87,12 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_ @@ -87,12 +87,12 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_
87 }' 87 }'
88 88
89 Curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_analyze' -H 'Content-Type: application/json' -d '{ 89 Curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_analyze' -H 'Content-Type: application/json' -d '{
90 - "analyzer": "index_ansj", 90 + "analyzer": "index_ik",
91 "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝" 91 "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝"
92 }' 92 }'
93 93
94 curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_analyze' -H 'Content-Type: application/json' -d '{ 94 curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_analyze' -H 'Content-Type: application/json' -d '{
95 - "analyzer": "query_ansj", 95 + "analyzer": "query_ik",
96 "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝" 96 "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝"
97 }' 97 }'
98 98
docs/搜索API对接指南.md
@@ -2075,8 +2075,8 @@ curl "http://localhost:6006/health" @@ -2075,8 +2075,8 @@ curl "http://localhost:6006/health"
2075 2075
2076 | 分析器 | 语言 | 描述 | 2076 | 分析器 | 语言 | 描述 |
2077 |--------|------|------| 2077 |--------|------|------|
2078 -| `index_ansj` | 中文 | 中文索引分析器(用于中文字段) |  
2079 -| `query_ansj` | 中文 | 中文查询分析器(用于中文字段) | 2078 +| `index_ik` | 中文 | 中文索引分析器(用于中文字段) |
  2079 +| `query_ik` | 中文 | 中文查询分析器(用于中文字段) |
2080 | `hanlp_index` ⚠️ TODO(暂不支持) | 中文 | 中文索引分析器(用于中文字段) | 2080 | `hanlp_index` ⚠️ TODO(暂不支持) | 中文 | 中文索引分析器(用于中文字段) |
2081 | `hanlp_standard` ⚠️ TODO(暂不支持) | 中文 | 中文查询分析器(用于中文字段) | 2081 | `hanlp_standard` ⚠️ TODO(暂不支持) | 中文 | 中文查询分析器(用于中文字段) |
2082 | `english` | 英文 | 标准英文分析器(用于英文字段) | 2082 | `english` | 英文 | 标准英文分析器(用于英文字段) |
docs/系统设计文档v1.md
@@ -89,7 +89,7 @@ @@ -89,7 +89,7 @@
89 - **BOOLEAN**:布尔类型 89 - **BOOLEAN**:布尔类型
90 90
91 #### 分析器支持 91 #### 分析器支持
92 -- **chinese_ecommerce**:中文电商分词器(index_ansj/query_ansj 92 +- **chinese_ecommerce**:中文电商分词器(index_ik/query_ik
93 - **english**:英文分析器 93 - **english**:英文分析器
94 - **russian**:俄文分析器 94 - **russian**:俄文分析器
95 - **arabic**:阿拉伯文分析器 95 - **arabic**:阿拉伯文分析器
docs/索引字段说明v2-plan.md
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 #### 1.1 多语言文本字段 11 #### 1.1 多语言文本字段
12 12
13 - 为文本字段添加中英文双字段支持(title.zh/title.en, brief.zh/brief.en, description.zh/description.en, vendor.zh/vendor.en) 13 - 为文本字段添加中英文双字段支持(title.zh/title.en, brief.zh/brief.en, description.zh/description.en, vendor.zh/vendor.en)
14 -- 中文字段使用 `index_ansj`/`query_ansj` 分析器(对应文档中的hanlp_index/hanlp_standard) 14 +- 中文字段使用 `index_ik`/`query_ik` 分析器(对应文档中的hanlp_index/hanlp_standard)
15 - 英文字段使用 `english` 分析器 15 - 英文字段使用 `english` 分析器
16 - **暂时只填充中文字段,英文字段设为空**(不需要语言检测,每个tenant的语言预先知道) 16 - **暂时只填充中文字段,英文字段设为空**(不需要语言检测,每个tenant的语言预先知道)
17 17
indexer/ANCHORS_AND_SEMANTIC_ATTRIBUTES.md
@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 "qanchors": { 22 "qanchors": {
23 "type": "object", 23 "type": "object",
24 "properties": { 24 "properties": {
25 - "zh": { "type": "text", "analyzer": "index_ansj", "search_analyzer": "query_ansj" }, 25 + "zh": { "type": "text", "analyzer": "index_ik", "search_analyzer": "query_ik" },
26 "en": { "type": "text", "analyzer": "english" }, 26 "en": { "type": "text", "analyzer": "english" },
27 "de": { "type": "text", "analyzer": "german" }, 27 "de": { "type": "text", "analyzer": "german" },
28 "ru": { "type": "text", "analyzer": "russian" }, 28 "ru": { "type": "text", "analyzer": "russian" },
suggestion/mapping.py
@@ -6,7 +6,7 @@ from typing import Dict, Any, List @@ -6,7 +6,7 @@ from typing import Dict, Any, List
6 6
7 7
8 ANALYZER_BY_LANG: Dict[str, str] = { 8 ANALYZER_BY_LANG: Dict[str, str] = {
9 - "zh": "index_ansj", 9 + "zh": "index_ik",
10 "en": "english", 10 "en": "english",
11 "ar": "arabic", 11 "ar": "arabic",
12 "hy": "armenian", 12 "hy": "armenian",
@@ -45,7 +45,7 @@ def _completion_field(lang: str) -> Dict[str, Any]: @@ -45,7 +45,7 @@ def _completion_field(lang: str) -> Dict[str, Any]:
45 return { 45 return {
46 "type": "completion", 46 "type": "completion",
47 "analyzer": analyzer, 47 "analyzer": analyzer,
48 - "search_analyzer": "query_ansj", 48 + "search_analyzer": "query_ik",
49 } 49 }
50 return {"type": "completion", "analyzer": analyzer} 50 return {"type": "completion", "analyzer": analyzer}
51 51
@@ -72,6 +72,20 @@ def build_suggestion_mapping(index_languages: List[str]) -> Dict[str, Any]: @@ -72,6 +72,20 @@ def build_suggestion_mapping(index_languages: List[str]) -> Dict[str, Any]:
72 "number_of_shards": 1, 72 "number_of_shards": 1,
73 "number_of_replicas": 0, 73 "number_of_replicas": 0,
74 "refresh_interval": "30s", 74 "refresh_interval": "30s",
  75 + "analysis": {
  76 + "analyzer": {
  77 + "index_ik": {
  78 + "type": "custom",
  79 + "tokenizer": "ik_max_word",
  80 + "filter": ["lowercase", "asciifolding"],
  81 + },
  82 + "query_ik": {
  83 + "type": "custom",
  84 + "tokenizer": "ik_smart",
  85 + "filter": ["lowercase", "asciifolding"],
  86 + },
  87 + }
  88 + },
75 }, 89 },
76 "mappings": { 90 "mappings": {
77 "properties": { 91 "properties": {