[英]Using Elasticsearch Java API to analyze text
我正在使用Elastic的Java庫6.2.4,並且正在嘗試分析文本。 我在文檔中找不到任何提及方法,也沒有在6.3版本的文檔中提及它。 我試圖建立一個AnalyzerRequest
,如下所示
try(RestHighLevelClient client =
new RestHighLevelClient(RestClient.builder(new HttpHost(elasticsearchHost, elasticsearchPort, elasticsearchScheme)))) {
AnalyzeRequest analyzeRequest = new AnalyzeRequest()
.index(elasticsearchIndex)
.analyzer("my_analyzer")
.text("Some Text To Analyze);
} catch (IOException e) {
log.error("Could not connect to elasticsearch", e);
}
但是我找不到如何使用它。 該答案建議使用不建議使用的TransportClient
,因此我無法使用它,也找不到其他示例。
當我嘗試查看RestHighLevelClient
提供的內容時,我僅找到用於搜索,索引編制等的方法。
任何幫助是極大的贊賞。
analyze
方法正在開發中,目標版本為6.4: https : //github.com/elastic/elasticsearch/pull/31577
您可以使用PreBuiltTransportClient :
Settings settings = ....;
TransportClient client = new PreBuiltTransportClient(settings);
AnalyzeRequest analyzeRequest = ...;
ActionFuture<AnalyzeResponse> analyzeResponse = client.admin().indices().analyze(analyzeRequest);
或者,您可以使用“低級客戶端” 並發 出自定義的休息請求: https : //www.elastic.co/guide/en/elasticsearch/client/java-rest/6.2/java-rest-low-usage-requests.html https ://www.elastic.co/guide/en/elasticsearch/reference/6.2/indices-analyze.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.