从 ElastiSearch 的 Java API 中的 SearchResponse 中排除字段

Exclude fields from SearchResponse in ElastiSearch's Java API

我找不到如何从弹性搜索的响应中排除字段。

这是我的请求:

SearchResponse response = client
            .prepareSearch("_all")
            .setSearchType(SearchType.DFS_QUERY_AND_FETCH)
            .setQuery(
                    QueryBuilders.boolQuery()
                    .should(matchQuery("location.endpoint", "activemq://*****"))
                    .should(matchQuery("location.endpoint", "http://localhost/proxy/etatest/soap/inbound/"))
                    .should(fuzzyLikeThisQuery("location.endpoint").likeText("//****"))
                    .should(matchQuery("status", "RESPONSE"))
                    .should(matchQuery("status", "RESPONSE_WITH_FAILURES")) 
                    .minimumNumberShouldMatch(1)
            )
            .setPostFilter(FilterBuilders.boolFilter()
                    .must(existsFilter("exchange.wfm_idocNumber"))
                    .must(rangeFilter("@timestamp").from("2015-01-08T14:20:00.197+01:00").to("2015-01-08T14:21:00.197+01:00"))
            )
            .execute()
            .actionGet();

谢谢

试试这个,将要排除的字段放入排除数组中。

    String[] includes = {};
    String[] excludes = {};
    SearchResponse response = client
            .prepareSearch("_all")
            .setSearchType(SearchType.DFS_QUERY_AND_FETCH)
            .setQuery(
                    QueryBuilders.boolQuery()
                            .should(matchQuery("location.endpoint", "activemq://*****"))
                            .should(matchQuery("location.endpoint", "http://localhost/proxy/etatest/soap/inbound/"))
                            .should(fuzzyLikeThisQuery("location.endpoint").likeText("//****"))
                            .should(matchQuery("status", "RESPONSE"))
                            .should(matchQuery("status", "RESPONSE_WITH_FAILURES"))
                            .minimumNumberShouldMatch(1)
            )
            .setPostFilter(FilterBuilders.boolFilter()
                            .must(existsFilter("exchange.wfm_idocNumber"))
                            .must(rangeFilter("@timestamp").from("2015-01-08T14:20:00.197+01:00").to("2015-01-08T14:21:00.197+01:00"))
            )
            .setFetchSource(includes, excludes)
            .execute()
            .actionGet();