java - elasticsearch ik分词时遇到的一个问题

 作小die_syj 发布于 2022-10-28 13:34

1.问题:

使用elasticsearch-rtf 版本2.2.1中使用ik分词发现当要搜索的词为中国时无法匹配“中国话”,“中国风”等词语。

2.开发语言
java 1.8

3.描述
感觉也不是什么大问题,在搜索江南之类的可以,但是中国这个词貌似很特殊无法匹配到搜索结果
请问这个是bug吗

映射关系

{
"state": "open",
"settings": {
"index": {
"creation_date": "1465957561705",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "UVIgBxS3SmeNIKQ3PWV6Rw",
"version": {
"created": "2020199"
}
}
},
"mappings": {
"musics": {
"_all": {
"search_analyzer": "ik_max_word",
"analyzer": "ik"
},
"properties": {
"singer": {
"search_analyzer": "ik_max_word",
"include_in_all": true,
"analyzer": "ik_smart",
"term_vector": "with_positions_offsets",
"boost": 3,
"type": "string"
},
"musicName": {
"search_analyzer": "ik_max_word",
"include_in_all": true,
"analyzer": "ik_smart",
"term_vector": "with_positions_offsets",
"boost": 4,
"type": "string"
},
"musicType": {
"search_analyzer": "ik_max_word",
"include_in_all": true,
"analyzer": "ik_smart",
"term_vector": "with_positions_offsets",
"boost": 2,
"type": "string"
}
}
}
},
"aliases": [
"my_music"
]
}

java搜索代码

    Spark.get(
                "/search",
                (request, response) -> {
                    SearchRequestBuilder srb = client.prepareSearch("my_music")
                            .setTypes("musics");

                    String music = request.queryParams("music");
                    QueryBuilder lyricQuery = null;

                    lyricQuery = QueryBuilders.boolQuery()
                            .should(QueryBuilders.matchQuery("musicName",music))
                            .should(QueryBuilders.matchQuery("singer",music))
                            .should(QueryBuilders.matchQuery("musicType",music));


                    srb.setQuery(lyricQuery);

                    SearchResponse searchResponse = srb.execute().actionGet();

                    SearchHit[] hits = searchResponse.getHits().getHits();

                    Map attributes = new HashMap<>();
                    attributes.put("songs", hits);

                    return new ModelAndView(attributes, "index.mustache");
                }, new MustacheTemplateEngine());

数据:

1 个回答
  • {
      "query" : {
        "match" : {
          "_all" : {
            "query" : "中国",
            "type" : "boolean"
          }
        }
      }
    }

    使用这种匹配模式又可以搜索到,真是奇怪

     lyricQuery=  QueryBuilders.matchQuery("_all",music);
    2022-11-12 01:44 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有