按名称排序elasticsearch [英] Sort by name elasticsearch

查看:75
本文介绍了按名称排序elasticsearch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用弹性搜索和按名称对我的文档进行排序官方的php客户端,我该如何进行?

I try to sort my documents per name using elastic search & the official php client , how i can proceed ?

    $params = [
        'index' => $this->index ,
        'type' => 'videos',
        'from' => $this->uri->segment(2),
        'size' => 12,
        'body' => [
        'query' => [
        'filtered' => [
            'filter' => [
                'term' => [ 'name' => $query ] ,
                'term' => [ 'tags' => $query ]
              ]
           ]
        ]
      ]
    ];




    $data['results'] = $this->client->search($params);

推荐答案

我知道这个问题已有一年多的历史了,但是在互联网上很难找到答案,所以我还是会回答. > 要指定要排序的字段和排序顺序,请使用以下语法:

I know this question is over a year old, but the answer is not easy to find on the internet, so I'll answer it anyway.
To specify the field to sort on and the order to sort in, use the following syntax:

$params['sort'] = array('updated_at:desc');

要在多个字段上排序:

$params['sort'] = array('updated_at:desc', 'user_id:asc', ...);

这篇关于按名称排序elasticsearch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