在弹性搜索Java中查询文档

时间:2018-12-05 14:45:45

标签: java elasticsearch

我想使用Java客户端从弹性搜索文档的特定字段中获取2个字段:

public SearchResponse getResponse(String index) {

    SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.searchSource();
    SearchResponse response = elasticHandler.prepareSearch()
        .setIndices(index)
        .setQuery(QueryBuilders.termsQuery("provider", "twitter"))
        .setSource(searchSourceBuilder)
        .setFetchSource((new String[] {"originId","name"}), null)
        .setSize(scrollSize).get();

    return response;
}

但是,包含两个字段originIdname的地图为空。 你能帮我吗?

0 个答案:

没有答案