DSL sort paramter illegal problem


(Hacksign) #1

Hi there

I'm using elasticsearch-php & upgraded ealsticsearch from 2.3.2 to 5.0.0, and there is something wrong with DSL sort field.
PHP code :

            $dsl = [
                'from' => G('elasticsearch')['page_size'] * ($_GET['page'] - 1),
                'size' => G('elasticsearch')['page_size'],
                'index' => 'logs-xxxx',
                'timeout' => '55s',
                'sort' => [
                    ['_score' => 'desc']
                ],
                ........
            ];

I got an exception :
illegal_argument_exception: request [/logs-xxxx/_search] contains unrecognized parameter: [sort[0][_score]]

According to this document, sort parameter should firstly be an array then cotains dicts which described sort fields & orders.

So is there anything wrong with my php code ?


(Alexander Reelsen) #2

Hey,

see the sort docs - there is no need so specify desc/asc with score based sorting, as there is no option.

--Alex


(Hacksign) #3

Well, _score is my test field.
Replace _score to any self-defined field also caused this exception :

 16             $dsl = [
 17                 'from' => G('elasticsearch')['page_size'] * ($_GET['page'] - 1),
 18                 'size' => G('elasticsearch')['page_size'],
 19                 'index' => 'logs-xxxx',
 20                 'timeout' => '55s',
 21                 'sort' => [
 22                     ['modify_time' => 'desc']
 23                 ],
 24             ];   

where modify_time in the mapping is :

        "properties" : {
          "modify_time" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss"
          },
          .....

there is still exception occured :

illegal_argument_exception: request [/logs-xxxx/_search] contains unrecognized parameter: [sort[0][modify_time]]


(Alexander Reelsen) #4

Hey,

can you try

'sort' => [
        ['modify_time' => ['order' => 'desc']],
    ]

--Alex


(Alexander Reelsen) #5

Hey

uhm wait, are those HTTP parameters? Did you ensure that this is the body being sent? IIRC by setting the body field - I am no PHP expert though.

--Alex


(Hacksign) #6

Well, I rechecked Elasticsearch-PHP document ...
Found out sort field's format :

[
    '<field>:<order>',
    ......
] 

problem solved .....


(system) #7