org.elasticsearch.search.aggregations.bucket.filter.InternalFilter Java Examples

The following examples show how to use org.elasticsearch.search.aggregations.bucket.filter.InternalFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AggregationTest.java    From elasticsearch-sql with Apache License 2.0 6 votes vote down vote up
@Test
public void reverseAnotherNestedGroupByOnNestedFieldWithFilterTestWithReverseNestedNoPath() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a'),reverse_nested(comment.data,'~comment')", TEST_INDEX_NESTED_TYPE));
    InternalNested nested = result.get("message.info@NESTED");
    InternalFilter filter = nested.getAggregations().get("myFilter@FILTER");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("comment.data@NESTED_REVERSED");
        InternalNested innerNested = reverseNested.getAggregations().get("comment.data@NESTED");
        Terms terms = innerNested.getAggregations().get("comment.data");
        Terms.Bucket internalBucket = terms.getBuckets().get(0);

        long count = ((ValueCount) internalBucket.getAggregations().get("COUNT(*)")).getValue();
        String key = internalBucket.getKey().toString();
        if(key.equalsIgnoreCase("ab")) {
            Assert.assertEquals(2, count);
        }
        else {
            throw new Exception(String.format("Unexpected key. expected: only a . found: %s", key));
        }
    }
}
 
Example #2
Source File: AggregationTest.java    From elasticsearch-sql with Apache License 2.0 6 votes vote down vote up
@Test
public void reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedNoPath() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a'),reverse_nested(someField)", TEST_INDEX_NESTED_TYPE));
    InternalNested nested = result.get("message.info@NESTED");
    InternalFilter filter = nested.getAggregations().get("myFilter@FILTER");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("someField@NESTED");
        Terms terms = reverseNested.getAggregations().get("someField");
        Terms.Bucket internalBucket = terms.getBuckets().get(0);

        long count = ((ValueCount) internalBucket.getAggregations().get("COUNT(*)")).getValue();
        String key = internalBucket.getKey().toString();
        if(key.equalsIgnoreCase("b")) {
            Assert.assertEquals(2, count);
        }
        else {
            throw new Exception(String.format("Unexpected key. expected: only a . found: %s", key));
        }
    }
}
 
Example #3
Source File: SearchAggregationParser.java    From sql4es with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an aggregation performed without grouping.
 * @param filter
 * @param rs
 * @throws SQLException
 */
private void processFilterAgg(InternalFilter filter, ESResultSet rs) throws SQLException{
	//String name = global.getName(); // we do not care about the global name for now
	List<Object> row = rs.getNewRow();
	Column count = null;
	for(Column c : rs.getHeading().columns())
		if(c.getOp() == Operation.COUNT) count = c;
	
	if(count != null){
		row.set(count.getIndex(), filter.getDocCount());
	}
	for(Aggregation agg : filter.getAggregations()){
		if(agg instanceof InternalNumericMetricsAggregation.SingleValue){
			InternalNumericMetricsAggregation.SingleValue numericAgg = 
					(InternalNumericMetricsAggregation.SingleValue)agg;
			String name =numericAgg.getName();
			Column column = rs.getHeading().getColumnByLabel(name);
			if(column == null){
				throw new SQLException("Unable to identify column for "+name);
			}
			row.set(column.getIndex(), numericAgg.value());
		}else throw new SQLException("Unable to parse aggregation of type "+agg.getClass());
	}
	rs.add(row);
}
 
Example #4
Source File: AggregationTest.java    From elasticsearch-sql with Apache License 2.0 6 votes vote down vote up
@Test
public void reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedAndEmptyPath() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a'),reverse_nested(someField,'')", TEST_INDEX_NESTED_TYPE));
    InternalNested nested = result.get("message.info@NESTED");
    InternalFilter filter = nested.getAggregations().get("myFilter@FILTER");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("someField@NESTED");
        Terms terms = reverseNested.getAggregations().get("someField");
        Terms.Bucket internalBucket = terms.getBuckets().get(0);

        long count = ((ValueCount) internalBucket.getAggregations().get("COUNT(*)")).getValue();
        String key = internalBucket.getKey().toString();
        if(key.equalsIgnoreCase("b")) {
            Assert.assertEquals(2, count);
        }
        else {
            throw new Exception(String.format("Unexpected key. expected: only a . found: %s", key));
        }
    }
}
 
