如何使用java API对弹性搜索中的文本进行分析? [英] how to analyze text in elasticsearch using java api?

查看:232
本文介绍了如何使用java API对弹性搜索中的文本进行分析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Elasticsearch 1.7.4及其java API。目前,我想用户计算前十名高频搜索词。所以我必须记录查询文本的用户类型搜索的单词,然后记录我必须分析查询文本的单词。我发现分析文本的平静方式是链接说,但我在TransportClient中找不到api。



任何人都知道如何使用java API或其他方式在弹性搜索中分析文本,而不是请求宁静的api?



感谢任何人可能会帮助想法,提示,资源等。

解决方案

使用文档中的示例(文本这是一个测试)正在使用标准分析器进行分析),这里是一个例子可以使用Java API完成相同的分析:

  TransportClient client = new TransportClient(); 
AnalyzeRequest request =(new AnalyzeRequest(this is a test))。analyzer(standard);
列表< AnalyzeResponse.AnalyzeToken> tokens = client.admin()。indices()。analyze(request).actionGet()。getTokens();
for(AnalyzeResponse.AnalyzeToken token:tokens)
{
//对每个令牌执行某些操作...
}

希望这有帮助!


I use Elasticsearch 1.7.4 and its java API.Currently, I want to count the top 10 high frequency searching words by user. So I have to record the words of query text which user type to search, and before recording the words I have to analyze the query text. I find the restful way to analyze text as the link says, but I can't find the api in TransportClient.

do anyone know how to analyze text in elasticsearch using java api or some other way rather than requesting the restful api?

Thanks to anyone who might help with ideas, tips, resources, etc.

解决方案

Using the example from the documentation (where the text "this is a test" is being analyzed using the standard analyzer), here is an example of how one might accomplish the same analysis using the Java 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...
}

Hope this helps!

这篇关于如何使用java API对弹性搜索中的文本进行分析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