# DSL sort paramter illegal problem

**URL:** <https://discuss.elastic.co/t/dsl-sort-paramter-illegal-problem/64969>\
**Category:** Elasticsearch\
**Created:** [November 4, 2016, 4:13am UTC](https://discuss.elastic.co/t/dsl-sort-paramter-illegal-problem/64969 "2016-11-04T04:13:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hacksign](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hacksign/32/5918_2.png) [@Hacksign](https://discuss.elastic.co/u/Hacksign)\
**Post date:** [November 4, 2016, 4:13am UTC](https://discuss.elastic.co/t/dsl-sort-paramter-illegal-problem/64969/1 "2016-11-04T04:13:59Z")

</div>

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 :

```auto
            $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](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-request-search-after.html) 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 ?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 7, 2016, 8:21am UTC](https://discuss.elastic.co/t/dsl-sort-paramter-illegal-problem/64969/2 "2016-11-07T08:21:54Z")

</div>

Hey,

see the [sort docs](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-request-sort.html) - there is no need so specify desc/asc with score based sorting, as there is no option.

--Alex

---

<div class="post-metadata">

**Author:** ![Hacksign](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hacksign/32/5918_2.png) [@Hacksign](https://discuss.elastic.co/u/Hacksign)\
**Post date:** [November 7, 2016, 9:04am UTC](https://discuss.elastic.co/t/dsl-sort-paramter-illegal-problem/64969/3 "2016-11-07T09:04:34Z")

</div>

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]]

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 7, 2016, 9:09am UTC](https://discuss.elastic.co/t/dsl-sort-paramter-illegal-problem/64969/4 "2016-11-07T09:09:05Z")

</div>

Hey,

can you try

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

```

--Alex

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 7, 2016, 9:10am UTC](https://discuss.elastic.co/t/dsl-sort-paramter-illegal-problem/64969/5 "2016-11-07T09:10:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hacksign](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hacksign/32/5918_2.png) [@Hacksign](https://discuss.elastic.co/u/Hacksign)\
**Post date:** [November 7, 2016, 10:27am UTC](https://discuss.elastic.co/t/dsl-sort-paramter-illegal-problem/64969/6 "2016-11-07T10:27:12Z")

</div>

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

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

```

problem solved .....

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:06pm UTC](https://discuss.elastic.co/t/dsl-sort-paramter-illegal-problem/64969/7 "2017-07-05T22:06:15Z")

</div>


