Elastic分词插件介绍

IK分词插件

插件主页

https://github.com/medcl/elasticsearch-analysis-ik

查看插件

1
2
3
4
[elon@icloud-store elasticsearch-6.0.0]$ bin/elasticsearch-plugin list
analysis-ik
analysis-pinyin
analysis-stconvert

分词测试

创建测试索引

1
2
3
4
5
6
[elon@icloud-store logs]# curl -XPUT "http://192.168.0.103:9200/index_test?pretty=true"
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "index_test"
}

测试分词效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
[elon@icloud-store logs]# curl 'http://192.168.0.103:9200/index_test/_analyze?pretty=true' -H 'Content-Type: application/json' -d '{ "analyzer":"ik_max_word", "text":"元旦火车票开售."}'
{
"tokens" : [
{
"token" : "元旦",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "火车票",
"start_offset" : 2,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "火车",
"start_offset" : 2,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 2
},
{
"token" : "车票",
"start_offset" : 3,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 3
},
{
"token" : "开售",
"start_offset" : 5,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 4
}
]
}

[elon@icloud-store logs]# curl 'http://192.168.0.103:9200/index_test/_analyze?pretty=true' -H 'Content-Type: application/json' -d '{ "analyzer":"ik_smart", "text":"元旦火车 票开售."}'
{
"tokens" : [
{
"token" : "元旦",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "火车票",
"start_offset" : 2,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "开售",
"start_offset" : 5,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 2
}
]
}

通过对中文串的分词结果可以明显看到, ik_smart和ik_max_word两种模式的分词结果上的差异.

  • ik_max_word: 会将文本做最细粒度的拆分,比如会将“元旦火车票开售”拆分为“元旦,火车票,火车,车票,开售”,会穷尽各种可能的组合;
  • ik_smart: 会做最粗粒度的拆分,比如会将“元旦火车票开售”拆分为“元旦,火车票,开售”;

应用示例

删除索引

1
2
3
4
[wuyu@icloud-store elasticsearch-6.0.0]$ curl -XDELETE "http://192.168.0.103:9200/index_test*?pretty=true"
{
"acknowledged" : true
}

创建索引

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[elon@icloud-store logs]# curl -XPUT "http://192.168.0.103:9200/index_test?pretty=true" -H 'Content-Type: application/json' -d'
{
"index": {
"number_of_shards": "1",
"number_of_replicas": "1"
}
}'
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "index_test"
}
[elon@icloud-store elasticsearch-6.0.0]$ curl -XGET "http://192.168.0.103:9200/index_test?pretty=true"
{
"index_test" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1512990681578",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "tXNLl-JERiuIxn-g4Ip3Og",
"version" : {
"created" : "6000099"
},
"provided_name" : "index_test"
}
}
}
}

