3

如何使用High Level Rest Client按不同值查找文档。文档讨论Aggregation framework了查找 distinct documentsby field。但我找不到任何使用High Level Rest Client. 我怎样才能与众不同documentsfield

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
                .must(QueryBuilders.matchQuery("Field1", "Value1"))
searchSourceBuilder.query(boolQueryBuilder);

searchSourceBuilder.aggregation(????)

数据

{
    ..
    ..

      "Field1" : "Value1",
      "Field2" : "Value2"
    },
    {
      "Field1" : "Value1",
      "Field2" : "Value21"
    }
}

预期输出(任何带有“Field1”的文档:“Value1”)

{
    ..
    ..

      "Field1" : "Value1",
      "Field2" : "Value2"
    }
}

不同嵌套值的弹性搜索查询

弹性聚合

下面的代码给出了相同的结果:

   AggregationBuilder termAggregationBuilder = AggregationBuilders
                .terms("someName")
                .field("Field1");
   AggregationBuilder topHitsAggregationBuilder = AggregationBuilders
                .topHits("someOtherName")
                .fetchSource(includeFields, excludeFields);
   searchSourceBuilder.aggregation(termAggregationBuilder.subAggregation(topHitsAggregationBuilder));
4

0 回答 0