Spring Boot Version (x) Spring Data Elasticsearch Version (y) Elasticsearch Version (z)x <= 1.3.5 y <= 1.3.4 z <= 1.7.2*x >= 1.4.x 2.0.0 <=y < 5.0.0** 2.0.0 <= z < 5.0.0*** – 只需要你修改下对应的 pom 文件版本号** – 下一个 ES 的版本会有重大的更新
1
2
|
分析器 Analyzer: ik_smart 或 ik_max_word
分词器 Tokenizer: ik_smart 或 ik_max_word
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
IK版 ES版本
主 5.x -> master
5.3.2 5.3.2
5.2.2 5.2.2
5.1.2 5.1.2
1.10.1 2.4.1
1.9.5 2.3.5
1.8.1 2.2.1
1.7.0 2.1.1
1.5.0 2.0.0
1.2.6 1.0.0
1.2.5 0.90.x
1.1.3 0.20.x
1.0.0 0.16.2 -> 0.19.0
|
1
2
3
|
cd
elasticsearch-2.3.2
/plugins
mkdir
ik
cp
...
|
1
2
|
index.analysis.analyzer.default.tokenizer :
"ik_max_word"
index.analysis.analyzer.default.
type
:
"ik"
|
1
|
localhost:9200
/_analyze
?analyzer=ik&pretty=
true
&text=泥瓦匠的博客是bysocket.com
|
可以得到下面的结果集:
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
|
{
"tokens"
: [
{
"token"
:
"泥瓦匠"
,
"start_offset"
: 0,
"end_offset"
: 3,
"type"
:
"CN_WORD"
,
"position"
: 0
},
{
"token"
:
"泥"
,
"start_offset"
: 0,
"end_offset"
: 1,
"type"
:
"CN_WORD"
,
"position"
: 1
},
{
"token"
:
"瓦匠"
,
"start_offset"
: 1,
"end_offset"
: 3,
"type"
:
"CN_WORD"
,
"position"
: 2
},
{
"token"
:
"匠"
,
"start_offset"
: 2,
"end_offset"
: 3,
"type"
:
"CN_WORD"
,
"position"
: 3
},
{
"token"
:
"博客"
,
"start_offset"
: 4,
"end_offset"
: 6,
"type"
:
"CN_WORD"
,
"position"
: 4
},
{
"token"
:
"bysocket.com"
,
"start_offset"
: 8,
"end_offset"
: 20,
"type"
:
"LETTER"
,
"position"
: 5
},
{
"token"
:
"bysocket"
,
"start_offset"
: 8,
"end_offset"
: 16,
"type"
:
"ENGLISH"
,
"position"
: 6
},
{
"token"
:
"com"
,
"start_offset"
: 17,
"end_offset"
: 20,
"type"
:
"ENGLISH"
,
"position"
: 7
}
]
}
|
1
2
3
4
5
|
/groupId
>
/artifactId
>
<
/dependency
>
|
1
2
3
|
# ES
spring.data.elasticsearch.repositories.enabled =
true
spring.data.elasticsearch.cluster-nodes = 127.0.0.1:9300
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
/**
* 调用 ES 获取 IK 分词后结果
*
* @param searchContent
* @
return
*/
private List
//
调用 IK 分词分词
AnalyzeRequestBuilder ikRequest = new AnalyzeRequestBuilder(elasticsearchTemplate.getClient(),
AnalyzeAction.INSTANCE,
"indexName"
,searchContent);
ikRequest.setTokenizer(
"ik"
);
List
//
循环赋值
List
ikTokenList.forEach(ikToken -> { searchTermList.add(ikToken.getTerm()); });
return
searchTermList;
}
|
推荐开源项目:《springboot-learning-example》
spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践