创建类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/person/_mapping?pretty=true"  -H 'Content-Type: application/json' -d'
{
"properties": {
"name": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}'
{
"acknowledged" : true
}
[elon@icloud-store elasticsearch-6.0.0]$ curl -XGET "http://192.168.0.103:9200/index_test?pretty=true"
{
"index_test" : {
"aliases" : { },
"mappings" : {
"person" : {
"properties" : {
"name" : {
"type" : "text",
"analyzer" : "ik_max_word"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1512990681578",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "tXNLl-JERiuIxn-g4Ip3Og",
"version" : {
"created" : "6000099"
},
"provided_name" : "index_test"
}
}
}
}

索引数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/person/1?pretty=true" -H 'Content-Type: application/json' -d'{"name":"元旦火车票开售."}'
{
"_index" : "index_test",
"_type" : "person",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/person/2?pretty=true" -H 'Content-Type: application/json' -d'{"name":"元旦节是公历新一年的第一天."}'
{
"_index" : "index_test",
"_type" : "person",
"_id" : "2",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/person?pretty=true" -H 'Content-Type: application/json' -d'{"name":"使用ES默认ID机制创建唯一键"}'
{
"_index" : "index_test",
"_type" : "person",
"_id" : "psZNRWABuJTmkY1Rwcoe",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1
}
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/person/2?pretty=true" -H 'Content-Type: application/json' -d'{"name":"元旦节是每年1月1号"}'
{
"_index" : "index_test",
"_type" : "person",
"_id" : "2",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}

查询数据(主键)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[elon@icloud-store elasticsearch-6.0.0]$ curl -XGET "http://192.168.0.103:9200/index_test/person/2?pretty=true"
{
"_index" : "index_test",
"_type" : "person",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"name" : "元旦节是公历新一年的第一天."
}
}
[elon@icloud-store elasticsearch-6.0.0]$ curl -XGET "http://192.168.0.103:9200/index_test/person/psZNRWABuJTmkY1Rwcoe?pretty=true"
{
"_index" : "index_test",
"_type" : "person",
"_id" : "psZNRWABuJTmkY1Rwcoe",
"_version" : 1,
"found" : true,
"_source" : {
"name" : "使用ES默认ID机制创建唯一键"
}
}

更新数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/person/2?pretty=true" -H 'Content-Type: application/json' -d'{"name":"元旦节是每年1月1号"}'
{
"_index" : "index_test",
"_type" : "person",
"_id" : "2",
"_version" : 2,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 1
}
[elon@icloud-store elasticsearch-6.0.0]$ curl -XGET "http://192.168.0.103:9200/index_test/person/2?pretty=true"
{
"_index" : "index_test",
"_type" : "person",
"_id" : "2",
"_version" : 2,
"found" : true,
"_source" : {
"name" : "元旦节是每年1月1号"
}
}

查询数据(关键词、分页、高量)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "192.168.0.103:9200/index_test/person/_search?pretty" -H 'Content-Type: application/json' -d'
{
"from" : 0,
"size" : 10,
"query": {
"match": {
"name": "元旦"
}
},
"highlight": {
"fields": {
"name": {}
}
}
}'
{
"took" : 14,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.5551721,
"hits" : [
{
"_index" : "index_test",
"_type" : "person",
"_id" : "1",
"_score" : 0.5551721,
"_source" : {
"name" : "元旦火车票开售."
},
"highlight" : {
"name" : [
"<em>元旦</em>火车票开售."
]
}
},
{
"_index" : "index_test",
"_type" : "person",
"_id" : "2",
"_score" : 0.4471386,
"_source" : {
"name" : "元旦节是每年1月1号"
},
"highlight" : {
"name" : [
"<em>元旦</em>节是每年1月1号"
]
}
}
]
}
}

Pinyin分词插件

插件主页

https://github.com/medcl/elasticsearch-analysis-pinyin

查看插件

1
2
3
4
[elon@icloud-store elasticsearch-6.0.0]$ bin/elasticsearch-plugin list
analysis-ik
analysis-pinyin
analysis-stconvert

分词测试

创建测试索引

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPUT "http://192.168.0.103:9200/index_test?pretty=true" -H 'Content-Type: application/json' -d'
{
"index" : {
"analysis" : {
"analyzer" : {
"pinyin_analyzer" : {
"tokenizer" : "mix_pinyin"
}
},
"tokenizer" : {
"mix_pinyin" : {
"type" : "pinyin",
"keep_separate_first_letter" : false,
"keep_full_pinyin" : true,
"keep_original" : true,
"limit_first_letter_length" : 16,
"lowercase" : true,
"remove_duplicated_term" : true
}
}
}
},
"number_of_shards": "3",
"number_of_replicas": "1"
}'
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "index_test"
}

[elon@icloud-store elasticsearch-6.0.0]$ curl -XGET "http://192.168.0.103:9200/index_test?pretty=true"
{
"index_test" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"number_of_shards" : "3",
"provided_name" : "index_test",
"creation_date" : "1513148861791",
"analysis" : {
"analyzer" : {
"pinyin_analyzer" : {
"tokenizer" : "mix_pinyin"
}
},
"tokenizer" : {
"mix_pinyin" : {
"lowercase" : "true",
"keep_original" : "true",
"remove_duplicated_term" : "true",
"keep_separate_first_letter" : "false",
"type" : "pinyin",
"limit_first_letter_length" : "16",
"keep_full_pinyin" : "true"
}
}
},
"number_of_replicas" : "1",
"uuid" : "uIW8o_bGTkefLEVL5mTw7w",
"version" : {
"created" : "6000099"
}
}
}
}
}

