ELK,萌萌哒

java中调用es ik去分词?

Elasticsearch | 作者 qq123 | 发布于2016年07月05日 | 阅读数:8164

就是对一个字符串切割
已邀请:

Scs

赞同来自: movetone

// 获取 TransportClient 实例 
TransportClient client = new TransportClient();

// 构建 AnalyzeRequest
AnalyzeRequest request = new AnalyzeRequest()
.text("this is a test") // 指定你需要 analyse 的文本
.analyzer("ik_smart"); // 指定你需要使用的 analyzer 名,大小写敏感

List<AnalyzeResponse.AnalyzeToken> tokens = client.admin().indices().analyze(request).actionGet().getTokens();
for (AnalyzeResponse.AnalyzeToken token : tokens){
System.out.println(token.getTerm()); // 在控制台输出
}
最开始贴的代码在“指定需要 analyse 的文本”时有错误,现在这段代码才是对的,顺便加点注释,其实不加也应该能看懂

nodexy - Another developer !

赞同来自:

可以直接访问:
[url=http://localhost:9200/your-index-name/_analyze?analyzer=ik&amp;text=]http://localhost:9200/your-ind ... xt%3D测试IK分词器[/url] 

非要在java里面调用,就直接发一个GET请求喽

movetone

赞同来自:

/**
         * ik分词器
         * ik_max_word:
         * 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,
         * 共和,和,国国,国歌”,会穷尽各种可能的组合;
         * ik_smart: 会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”。
         */
        queryBuilder.analyzer("ik_smart");

Scs

赞同来自:

http://stackoverflow.com/quest ... a-api
 
TransportClient client = new TransportClient();
AnalyzeRequest request = (new AnalyzeRequest("this is a test")).analyzer("standard");
List<AnalyzeResponse.AnalyzeToken> tokens = client.admin().indices().analyze(request).actionGet().getTokens();
for (AnalyzeResponse.AnalyzeToken token : tokens)
{
// do something with each token...
}

要回复问题请先登录注册