两个实体:集合和产品.收集是产品的父母.
我需要按照产品的条款进行搜索,并展示每个产品有4个产品.
收藏品和产品可以部分匹配,但最先匹配.如果匹配不满,则某些条款具有优先权.
示例:搜索"color:red"和"material:stone"需要首先显示红色宝石,然后显示任何其他红色(这是关于集合匹配和产品匹配).
所以,所有这些都通过以下要求解决:
{
"query": {
"has_child": {
"type": "products",
"query": {
"bool": {
"should": [
{
"constant_score": {
"filter": {
"match_all": {}
},
"boost": 1
}
},
{
"constant_score": {
"filter": {
"terms": { "_name": "colors", "colors": [5] }
},
"boost": 1.2
}
},
{
"constant_score": {
"filter": {
"terms": { "_name": "materials", "productTypes": [6] }
},
"boost": 1
}
}
]
}
},
"score_mode": "max",
"inner_hits": {
"size": 4,
"sort": [
"_score"
]
}
}
}, …Run Code Online (Sandbox Code Playgroud)