- 查看es是否安装了ik分词插件
- 查看实体类有没有设置正确,例如:
-
@Field(type = FieldType.Text,analyzer = "ik_max_word", searchAnalyzer = "ik_max_word",store = true)
- 通过rest接口查看mapping实际的生成情况
- http://es-ip:es-port/[实体的indexName]/_mapping
{
"blog": {
"mappings": {
"properties": {
"_class": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"age": {
"type": "long"
},
"firstname": {
"type": "text",
"store": true,
"analyzer": "ik_max_word"
},
"lastname": {
"type": "text",
"store": true,
"analyzer": "ik_max_word"
}
}
}
}
}
字段中如果有analyzer,说明设置生效了,如果没有,删除相关mapping,重新生成
- 通过单元测试可以发现,停词无法再查出结果
-
@Test public void testH21231111(){ List<SearchHit<Blog>> searchHitList = blogRepository.findByFirstname("的"); for (SearchHit<Blog> customerSearchHit : searchHitList) { Blog content = customerSearchHit.getContent(); System.out.println(content); List<String> firstname = customerSearchHit.getHighlightField("firstname"); for (String s : firstname) { System.out.println(s); } } }
通过配置有的词库查询,可以查到结果
-
在后面加上一个停词,还是可以查出结果,正确
-
至此便对了