Example #5
Source File: AggregationTest.java    From elasticsearch-sql with Apache License 2.0 6 votes vote down vote up
@Test
public void groupByTestWithFilter() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/account GROUP BY filter(gender='m'),gender", TEST_INDEX_ACCOUNT));
    InternalFilter filter = result.get("filter(gender = 'm')@FILTER");
    Terms gender = filter.getAggregations().get("gender");

    for(Terms.Bucket bucket : gender.getBuckets()) {
        String key = bucket.getKey().toString();
        long count = ((ValueCount) bucket.getAggregations().get("COUNT(*)")).getValue();
        if(key.equalsIgnoreCase("m")) {
            Assert.assertEquals(507, count);
        }
        else {
            throw new Exception(String.format("Unexpected key. expected: only m. found: %s", key));
        }
    }
}
 
Example #6
Source File: AggregationTest.java    From elasticsearch-sql with Apache License 2.0 6 votes vote down vote up
@Test
public void groupByOnNestedFieldWithFilterTest() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a')", TEST_INDEX_NESTED_TYPE));
    InternalNested nested = result.get("message.info@NESTED");
    InternalFilter filter = nested.getAggregations().get("myFilter@FILTER");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        String key = bucket.getKey().toString();
        long count = ((ValueCount) bucket.getAggregations().get("COUNT(*)")).getValue();
        if(key.equalsIgnoreCase("a")) {
            Assert.assertEquals(2, count);
        }

        else {
            throw new Exception(String.format("Unexpected key. expected: only a . found: %s", key));
        }
    }
}
 
Example #7
Source File: AggregationTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void reverseAnotherNestedGroupByOnNestedFieldWithFilterAndSumOnReverseNestedField() throws Exception {
    Aggregations result = query(String.format("SELECT sum(reverse_nested(comment.likes,'~comment')) bla FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a')", TEST_INDEX_NESTED_TYPE));
    InternalNested nested = result.get("message.info@NESTED");
    InternalFilter filter = nested.getAggregations().get("myFilter@FILTER");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("comment.likes@NESTED_REVERSED");
        InternalNested innerNested = reverseNested.getAggregations().get("comment.likes@NESTED");
        InternalSum sum = innerNested.getAggregations().get("bla");
        Assert.assertEquals(4.0,sum.getValue(),0.000001);

    }
}
 
Example #8
Source File: AggregationTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void reverseAnotherNestedGroupByOnNestedFieldWithFilterTestWithReverseNestedOnHistogram() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a'),histogram('field'='comment.likes','reverse_nested'='~comment','interval'='2' , 'alias' = 'someAlias' )", TEST_INDEX_NESTED_TYPE));
    InternalNested nested = result.get("message.info@NESTED");
    InternalFilter filter = nested.getAggregations().get("myFilter@FILTER");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("~comment@NESTED_REVERSED");
        InternalNested innerNested = reverseNested.getAggregations().get("~comment@NESTED");
        InternalHistogram histogram = innerNested.getAggregations().get("someAlias");
        Assert.assertEquals(2, histogram.getBuckets().size());

    }
}
 
Example #9
Source File: AggregationTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void reverseToRootGroupByOnNestedFieldWithFilterAndSumOnReverseNestedField() throws Exception {
    Aggregations result = query(String.format("SELECT sum(reverse_nested(myNum)) bla FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a')", TEST_INDEX_NESTED_TYPE));
    InternalNested nested = result.get("message.info@NESTED");
    InternalFilter filter = nested.getAggregations().get("myFilter@FILTER");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("myNum@NESTED");
        InternalSum sum = reverseNested.getAggregations().get("bla");
        Assert.assertEquals(5.0,sum.getValue(),0.000001);

    }
}
 
