我需要按下一个顺序对结果进行排序:
- 用户,我关注
- 跟随我的用户
- 所有其他用户
我的用户看起来像这样:
{
"username": "admin"
"followers": [
{
"id": 2,
"username": "kiehn.nicola2"
},
{
"id": 3,
"username": "adaline253"
},
{
"id": 4,
"username": "skuhic4"
}
],
"following": [
{
"id": 2,
"username": "kiehn.nicola2"
},
{
"id": 3,
"username": "adaline253"
},
{
"id": 4,
"username": "skuhic4"
},
{
"id": 5,
"username": "heaney.garth5"
}
]
}
可能吗?
当然,我知道当前的用户 ID 和用户名。
我写了这个查询,但它不起作用(例如,用户 id 为 1):
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"username": {
"value": "*a*",
"boost": 1
}
}
}
]
}
},
"sort": [
{
"following.username": {
"order": "asc",
"nested_path": "following",
"nested_filter": {
"term": {
"following.id": 1
}
}
},
"followers.username": {
"order": "asc",
"nested_path": "followers",
"nested_filter": {
"term": {
"followers.id": 1
}
}
}
}
],
"size": 40
}