Hacksign
(Hacksign)
November 4, 2016, 4:13am
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 ?
spinscale
(Alexander Reelsen)
November 7, 2016, 8:21am
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
(Hacksign)
November 7, 2016, 9:04am
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]]
spinscale
(Alexander Reelsen)
November 7, 2016, 9:09am
4
Hey,
can you try
'sort' => [
['modify_time' => ['order' => 'desc']],
]
--Alex
spinscale
(Alexander Reelsen)
November 7, 2016, 9:10am
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
(Hacksign)
November 7, 2016, 10:27am
6
Well, I rechecked Elasticsearch-PHP document ...
Found out sort field's format :
[
'<field>:<order>',
......
]
problem solved .....