Example #10
Source File: AggregationTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedOnHistogram() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a'),histogram('field'='myNum','reverse_nested'='','interval'='2' , 'alias' = 'someAlias' )", TEST_INDEX_NESTED_TYPE));
    InternalNested nested = result.get("message.info@NESTED");
    InternalFilter filter = nested.getAggregations().get("myFilter@FILTER");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("someAlias@NESTED");
        InternalHistogram histogram = reverseNested.getAggregations().get("someAlias");
        Assert.assertEquals(3, histogram.getBuckets().size());

    }
}
 
Example #11
Source File: SearchResult.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
public SearchResult(SearchResponse resp, Select select) throws SqlParseException {
	Aggregations aggs = resp.getAggregations();
	if (aggs.get("filter") != null) {
		InternalFilter inf = aggs.get("filter");
		aggs = inf.getAggregations();
	}
	if (aggs.get("group by") != null) {
		InternalTerms terms = aggs.get("group by");
		Collection<Bucket> buckets = terms.getBuckets();
		this.total = buckets.size();
		results = new ArrayList<>(buckets.size());
		for (Bucket bucket : buckets) {
			Map<String, Object> aggsMap = toAggsMap(bucket.getAggregations().getAsMap());
			aggsMap.put("docCount", bucket.getDocCount());
			results.add(aggsMap);
		}
	} else {
		results = new ArrayList<>(1);
		this.total = 1;
		Map<String, Object> map = new HashMap<>();
		for (Aggregation aggregation : aggs) {
			map.put(aggregation.getName(), covenValue(aggregation));
		}
		results.add(map);
	}

}
 
Example #12
Source File: SearchAggregationParser.java    From sql4es with Apache License 2.0 5 votes vote down vote up
/**
 * Parses an ES aggregation into a set of ResultRows
 * @param agg
 * @return
 * @throws SQLException
 */
public void parseAggregation(Aggregation agg, ESResultSet rs) throws SQLException{
	if(agg instanceof Terms){
		dfsAggregations((Terms)agg, rs, rs.getNewRow());
	}else if (agg instanceof InternalFilter){
		processFilterAgg((InternalFilter)agg, rs);
	}else if (agg instanceof InternalCardinality){
		processCardinalityAgg((InternalCardinality)agg, rs);
	}else throw new SQLException ("Unknown aggregation type "+agg.getClass().getName());
}
 
Example #13
Source File: EsProductServiceImpl.java    From macrozheng-mall with MIT License 4 votes vote down vote up
/**
 * 将返回结果转换为对象
 */
