be
搜不到想要的数据i want to be xxx
停用词
我们用的是ik分词, 然后去issues
查找相关信息, 才了解到停用词.
关于停用词的解释所以我要做的只要把停用词删除掉即可
Elasticsearch
的根目录下(以你安装的为准, 我使用的是Docker
)cd /usr/share/elasticsearch
ik
的配置(在es
的config
目录下寻找, 旧版本可能在plugins
目录里)cd config/analysis-ik
stopword.dic
# cat stopword.dic
a
an
and
are
as
at
be
but
by
for
if
in
into
is
it
no
not
of
on
or
such
that
the
their
then
there
these
they
this
to
was
will
with
be
Elasticsearch
be
查找到文档了POST /_analyze
{
"analyzer": "ik_max_word",
"text": "q宠大乱斗"
}
--------------
{
"tokens": [{
"token": "q",
"start_offset": 0,
"end_offset": 1,
"type": "ENGLISH",
"position": 0
},
{
"token": "宠大",
"start_offset": 1,
"end_offset": 3,
"type": "CN_WORD",
"position": 1
},
{
"token": "大乱斗",
"start_offset": 2,
"end_offset": 5,
"type": "CN_WORD",
"position": 2
},
{
"token": "大乱",
"start_offset": 2,
"end_offset": 4,
"type": "CN_WORD",
"position": 3
},
{
"token": "斗",
"start_offset": 4,
"end_offset": 5,
"type": "CN_CHAR",
"position": 4
}
]
}
ik
下的配置文件IKAnalyzer.cfg.xml
# cat IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict"></entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
ext_dict
扩展自定义词库, 多个文件使用;
隔开# cat IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict">custom_words.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
# cat custom_words.dic
q宠
Elasticsearch
POST /_analyze
{
"analyzer": "ik_max_word",
"text": "q宠大乱斗"
}
--------------
{
"tokens": [{
"token": "q宠",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
},
{
"token": "q",
"start_offset": 0,
"end_offset": 1,
"type": "ENGLISH",
"position": 1
},
{
"token": "宠大",
"start_offset": 1,
"end_offset": 3,
"type": "CN_WORD",
"position": 2
},
{
"token": "大乱斗",
"start_offset": 2,
"end_offset": 5,
"type": "CN_WORD",
"position": 3
},
{
"token": "大乱",
"start_offset": 2,
"end_offset": 4,
"type": "CN_WORD",
"position": 4
},
{
"token": "斗",
"start_offset": 4,
"end_offset": 5,
"type": "CN_CHAR",
"position": 5
}
]
}
q宠