我想通过 ES 客户端查询 crateDB。但失败了
我在crate.yml
中设置了es.api.enabled: true
,并使用 ES java-rest-high-level-client 通过端口 4200
连接 crateDB,但没有得到任何响应
public class crateAPI {
public static void main(String[] args) throws Exception{
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("localhost", 4200, "http")));
SearchRequest searchRequest =new SearchRequest();
SearchSourceBuilder searchSourceBuilder =new SearchSourceBuilder();
searchSourceBuilder.query
(QueryBuilders.termQuery("test.news.content","test"));
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest);
for(SearchHit hit : searchResponse.getHits().getHits()){
System.out.println(hit.getSourceAsString());
}
client.close();
}
}
您可能不应该(并且很快就会被弃用)他们的官方文档中的建议
这里但是,如果您必须同时这样做,Crate将像这样响应标准的ES URL搜索。
http://your-server:4200/*your-index-name*/_search?q=your-field:your-search-value