private EsProductRelatedInfo convertProductRelatedInfo(SearchResponse response) {
    EsProductRelatedInfo productRelatedInfo = new EsProductRelatedInfo();
    Map<String, Aggregation> aggregationMap = response.getAggregations().getAsMap();
    //设置品牌
    Aggregation brandNames = aggregationMap.get("brandNames");
    List<String> brandNameList = new ArrayList<>();
    for(int i = 0; i<((StringTerms) brandNames).getBuckets().size(); i++){
        brandNameList.add(((StringTerms) brandNames).getBuckets().get(i).getKeyAsString());
    }
    productRelatedInfo.setBrandNames(brandNameList);
    //设置分类
    Aggregation productCategoryNames = aggregationMap.get("productCategoryNames");
    List<String> productCategoryNameList = new ArrayList<>();
    for(int i=0;i<((StringTerms) productCategoryNames).getBuckets().size();i++){
        productCategoryNameList.add(((StringTerms) productCategoryNames).getBuckets().get(i).getKeyAsString());
    }
    productRelatedInfo.setProductCategoryNames(productCategoryNameList);
    //设置参数
    Aggregation productAttrs = aggregationMap.get("allAttrValues");
    List<Terms.Bucket> attrIds = ((LongTerms) ((InternalFilter)productAttrs.getProperty("productAttrs")).getAggregations().getProperty("attrIds")).getBuckets();
    List<EsProductRelatedInfo.ProductAttr> attrList = new ArrayList<>();
    for (Terms.Bucket attrId : attrIds) {
        EsProductRelatedInfo.ProductAttr attr = new EsProductRelatedInfo.ProductAttr();
        attr.setAttrId((Long) attrId.getKey());
        List<String> attrValueList = new ArrayList<>();
        List<Terms.Bucket> attrValues = ((StringTerms) attrId.getAggregations().get("attrValues")).getBuckets();
        List<Terms.Bucket> attrNames = ((StringTerms) attrId.getAggregations().get("attrNames")).getBuckets();
        for (Terms.Bucket attrValue : attrValues) {
            attrValueList.add(attrValue.getKeyAsString());
        }
        attr.setAttrValues(attrValueList);
        if(!CollectionUtils.isEmpty(attrNames)){
            String attrName = attrNames.get(0).getKeyAsString();
            attr.setAttrName(attrName);
        }
        attrList.add(attr);
    }
    productRelatedInfo.setProductAttrs(attrList);
    return productRelatedInfo;
}
 
Example #14
Source File: EsProductServiceImpl.java    From mall with Apache License 2.0 4 votes vote down vote up
/**
 * 将返回结果转换为对象
 */
private EsProductRelatedInfo convertProductRelatedInfo(SearchResponse response) {
    EsProductRelatedInfo productRelatedInfo = new EsProductRelatedInfo();
    Map<String, Aggregation> aggregationMap = response.getAggregations().getAsMap();
    //设置品牌
    Aggregation brandNames = aggregationMap.get("brandNames");
    List<String> brandNameList = new ArrayList<>();
    for(int i = 0; i<((Terms) brandNames).getBuckets().size(); i++){
        brandNameList.add(((Terms) brandNames).getBuckets().get(i).getKeyAsString());
    }
    productRelatedInfo.setBrandNames(brandNameList);
    //设置分类
    Aggregation productCategoryNames = aggregationMap.get("productCategoryNames");
    List<String> productCategoryNameList = new ArrayList<>();
    for(int i=0;i<((Terms) productCategoryNames).getBuckets().size();i++){
        productCategoryNameList.add(((Terms) productCategoryNames).getBuckets().get(i).getKeyAsString());
    }
    productRelatedInfo.setProductCategoryNames(productCategoryNameList);
    //设置参数
    Aggregation productAttrs = aggregationMap.get("allAttrValues");
    List<LongTerms.Bucket> attrIds = ((LongTerms) ((InternalFilter) ((InternalNested) productAttrs).getProperty("productAttrs")).getProperty("attrIds")).getBuckets();
    List<EsProductRelatedInfo.ProductAttr> attrList = new ArrayList<>();
    for (Terms.Bucket attrId : attrIds) {
        EsProductRelatedInfo.ProductAttr attr = new EsProductRelatedInfo.ProductAttr();
        attr.setAttrId((Long) attrId.getKey());
        List<String> attrValueList = new ArrayList<>();
        List<StringTerms.Bucket> attrValues = ((StringTerms) attrId.getAggregations().get("attrValues")).getBuckets();
        List<StringTerms.Bucket> attrNames = ((StringTerms) attrId.getAggregations().get("attrNames")).getBuckets();
        for (Terms.Bucket attrValue : attrValues) {
            attrValueList.add(attrValue.getKeyAsString());
        }
        attr.setAttrValues(attrValueList);
        if(!CollectionUtils.isEmpty(attrNames)){
            String attrName = attrNames.get(0).getKeyAsString();
            attr.setAttrName(attrName);
        }
        attrList.add(attr);
    }
    productRelatedInfo.setProductAttrs(attrList);
    return productRelatedInfo;
}
 
