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

时间:2015-01-09 13:23:15

标签: elasticsearch

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

这是我的要求:

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();

谢谢

1 个答案:

答案 0 :(得分:1)

尝试此操作,将要排除的字段放在排除数组中。

    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();