独特的高级Rest Client弹性查询

时间:2019-11-25 02:33:55

标签: elasticsearch elasticsearch-java-api elasticsearch-high-level-restclient

如何使用High Level Rest Client通过不同的值查找文档。文档讨论了Aggregation framework,用于documents查找不同的field。但是我找不到使用High Level Rest Client的任何示例。如何通过documents来区分field

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"
    }
}

Elastic Search Query for Distinct Nested Values

Elastic Aggregation

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

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

0 个答案:

没有答案