Elasticsearch-php: How to include additional sort options using elasticsearch-php client

Created on 27 Oct 2018  路  4Comments  路  Source: elastic/elasticsearch-php

Summary of problem or feature request

Hello, according to the inline documentation for sorting in the elasticsearch-php client, in order to use sorting it is described as thus:

['sort'] = (list) A comma-separated list of <field>:<direction> pairs

How do you add additional sort options such as: "ignore_unmapped": true as described here: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#geo-sorting ?

Code snippet of problem

I tried formatting the sort options like this:

[
     "sort" => [
        "publish_date" => [
             "order" => "desc",
             "ignore_unmapped" => true
         ]
    ]
]

but this resulted in a request contains unrecognized parameters: [sort[publish_date][ignore_unmapped]] error.

System details

  • Operating System: Alpine 3.7.0
  • PHP Version: 7.1.20
  • ES-PHP client version: v6.0.1
  • Elasticsearch version: 6.4.0

Most helpful comment

IMPORTANT: If you want to use more advanced sorting don't use the sort parameter of the elasticsearch php client but instead put sort under body. Just lost 1h figuring this out :).

All 4 comments

You may put publish_date in an array:

[
     "sort" => [
        [
            "publish_date" => ["order" => "desc", "ignore_unmapped" => true]
        ]
    ]
]

Thanks. I'll give that a try.

IMPORTANT: If you want to use more advanced sorting don't use the sort parameter of the elasticsearch php client but instead put sort under body. Just lost 1h figuring this out :).

I ended up having to put the sort parameter under the body before it worked for me. Thanks for the heads up @hacfi

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marksparrish picture marksparrish  路  6Comments

PascalThesing picture PascalThesing  路  7Comments

ls
ssanchezromero picture ssanchezromero  路  6Comments

sebsel picture sebsel  路  3Comments

grokify picture grokify  路  5Comments