从一个文件Elasticsearch java获取所有字段

时间:2016-11-10 12:04:26

标签: java elasticsearch

我正在尝试从一个价格最低的文档中获取所有字段。使用min我只能得到特定的价格。我应该如何检索一个文档的所有字段。

我已经编写了这段代码来检索最低价格

AggregationBuilder aggregation = AggregationBuilders.nested("nestedAgg").path("carSpecPojo")
            .subAggregation(AggregationBuilders.min("carSpecAgg").field("carSpecPojo.price"));
    SearchQuery searchQuery = (SearchQuery) new NativeSearchQueryBuilder()
            .addAggregation(aggregation).build(); 
    Aggregations aggregations = elasticsearchTemplate.query(searchQuery, new ResultsExtractor<Aggregations>() {
        @Override
        public Aggregations extract(SearchResponse response) {
            return response.getAggregations();
        }});
    Nested nest = aggregations.get("nestedAgg");
    Min min = nest.getAggregations().get("carSpecAgg");

我的弹性文件将是这样的

 "brand_name": "maruti",
           "model": "i20",
           "year": "2015",
           "carSpecPojo": {
              "engine_power": "400hp",
              "price": 9000000,
              "transmission_type": "auto",
              "airbag": "yes",
              "abs": 1,
              "max_speed": "170kmp",
              "color": "black",
              "fuel": "petrol",
              "mileage": 5,
              "door": 4,
              "seat_capacity": 4
           }
        }

当我得到最低价格XXXXXXX时,我需要本文档中的所有字段

提前致谢

0 个答案:

没有答案