测试分词效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
[elon@icloud-store elasticsearch-6.0.0]$ curl "http://192.168.0.103:9200/index_test/_analyze?pretty=true" -H 'Content-Type: application/json' -d'{ "analyzer":"pinyin_analyzer", "text":"元旦火车票开售."}'
{
"tokens" : [
{
"token" : "yuan",
"start_offset" : 0,
"end_offset" : 1,
"type" : "word",
"position" : 0
},
{
"token" : "元旦火车票开售.",
"start_offset" : 0,
"end_offset" : 8,
"type" : "word",
"position" : 0
},
{
"token" : "ydhcpks",
"start_offset" : 0,
"end_offset" : 7,
"type" : "word",
"position" : 0
},
{
"token" : "dan",
"start_offset" : 1,
"end_offset" : 2,
"type" : "word",
"position" : 1
},
{
"token" : "huo",
"start_offset" : 2,
"end_offset" : 3,
"type" : "word",
"position" : 2
},
{
"token" : "che",
"start_offset" : 3,
"end_offset" : 4,
"type" : "word",
"position" : 3
},
{
"token" : "piao",
"start_offset" : 4,
"end_offset" : 5,
"type" : "word",
"position" : 4
},
{
"token" : "kai",
"start_offset" : 5,
"end_offset" : 6,
"type" : "word",
"position" : 5
},
{
"token" : "shou",
"start_offset" : 6,
"end_offset" : 7,
"type" : "word",
"position" : 6
}
]
}

应用示例(Ik+Pinyin)

应用示例展示IK+Pinyin集成的索引分词效果

删除索引

1
2
3
4
[elon@icloud-store elasticsearch-6.0.0]$ curl -XDELETE "http://192.168.0.103:9200/index_test*?pretty=true"
{
"acknowledged" : true
}

创建索引

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPUT "http://192.168.0.103:9200/index_test?pretty=true" -H 'Content-Type: application/json' -d'
{
"index" : {
"analysis": {
"analyzer": {
"default" : {
"tokenizer" : "ik_smart"
},
"ik_pinyin_analyzer": {
"type": "custom",
"tokenizer": "ik_smart",
"filter": [
"mix_pinyin",
"word_delimiter"
]
}
},
"filter": {
"mix_pinyin": {
"type": "pinyin",
"first_letter": "prefix",
"padding_char": " "
}
}
}
},
"number_of_shards": "3",
"number_of_replicas": "1"
}'
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "index_test"
}

[elon@icloud-store elasticsearch-6.0.0]$ curl -XGET "http://192.168.0.103:9200/index_test?pretty=true"
{
"index_test" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"number_of_shards" : "3",
"provided_name" : "index_test",
"creation_date" : "1513155447722",
"analysis" : {
"filter" : {
"mix_pinyin" : {
"padding_char" : " ",
"type" : "pinyin",
"first_letter" : "prefix"
}
},
"analyzer" : {
"ik_pinyin_analyzer" : {
"filter" : [
"mix_pinyin",
"word_delimiter"
],
"type" : "custom",
"tokenizer" : "ik_smart"
},
"default" : {
"tokenizer" : "ik_smart"
}
}
},
"number_of_replicas" : "1",
"uuid" : "JiyIMwnlS7mpMB1T-3MmOQ",
"version" : {
"created" : "6000099"
}
}
}
}
}

