java - elasticsearch ik分词时遇到的一个问题
怪我咯
怪我咯 2017-04-18 09:14:43
0
1
784

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());

数据:

怪我咯
怪我咯

走同样的路,发现不同的人生

membalas semua (1)
Peter_Zhu
{ "query" : { "match" : { "_all" : { "query" : "中国", "type" : "boolean" } } } }

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

lyricQuery= QueryBuilders.matchQuery("_all",music);
    Muat turun terkini
    Lagi>
    kesan web
    Kod sumber laman web
    Bahan laman web
    Templat hujung hadapan
    Tentang kita Penafian Sitemap
    Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!