如何使用es客户端查询crateDB

时间:2019-01-10 08:38:56

标签: crate cratedb

我想通过ES客户端查询crateDB。但是失败

我在es.api.enabled: true中设置了 crate.yml ,并使用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();
    }
}

1 个答案:

答案 0 :(得分:0)

您可能不应该(很快就会被弃用),如其官方文档here

所建议的那样

但是,如果您必须同时这样做,则Crate会像这样响应标准的ES URL搜索

http://your-server:4200/*your-index-name*/_search?q=your-field:your-search-value