测试分词效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
[elon@icloud-store elasticsearch-6.0.0]$ curl "http://192.168.0.103:9200/index_test/_analyze?pretty=true" -H 'Content-Type: application/json' -d'{ "analyzer":"ik_pinyin_analyzer", "text":"元旦节是公历新一年的第一天."}'
{
"tokens" : [
{
"token" : "yuan",
"start_offset" : 0,
"end_offset" : 3,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "dan",
"start_offset" : 0,
"end_offset" : 3,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "jie",
"start_offset" : 0,
"end_offset" : 3,
"type" : "CN_WORD",
"position" : 2
},
{
"token" : "ydj",
"start_offset" : 0,
"end_offset" : 3,
"type" : "CN_WORD",
"position" : 2
},
{
"token" : "shi",
"start_offset" : 3,
"end_offset" : 4,
"type" : "CN_CHAR",
"position" : 3
},
{
"token" : "s",
"start_offset" : 3,
"end_offset" : 4,
"type" : "CN_CHAR",
"position" : 3
},
{
"token" : "gong",
"start_offset" : 4,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 4
},
{
"token" : "li",
"start_offset" : 4,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 5
},
{
"token" : "gl",
"start_offset" : 4,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 5
},
{
"token" : "xin",
"start_offset" : 6,
"end_offset" : 7,
"type" : "CN_CHAR",
"position" : 6
},
{
"token" : "x",
"start_offset" : 6,
"end_offset" : 7,
"type" : "CN_CHAR",
"position" : 6
},
{
"token" : "yi",
"start_offset" : 7,
"end_offset" : 9,
"type" : "CN_WORD",
"position" : 7
},
{
"token" : "nian",
"start_offset" : 7,
"end_offset" : 9,
"type" : "CN_WORD",
"position" : 8
},
{
"token" : "yn",
"start_offset" : 7,
"end_offset" : 9,
"type" : "CN_WORD",
"position" : 8
},
{
"token" : "de",
"start_offset" : 9,
"end_offset" : 10,
"type" : "CN_CHAR",
"position" : 9
},
{
"token" : "d",
"start_offset" : 9,
"end_offset" : 10,
"type" : "CN_CHAR",
"position" : 9
},
{
"token" : "di",
"start_offset" : 10,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 10
},
{
"token" : "yi",
"start_offset" : 10,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 11
},
{
"token" : "tian",
"start_offset" : 10,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 12
},
{
"token" : "dyt",
"start_offset" : 10,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 12
}
]
}

