如何使用es客户端查询crateDB
How can I use the es client to query crateDB
我想通过 ES 查询 crateDB client.But 失败
我在crate.yml
中设置了es.api.enabled: true
并且我使用了ESjava-rest-high-level-client来连接crateDB 通过端口 4200
,但我无法得到任何响应
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();
}
}
您可能不应该(并且很快就会被弃用),正如官方文档中所建议的那样here
但如果您同时需要这样做,Crate 会像这样响应标准 ES URL 搜索
http://your-server:4200/*your-index-name*/_search?q=your-field:your-search-value
我想通过 ES 查询 crateDB client.But 失败
我在crate.yml
中设置了es.api.enabled: true
并且我使用了ESjava-rest-high-level-client来连接crateDB 通过端口 4200
,但我无法得到任何响应
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();
}
}
您可能不应该(并且很快就会被弃用),正如官方文档中所建议的那样here
但如果您同时需要这样做,Crate 会像这样响应标准 ES URL 搜索
http://your-server:4200/*your-index-name*/_search?q=your-field:your-search-value