>  Q&A  >  본문

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일 전842

모든 응답(1)나는 대답할 것이다

  • 天蓬老师

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

    으아악

    이런 매칭 모드로 검색이 가능하다니 정말 신기하네요

    으아악

    회신하다
    0
  • 취소회신하다