elasticsearch 在电商环境下 根据菜单分类进行排序 求教
0 ). 现在问题是
在电商环境下
一个商品是有多个菜单分类(productGroup)的
现在是需要查询结果中包含 productGroup.id 为 2117
并且 根据 productGroup.id 为 2117 的sort 值进行排序
1. elasticsearch 查询问题
##查询条件是
{
"query": {
"bool": {
"must": [
{
"term": {
"productGroup.id": "2117"
}
}
],
"must_not": [],
"should": []
}
},
"from": 1,
"size": 2,
"sort": {
"productGroup.sort": {
"order": "asc",
"mode":"min",
"nested_filter": {
"term": {
"productGroup.id": {
"value": "2117"
}
}
}
}
},
"_source": {
"includes": [
"product_id",
"product_name",
"productGroup.id",
"productGroup.sort"
],
"excludes": []
}
}
##结果集是
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 128,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "test123",
"_type": "goods",
"_id": "71698",
"_score": 1.0,
"_source": {
"productGroup": [
{
"id": 2061,
"sort": 255
},
{
"id": 2113,
"sort": 255
},
{
"id": 2117,
"sort": 255
}
],
"product_id": 71698
}
},
{
"_index": "test123",
"_type": "goods",
"_id": "69354",
"_score": 1.0,
"_source": {
"productGroup": [
{
"id": 1992,
"sort": 255
},
{
"id": 2113,
"sort": 255
},
{
"id": 2117,
"sort": 4
}
],
"product_id": 69354
}
}
]
}
}