按内部匹配量对父级用户列表进行排序

时间:2019-01-01 13:29:00

标签: php laravel elasticsearch

我在Elasticsearch中有20万个用户,每个用户都有自己的收件箱。现在假设三个用户用户A,B和C。用户A和用户C向用户B发送消息。因此,当用户B从elasticsearch获取用户列表时,用户A和C应该位于用户列表的顶部,因为A和B最最近发送给用户B的消息。我编写了下面给出的Elasticsearch查询

{
  "_source": [
    "db_id",
    "username",
    "message_privacy"
  ],
  "from": "0",
  "size": "40",
  "sort": [{"messages_received.created_at" : "desc"}],
  "query": {
    "bool": {
      "must": [
        {
           "term":{
             "type":"user"
           }
        },
        {
          "has_child": {
            "type": "messages_received",
            "inner_hits": {
              "sort": [
                {
                  "created_at": "desc"
                }
              ],
              "size": 1,
              "_source": [
                "id",
                "user_id",
                "object_id",
                "created_at"
              ]
            },
            "query": {
              "bool": {
                "must": [
                  {
                    "term": {
                      "object_id": "u-5"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

但是当我运行查询时,它给了我错误

  

{“错误”:{       “根本原因”: [         {           “ type”:“ query_shard_exception”,           “ reason”:“未找到[messages_received.created_at]的映射以进行排序”,           “ index_uuid”:“ 5jsM1khYRrC0cjWbRjsx5A”,           “ index”:“趋势”         }       ]

我在Google上搜索了此问题,但没有找到适合我的情况的解决方案。

映射

{
 "type": {
            "type": "join",
            "eager_global_ordinals": true,
            "relations": {
              "post": [
                "comments",
                "place",
                "media",
                "views",
                "likes",
                "post_box"
              ],
              "box": "posts",
              "user": [
                "user_views",
                "user_likes",
                "followers",
                "post",
                "blocked",
                "followings",
                "box",
                "block",
                "notifications",
                "messages_received",
                "messages_sent"
              ],
              "posts": "posts_views"
            }
          }}

0 个答案:

没有答案