首页  >  问答  >  正文

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

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<String, Object> attributes = new HashMap<>();
                    attributes.put("songs", hits);

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

数据:

怪我咯怪我咯2762 天前843

全部回复(1)我来回复

  • 天蓬老师

    天蓬老师2017-04-18 09:16:43

    {
      "query" : {
        "match" : {
          "_all" : {
            "query" : "中国",
            "type" : "boolean"
          }
        }
      }
    }

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

     lyricQuery=  QueryBuilders.matchQuery("_all",music);

    回复
    0
  • 取消回复