Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
mall
Commits
e0bcd0ce
Commit
e0bcd0ce
authored
Jun 08, 2019
by
macro
Browse files
elasticsearch 聚合搜索结果集映射修改
parent
df5a6b28
Changes
1
Hide whitespace changes
Inline
Side-by-side
mall-search/src/main/java/com/macro/mall/search/service/impl/EsProductServiceImpl.java
View file @
e0bcd0ce
...
...
@@ -15,6 +15,7 @@ import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import
org.elasticsearch.search.aggregations.Aggregation
;
import
org.elasticsearch.search.aggregations.AggregationBuilders
;
import
org.elasticsearch.search.aggregations.bucket.filter.InternalFilter
;
import
org.elasticsearch.search.aggregations.bucket.nested.InternalNested
;
import
org.elasticsearch.search.aggregations.bucket.terms.LongTerms
;
import
org.elasticsearch.search.aggregations.bucket.terms.StringTerms
;
import
org.elasticsearch.search.aggregations.bucket.terms.Terms
;
...
...
@@ -247,25 +248,25 @@ public class EsProductServiceImpl implements EsProductService {
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);
List
<
Long
Terms
.
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
<
String
Terms
.
Bucket
>
attrValues
=
((
StringTerms
)
attrId
.
getAggregations
().
get
(
"attrValues"
)).
getBuckets
();
List
<
String
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
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment