ElasticSearch sort order for multiple fields

0x4a6f4672

What is the best way to specify the sort order in ElasticSearch for multiple fields? The query string format does not seem to work at all:

http://elasticsearch_url/index/_search?sort=field1:asc&sort=field2:desc&size=100

One would like to sort first by field1, then by field2, but only one of the fields seems to be sorted correctly. The full notations works better, but the first entries have occasionally the wrong search order:

curl -s -XGET http://elasticsearch_url/index/_search -d '
{
    "sort": [
        { "field1": { "order": "desc" }},
        { "field2": { "order": "desc" }}
    ],
    "size": 100
}'
0x4a6f4672

Apparently the second, full notation works better.

There was another problem that one of the fields contained urls, which was parsed in odd ways by ElasticSearch. Even normal string fields can be difficult to sort, indexing a url in ElasticSearch is even more difficult.

The sort keyword takes in an array that can target multiple fields.

curl -s -XGET http://elasticsearch_url/index/_search -d '
{
    "sort": [
        { "field1": { "order": "desc" }},
        { "field2": { "order": "desc" }}
    ],
    "size": 100
}'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Sort collection by multiple fields in Kotlin

From Dev

ElasticSearch group by multiple fields

From Dev

Search on multiple fields with Elasticsearch

From Dev

Search on multiple fields with ElasticSearch with or, and operators

From Dev

Elasticsearch multiple fields autosuggestion

From Dev

bash sort on multiple fields and deduplicating

From Dev

ElasticSearch and searching on multiple fields in PHP

From Dev

Elasticsearch match multiple fields

From Dev

Realm java sort with multiple fields

From Dev

Elasticsearch getting distance with different sort order

From Dev

ElasticSearch filtering on multiple fields (with aggregration)

From Dev

How to sort struct fields in alphabetical order

From Dev

Fields not getting sorted in alphabetical order in elasticsearch

From Dev

Sort arrays by multiple fields

From Dev

ElasticSearch: sort in specific order

From Dev

Elasticsearch: Sort on different fields depending on type

From Dev

sql complex order by multiple fields

From Dev

Can I sort on multiple fields in numpy structured array with some reversed, a la SQL ORDER BY

From Dev

ElasticSearch and searching on multiple fields in PHP

From Dev

Sort a list by multiple fields

From Dev

Elasticsearch match multiple fields

From Dev

MongoDB sort order on timestamp / ISODate fields

From Dev

elasticsearch sort not working with partial_fields

From Dev

Order By clause on multiple fields with group

From Dev

Elasticsearch sort on multiple queries

From Dev

Sort arrays by multiple fields

From Dev

Order By Dynamically, multiple fields

From Dev

Elasticsearch multiple fields OR query

From Dev

Elasticsearch sort based on multiple fields

Related Related

HotTag

Archive