Example #15
Source File: EsProductServiceImpl.java    From macrozheng with Apache License 2.0 4 votes vote down vote up
/**
 * 将返回结果转换为对象
 */
private EsProductRelatedInfo convertProductRelatedInfo(SearchResponse response) {
    EsProductRelatedInfo productRelatedInfo = new EsProductRelatedInfo();
    Map<String, Aggregation> aggregationMap = response.getAggregations().getAsMap();
    //设置品牌
    Aggregation brandNames = aggregationMap.get("brandNames");
    List<String> brandNameList = new ArrayList<>();
    for(int i = 0; i<((Terms) brandNames).getBuckets().size(); i++){
        brandNameList.add(((Terms) brandNames).getBuckets().get(i).getKeyAsString());
    }
    productRelatedInfo.setBrandNames(brandNameList);
    //设置分类
    Aggregation productCategoryNames = aggregationMap.get("productCategoryNames");
    List<String> productCategoryNameList = new ArrayList<>();
    for(int i=0;i<((Terms) productCategoryNames).getBuckets().size();i++){
        productCategoryNameList.add(((Terms) productCategoryNames).getBuckets().get(i).getKeyAsString());
    }
    productRelatedInfo.setProductCategoryNames(productCategoryNameList);
    //设置参数
    Aggregation productAttrs = aggregationMap.get("allAttrValues");
    List<LongTerms.Bucket> attrIds = ((LongTerms) ((InternalFilter) ((InternalNested) productAttrs).getProperty("productAttrs")).getProperty("attrIds")).getBuckets();
    List<EsProductRelatedInfo.ProductAttr> attrList = new ArrayList<>();
    for (Terms.Bucket attrId : attrIds) {
        EsProductRelatedInfo.ProductAttr attr = new EsProductRelatedInfo.ProductAttr();
        attr.setAttrId((Long) attrId.getKey());
        List<String> attrValueList = new ArrayList<>();
        List<StringTerms.Bucket> attrValues = ((StringTerms) attrId.getAggregations().get("attrValues")).getBuckets();
        List<StringTerms.Bucket> attrNames = ((StringTerms) attrId.getAggregations().get("attrNames")).getBuckets();
        for (Terms.Bucket attrValue : attrValues) {
            attrValueList.add(attrValue.getKeyAsString());
        }
        attr.setAttrValues(attrValueList);
        if(!CollectionUtils.isEmpty(attrNames)){
            String attrName = attrNames.get(0).getKeyAsString();
            attr.setAttrName(attrName);
        }
        attrList.add(attr);
    }
    productRelatedInfo.setProductAttrs(attrList);
    return productRelatedInfo;
}
 
Example #16
Source File: EsProductServiceImpl.java    From mall-swarm with Apache License 2.0 4 votes vote down vote up
/**
 * 将返回结果转换为对象
 */
