Skip to content

Commit eabaaaf

Browse files
committed
update README.md
对 use_smart 做详细说明。
1 parent 664e2b9 commit eabaaaf

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,52 @@ Or
6565
index.analysis.analyzer.ik.type : "ik"
6666
```
6767
68-
you can set your prefer segment mode,default `use_smart` is false.
68+
#### 以上两种配置方式的区别:
69+
70+
1、第二种方式,只定义了一个名为 ik 的 analyzer,其 use_smart 采用默认值 false
71+
72+
2、第一种方式,定义了三个 analyzer,分别为:ik、ik_max_word、ik_smart,其中 ik_max_word 和 ik_smart 是基于 ik 这个 analyzer 定义的,并各自明确设置了 use_smart 的不同值。
73+
74+
3、其实,ik_max_word 等同于 ik。ik_max_word 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合;而 ik_smart 会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”。
75+
76+
因此,建议,在设置 mapping 时,用 ik 这个 analyzer,以尽可能地被搜索条件匹配到。
77+
78+
不过,如果你想将 /index_name/_analyze 这个 RESTful API 做为分词器用,用来提取某段文字中的主题词,则建议使用 ik_smart 这个 analyzer:
79+
80+
```
81+
POST /hailiang/_analyze?analyzer=ik_smart HTTP/1.1
82+
Host: localhost:9200
83+
Cache-Control: no-cache
84+
85+
中华人民共和国国歌
86+
```
87+
88+
返回值:
89+
90+
```json
91+
{
92+
"tokens" : [ {
93+
"token" : "中华人民共和国",
94+
"start_offset" : 0,
95+
"end_offset" : 7,
96+
"type" : "CN_WORD",
97+
"position" : 1
98+
}, {
99+
"token" : "国歌",
100+
"start_offset" : 7,
101+
"end_offset" : 9,
102+
"type" : "CN_WORD",
103+
"position" : 2
104+
} ]
105+
}
106+
```
107+
108+
另外,可以在 elasticsearch.yml 里加上如下一行,设置默认的 analyzer 为 ik:
109+
110+
```yaml
111+
index.analysis.analyzer.default.type : "ik"
112+
```
113+
69114
70115
### Mapping Configuration
71116

0 commit comments

Comments
 (0)