Php ElasticSearch按嵌套字段值排序
我需要按下一个顺序对结果进行排序:Php ElasticSearch按嵌套字段值排序,php,symfony,elasticsearch,Php,Symfony,elasticsearch,我需要按下一个顺序对结果进行排序: 用户,这是我所关注的 用户们,我就是这么想的 所有其他用户 我有这样的用户: { "username": "admin" "followers": [ { "id": 2, "username": "kiehn.nicola2" }, { "id": 3, "username": "adaline2
- 用户,这是我所关注的
- 用户们,我就是这么想的
- 所有其他用户
{
"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):
我会通过提升来做到这一点;将追随者中具有搜索者id的点击量增加一个数量,然后将搜索者位于其“以下”字段中的点击量增加一个较低的值: 注意:本例中搜索者的id为55
"query": {
"bool": {
"should": [
{
"nested": {
"path": "followers",
"query": {
"term" : { "followers.id": { "value": 55, "boost": 3.0 } }
}
}
},
{
"nested": {
"path": "following",
"query": {
"term" : { "following.id": { "value": 55, "boost": 2.0 } }
}
}
},
{
"match_all": { "boost": 1.0 }
}
]
}
}
如果搜索者在命中的追随者字段中,则搜索者跟踪该命中,因此提升幅度最高,等等
您说您需要所有其他用户,因此在最后使用了
“match_all:{}
查询。我会通过提高点击率来实现这一点;将追随者中有搜索者id的点击率提高一个数量,然后将搜索者在其“following”字段中的点击率提高一个较低的值:
注意:本例中搜索者的id为55
"query": {
"bool": {
"should": [
{
"nested": {
"path": "followers",
"query": {
"term" : { "followers.id": { "value": 55, "boost": 3.0 } }
}
}
},
{
"nested": {
"path": "following",
"query": {
"term" : { "following.id": { "value": 55, "boost": 2.0 } }
}
}
},
{
"match_all": { "boost": 1.0 }
}
]
}
}
如果搜索者在命中的追随者字段中,则搜索者跟踪该命中,因此提升幅度最高,等等
您说您需要所有其他用户,因此在末尾使用了“match_all:{}
查询