0

I tried to sort results with a title but it didn't work properly.


Query :

GET /products/_search
{
        "sort": [
            { "title.keyword":   { "order": "desc" }}
          ],
        "query": {
           ....
        },

}

Mapping

"mappings" : {
      "properties" : {
        ...
        "title" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        ...
      }
    }

Results

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 826,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "products",
        "_type" : "_doc",
        "_id" : "1457580605505",
        "_score" : null,
        "_source" : {
          "id" : 1457580605505,
          "title" : "Étui-portefeuille multifonction pour iPhone",  <-----
          "body_html" : "description here",

after googling I didn't found the right answer for my case. maybe because I'm using ES7 and solution giving not compatible with it.
I have multiple products start with Z...
thanks

1
  • 1
    add some of your data as well for a complete understanding Commented May 3, 2019 at 11:12

1 Answer 1

2

É is after Z in character sorting. ( É is different from E ). When you want to sort on some string in elastic you should apply a normalizer to your field to achieve natural sorting.

You should go to this documentation page : normalizer

In your case since you use french language, your normalizer should be composed of lowercase and ascii_folding filters. So the example in the documentation page should perfectly match your needs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.