0

Im having trouble getting sort to work correctly in my query. I have tried a very simple example and get some unexpected results.

Query

{
  "query": {
    "match_all": {}
  },
  "sort": "name"
}

The result is that the names with numbers in come higher than those without. For example Eurosport 1 will come before Animal Planet.

"sort": [
  "1"
] 

and

"sort": [
  "a"
]

Is whats returned for each respectively.

Do I need something extra to have sort treat the fields as strings for sorting?

I can post more of the responses if its relevant.

Tom Squires
  • 8,848
  • 12
  • 46
  • 72

1 Answers1

0

So it looks like elastic search behaves differently depending on if the field's index is analyzed or not_analyzed. In my case it was analyzed so it was treating "Eurosport 1" as two words due to the whitespace and sorting on that.

see analyzed or not_analyzed, what to choose

Tom Squires
  • 8,848
  • 12
  • 46
  • 72