可能一年才能想起来写一次博客 居然没忘记密码。。。最近用到了es各种坑坑绊绊,打算系统的总结一下,先写一篇备忘。
es英文分词默认是通过空格之类的拆分成单词吧,举个栗子,在kibana dev_tools/console运行下面查询
GET _analyze
{"analyzer" : "standard", "text" : "hello world es hahha"}
返回结果如下
{
"tokens" : [
{
"token" : "hello",
"start_offset" : 0,
"end_offset" : 5,
"type" : "<ALPHANUM>",
"position" : 0
},
{
"token" : "world",
"start_offset" : 6,
"end_offset" : 11,
"type" : "<ALPHANUM>",
"position" : 1
},
{
"token" : "es",
"start_offset" : 12,
"end_offset" : 14,
"type" : "<ALPHANUM>",
"position" : 2
},
{
"token" : "hahha",
"start_offset" : 15,
"end_offset" : 20,
"type" : "<ALPHANUM>",
"position" : 3
}
]
}
如果是有中文搜索,es 默认的analyzer是standard分词,对于中文会按单个文字拆分,比如这么一句话“这是一首简单的小情歌”,每个字都是一个索引,就没有了单词的概念,这时搜索就会返回一些不是想要的结果。
GET _analyze
{"analyzer" : "standard",