elasticsearch排序根本不起作用

时间:2016-02-09 06:32:49

标签: php elasticsearch elastica

我使用下面的代码进行排序

//http://10.132.150.186:8010/rest-client/service/movie/romance/hindi/2012/0/10/asc

if($urlParam[1] != 'all')
    $params['body']['query']['filtered']['filter']['and'][]['term']['gener'] = $urlParam[1];

if($urlParam[2] != 'all')
    $params['body']['query']['filtered']['filter']['and'][]['term']['language'] = $urlParam[2];

if($urlParam[3] != 'all')
    $params['body']['query']['filtered']['filter']['and'][]['term']['year'] = $urlParam[3];

if($urlParam[4] != 'all')
    $params['from'] = $urlParam[4];

if($urlParam[5] != 'all')
    $params['size'] = $urlParam[5]; 

if($urlParam[6] != 'all')
    $params['sort']['movieid'] = ['order' => $urlParam[6]]; 

$result = $client->search($params);

Url在上面的代码中也提到了,我正在映射上面的代码。 除第6个条件外,所有条件都按预期工作(即排序不起作用)。

以下是我得到的输出

Array
(
    [0] => Array
        (
            [_index] => pvrmod
            [_type] => movie
            [_id] => 22
            [_score] => 1
            [_source] => Array
                (
                    [movieid] => 22
                    [title] => namaste london22
                    [desc] => namaste london description
                    [gener] => romance
                    [language] => hindi
                    [year] => 2012
                    [tags] => Array
                        (
                            [0] => romance
                            [1] => akshay kumar
                            [2] => caterina kaif
                            [3] => romance
                            [4] => hindi
                            [5] => namaste london
                        )

                    [actor] => Array
                        (
                            [0] => akshay kumar
                            [1] => caterina kaif
                        )

                )

        )

    [4] => Array
        (
            [_index] => pvrmod
            [_type] => movie
            [_id] => 29
            [_score] => 1
            [_source] => Array
                (
                    [movieid] => 29
                    [title] => namaste london29
                    [desc] => namaste london description
                    [gener] => romance
                    [language] => hindi
                    [year] => 2012
                    [tags] => Array
                        (
                            [0] => romance
                            [1] => akshay kumar
                            [2] => caterina kaif
                            [3] => romance
                            [4] => hindi
                            [5] => namaste london
                        )

                    [actor] => Array
                        (
                            [0] => akshay kumar
                            [1] => caterina kaif
                        )

                )

        )

    [5] => Array
        (
            [_index] => pvrmod
            [_type] => movie
            [_id] => 21
            [_score] => 1
            [_source] => Array
                (
                    [movieid] => 21
                    [title] => namaste london21
                    [desc] => namaste london description
                    [gener] => romance
                    [language] => hindi
                    [year] => 2012
                    [tags] => Array
                        (
                            [0] => romance
                            [1] => akshay kumar
                            [2] => caterina kaif
                            [3] => romance
                            [4] => hindi
                            [5] => namaste london
                        )

                    [actor] => Array
                        (
                            [0] => akshay kumar
                            [1] => caterina kaif
                        )

                )

        )

)

请帮忙。

提前致谢。

1 个答案:

答案 0 :(得分:2)

得到解决方案。实际上我把条件放错了地方。 我需要放$params['body']['sort']['movieid'] = ['order' => $urlParam[6]]; 而不是$params['sort']['movieid'] = ['order' => $urlParam[6]];