private EsProductRelatedInfo convertProductRelatedInfo(SearchResponse response) {
    EsProductRelatedInfo productRelatedInfo = new EsProductRelatedInfo();
    Map<String, Aggregation> aggregationMap = response.getAggregations().getAsMap();
    //设置品牌
    Aggregation brandNames = aggregationMap.get("brandNames");
    List<String> brandNameList = new ArrayList<>();
    for(int i = 0; i<((Terms) brandNames).getBuckets().size(); i++){
        brandNameList.add(((Terms) brandNames).getBuckets().get(i).getKeyAsString());
    }
    productRelatedInfo.setBrandNames(brandNameList);
    //设置分类
    Aggregation productCategoryNames = aggregationMap.get("productCategoryNames");
    List<String> productCategoryNameList = new ArrayList<>();
    for(int i=0;i<((Terms) productCategoryNames).getBuckets().size();i++){
        productCategoryNameList.add(((Terms) productCategoryNames).getBuckets().get(i).getKeyAsString());
    }
    productRelatedInfo.setProductCategoryNames(productCategoryNameList);
    //设置参数
    Aggregation productAttrs = aggregationMap.get("allAttrValues");
    List<LongTerms.Bucket> attrIds = ((LongTerms) ((InternalFilter) ((InternalNested) productAttrs).getProperty("productAttrs")).getProperty("attrIds")).getBuckets();
    List<EsProductRelatedInfo.ProductAttr> attrList = new ArrayList<>();
    for (Terms.Bucket attrId : attrIds) {
        EsProductRelatedInfo.ProductAttr attr = new EsProductRelatedInfo.ProductAttr();
        attr.setAttrId((Long) attrId.getKey());
        List<String> attrValueList = new ArrayList<>();
        List<StringTerms.Bucket> attrValues = ((StringTerms) attrId.getAggregations().get("attrValues")).getBuckets();
        List<StringTerms.Bucket> attrNames = ((StringTerms) attrId.getAggregations().get("attrNames")).getBuckets();
        for (Terms.Bucket attrValue : attrValues) {
            attrValueList.add(attrValue.getKeyAsString());
        }
        attr.setAttrValues(attrValueList);
        if(!CollectionUtils.isEmpty(attrNames)){
            String attrName = attrNames.get(0).getKeyAsString();
            attr.setAttrName(attrName);
        }
        attrList.add(attr);
    }
    productRelatedInfo.setProductAttrs(attrList);
    return productRelatedInfo;
}
 
Example #17
Source File: EsProductServiceImpl.java    From BigDataPlatform with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 将返回结果转换为对象
 */
private EsProductRelatedInfo convertProductRelatedInfo(SearchResponse response) {
    EsProductRelatedInfo productRelatedInfo = new EsProductRelatedInfo();
    Map<String, Aggregation> aggregationMap = response.getAggregations().getAsMap();
    //设置品牌
    Aggregation brandNames = aggregationMap.get("brandNames");
    List<String> brandNameList = new ArrayList<>();
    for(int i = 0; i<((Terms) brandNames).getBuckets().size(); i++){
        brandNameList.add(((Terms) brandNames).getBuckets().get(i).getKeyAsString());
    }
    productRelatedInfo.setBrandNames(brandNameList);
    //设置分类
    Aggregation productCategoryNames = aggregationMap.get("productCategoryNames");
    List<String> productCategoryNameList = new ArrayList<>();
    for(int i=0;i<((Terms) productCategoryNames).getBuckets().size();i++){
        productCategoryNameList.add(((Terms) productCategoryNames).getBuckets().get(i).getKeyAsString());
    }
    productRelatedInfo.setProductCategoryNames(productCategoryNameList);
    //设置参数
    Aggregation productAttrs = aggregationMap.get("allAttrValues");
    List<LongTerms.Bucket> attrIds = ((LongTerms) ((InternalFilter) ((InternalNested) productAttrs).getProperty("productAttrs")).getProperty("attrIds")).getBuckets();
    List<EsProductRelatedInfo.ProductAttr> attrList = new ArrayList<>();
    for (Terms.Bucket attrId : attrIds) {
        EsProductRelatedInfo.ProductAttr attr = new EsProductRelatedInfo.ProductAttr();
        attr.setAttrId((Long) attrId.getKey());
        List<String> attrValueList = new ArrayList<>();
        List<StringTerms.Bucket> attrValues = ((StringTerms) attrId.getAggregations().get("attrValues")).getBuckets();
        List<StringTerms.Bucket> attrNames = ((StringTerms) attrId.getAggregations().get("attrNames")).getBuckets();
        for (Terms.Bucket attrValue : attrValues) {
            attrValueList.add(attrValue.getKeyAsString());
        }
        attr.setAttrValues(attrValueList);
        if(!CollectionUtils.isEmpty(attrNames)){
            String attrName = attrNames.get(0).getKeyAsString();
            attr.setAttrName(attrName);
        }
        attrList.add(attr);
    }
    productRelatedInfo.setProductAttrs(attrList);
    return productRelatedInfo;
}