Easysearch、Elasticsearch 还是 Opensearch,是个问题

使用 IK 中文分词插件,当查询某些关键字的时候查询不到数据,请问问题出在哪里?

Elasticsearch | 作者 Sune | 发布于2019年06月20日 | 阅读数:7375

es查询使用ik_smart分词器和ik_max_word分词器查询长的字符串都可以查到数据,当使用”饭局“关键字查询不到任何数据。
es版本7.1.0
前提:在创建索引的时候没有直接指定content的分词器, 而是在查询的时候指定的分词器。
下面对两种模式做测试:
1、使用ik_smart分词:{
"analyzer":"ik_smart",
"text":"饭局"
}
使用ik_smart分词结果:
{"tokens": [
{
"token": "饭局",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
}
]}
 
2、使用ik_max_word分词:
{
"analyzer":"ik_max_word",
"text":"饭局"
}
使用ik_max_word分词结果:
{"tokens": [
{
"token": "饭局",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
}
]}
doc内容包含"饭局"如下:

1560998585(1).png

 
查询java代码如下:

1560998740(1).jpg

 
 
 
已邀请:

Sune - 90后IT

赞同来自:

问题已经解决。
IK分词器主要有两种:ik_smart、ik_max_word,根据需求在创建索引的时候指定全局默认索引,或者在设置doc的单个属性的分词器。
问题:第二张图上指定的分词器不好使,还会导致其它的词条查不到数据的情况 ,具体原因需要再查。
解决办法:因属性比较简单,数据量小,所以重建索引,重新同步数据,设置索引的默认分词器,设置一切正常了。
http://191.168.2.55:9200/order_index/{
    "settings" : {
        "index" : {
            "analysis.analyzer.default.type": "ik_max_word"
        }
    }
}

alvin - 90后IT男

赞同来自:

怀疑faq_index的mapping设置的有问题
 
PUT test_index
{
"settings": {
"number_of_shards": 5
},
"mappings": {
"_doc":{
"properties":{
"title":{
"type": "text"
},
"type": {
"type": "float"
},
"keyword": {
"type": "text",
"analyzer": "ik_smart"
},
"content":{
"type": "text",
"analyzer": "ik_smart"
}
}
}
}
}
POST test_index/_doc/1
{
  "title":"中国式饭局,有多少人觉得自己爽了",
  "type":1,
  "keyword":"饭局 家装 爽",
  "content":"很多人把饭局当做很功利的场所"
}

GET test_index/_doc/_search
{
  "query":{
    "match": {
      "content": "饭局"
    }
  }
}
最好在创建索引时指定analyzer,查询时很少指定用什么分词器的

WangChuanfu - 深入学习es

赞同来自:

创建mapping的时候就指定分词器,

要回复问题请先登录注册