how to analyze text in elasticsearch using java api?

纵然是瞬间 提交于 2019-12-02 13:51:56

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/35040625/how-to-analyze-text-in-elasticsearch-using-java-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!