创建类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
[elon@icloud-store elasticsearch-6.0.0]$ curl "http://192.168.0.103:9200/index_test/article/_mapping?pretty=true" -H 'Content-Type: application/json' -d'
{
"properties": {
"name": {
"type" : "text",
"analyzer" : "ik_smart",
"fields" : {
"pinyin" : {
"type" : "text",
"term_vector" : "with_positions_offsets",
"analyzer" : "ik_pinyin_analyzer",
"boost" : 10.0
}
}
}
}
}'
{
"acknowledged" : true
}
[elon@icloud-store elasticsearch-6.0.0]$ curl -XGET "http://192.168.0.103:9200/index_test?pretty=true"
{
"index_test" : {
"aliases" : { },
"mappings" : {
"article" : {
"properties" : {
"name" : {
"type" : "text",
"fields" : {
"pinyin" : {
"type" : "text",
"boost" : 10.0,
"term_vector" : "with_positions_offsets",
"analyzer" : "ik_pinyin_analyzer"
}
},
"analyzer" : "ik_smart"
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : "3",
"provided_name" : "index_test",
"creation_date" : "1513155447722",
"analysis" : {
"filter" : {
"mix_pinyin" : {
"padding_char" : " ",
"type" : "pinyin",
"first_letter" : "prefix"
}
},
"analyzer" : {
"ik_pinyin_analyzer" : {
"filter" : [
"mix_pinyin",
"word_delimiter"
],
"type" : "custom",
"tokenizer" : "ik_smart"
},
"default" : {
"tokenizer" : "ik_smart"
}
}
},
"number_of_replicas" : "1",
"uuid" : "JiyIMwnlS7mpMB1T-3MmOQ",
"version" : {
"created" : "6000099"
}
}
}
}
}

索引数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/article/1?pretty=true" -H 'Content-Type: application/json' -d'{"name":"元旦火车票 开售."}'
{
"_index" : "index_test",
"_type" : "article",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/article/2?pretty=true" -H 'Content-Type: application/json' -d'{"name":"元旦节是公历新一年的第一天."}'
{
"_index" : "index_test",
"_type" : "article",
"_id" : "2",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/article/3?pretty=true" -H 'Content-Type: application/json' -d'{"name":"元旦节是每年1月1号"}'
{
"_index" : "index_test",
"_type" : "article",
"_id" : "3",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}

查询数据(主键)

1
2
3
4
5
6
7
8
9
10
11
[elon@icloud-store elasticsearch-6.0.0]$ curl -XGET "http://192.168.0.103:9200/index_test/article/2?pretty=true"
{
"_index" : "index_test",
"_type" : "article",
"_id" : "2",
"_version" : 1,
"found" : true,
"_source" : {
"name" : "元旦节是公历新一年的第一天."
}
}

查询数据(中文)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/article/_search?pretty" -H 'Content-Type: application/json' -d'
{
"from" : 0,
"size" : 10,
"query": {
"match": {
"name": "元旦节"
}
},
"highlight": {
"fields": {
"name": {}
}
}
}'
{
"took" : 9,
"timed_out" : false,
"_shards" : {
"total" : 3,
"successful" : 3,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.6288345,
"hits" : [
{
"_index" : "index_test",
"_type" : "article",
"_id" : "3",
"_score" : 0.6288345,
"_source" : {
"name" : "元旦节是每年1月1号"
},
"highlight" : {
"name" : [
"<em>元旦节</em>是每年1月1号"
]
}
},
{
"_index" : "index_test",
"_type" : "article",
"_id" : "2",
"_score" : 0.2876821,
"_source" : {
"name" : "元旦节是公历新一年的第一天."
},
"highlight" : {
"name" : [
"<em>元旦节</em>是公历新一年的第一天."
]
}
}
]
}
}

查询数据(拼音)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/article/_search?pretty" -H 'Content-Type: application/json' -d'
{
"from" : 0,
"size" : 10,
"query": {
"match": {
"name.pinyin": "ydj"
}
},
"highlight": {
"fields": {
"name.pinyin": {}
}
}
}'
{
"took" : 7,
"timed_out" : false,
"_shards" : {
"total" : 3,
"successful" : 3,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 7.5108185,
"hits" : [
{
"_index" : "index_test",
"_type" : "article",
"_id" : "3",
"_score" : 7.5108185,
"_source" : {
"name" : "元旦节是每年1月1号"
},
"highlight" : {
"name.pinyin" : [
"<em>元旦节</em>是每年1<em>月</em>1号"
]
}
},
{
"_index" : "index_test",
"_type" : "article",
"_id" : "2",
"_score" : 3.693319,
"_source" : {
"name" : "元旦节是公历新一年的第一天."
},
"highlight" : {
"name.pinyin" : [
"<em>元旦节</em>是公历新一年<em>的</em>第一天."
]
}
}
]
}
}

[elon@icloud-store elasticsearch-6.0.0]$ curl -XPOST "http://192.168.0.103:9200/index_test/article/_search?pretty" -H 'Content-Type: application/json' -d'
{
"from" : 0,
"size" : 10,
"query": {
"match": {
"name.pinyin": "元旦j"
}
},
"highlight": {
"fields": {
"name.pinyin": {}
}
}
}'
{
"took" : 16,
"timed_out" : false,
"_shards" : {
"total" : 3,
"successful" : 3,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 3.693319,
"hits" : [
{
"_index" : "index_test",
"_type" : "article",
"_id" : "2",
"_score" : 3.693319,
"_source" : {
"name" : "元旦节是公历新一年的第一天."
},
"highlight" : {
"name.pinyin" : [
"<em>元旦节</em>是公历新一年的第一天."
]
}
},
{
"_index" : "index_test",
"_type" : "article",
"_id" : "1",
"_score" : 2.560377,
"_source" : {
"name" : "元旦火车票 开售."
},
"highlight" : {
"name.pinyin" : [
"<em>元旦</em>火车票 开售."
]
}
},
{
"_index" : "index_test",
"_type" : "article",
"_id" : "3",
"_score" : 1.9756038,
"_source" : {
"name" : "元旦节是每年1月1号"
},
"highlight" : {
"name.pinyin" : [
"<em>元旦节</em>是每年1月1号"
]
}
}
]
}
}
`