Elasticsearch: sorting Spanish double names alphabetically

I am making an Elasticsearch query and I want the results to be sorted alphabetically by last name. My problem: the names of all Spanish double names, and ES does not order them as I would like. I would prefer the order to be as follows:

Batres Rivera
Batrín Chojoj
Fion Morales
Lopez Giron
Martinez Castellanos
Milán Casanova

This is my request:

{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "Last Name": {
        "order": "asc"
      }
    }
  ]
}

The order I get with this is:

Batres Rivera
Batrín Chojoj
Milán Casanova
Martinez Castellanos
Fion Morales
Lopez Giron

Thus, it is not sorted by the first line, but any of them (Batres, Batrin, Casanova, Castellanos, Fion, Giron).
If I try extra

{
    "order": "asc",
    "mode": "max"
}

then I get:

Batrín Chojoj
Lopez Giron
Martinez Castellanos
Milán Casanova
Fion Morales
Batres Rivera

All fields are indexed by default, I checked with

curl -XGET localhost/my_index/_mapping 

and i will be back

my_index: {
    my_type: {
        properties: {
            FirstName: {
                type: string
            }LastName: {
                type: string
            }MiddleName: {
                type: string
            }
            ...
        }
    }
}

Does anyone know how to get ordered results to be ordered in alphabetical order using the start line of the last name?

Thanks!

+4
2

, LastName , Batres Rivera : batres rivera. , " ". , , (min max) .

, LastName (Batres Rivera) ,

{ "type": "string", "index": "not_analyzed"}

, : rivera .

: .. : .

0.90. * :

curl -XPUT "http://localhost:9200/my_index" -d'
{
   "mappings": {
      "my_type": {
         "properties": {
            "LastName": {
               "type": "multi_field",
               "fields": {
                  "LastName": {
                     "type": "string"
                  },
                  "raw": {
                     "type": "string",
                     "index": "not_analyzed"
                  }
               }
            }
         }
      }
   }
}'

1.0. * multi_field , :

curl -XPUT "http://localhost:9200/my_index" -d'
{
   "mappings": {
      "my_type": {
         "properties": {
            "LastName": {
               "type": "string",
               "fields": {
                  "raw": {
                     "type": "string",
                     "index": "not_analyzed"
                  }
               }
            }
         }
      }
   }
}'

, LastName , LastName.raw :

curl -XGET "http://localhost:9200/my_index/my_type/_search" -d'
{
   "query": {
      "match": {
         "LastName": "rivera"
      }
   },
   "sort": "LastName.raw"
}'

,

ICU ( ). , :

curl -XPUT "http://localhost:9200/my_index" -d'
{
   "settings": {
      "analysis": {
         "analyzer": {
            "folding": {
               "type": "custom",
               "tokenizer": "icu_tokenizer",
               "filter": [
                  "icu_folding"
               ]
            },
            "es_sorting": {
               "type": "custom",
               "tokenizer": "keyword",
               "filter": [
                  "lowercase",
                  "spanish"
               ]
            }
         },
         "filter": {
            "spanish": {
               "type": "icu_collation",
               "language": "es"
            }
         }
      }
   },
   "mappings": {
      "my_type": {
         "properties": {
            "LastName": {
               "type": "string",
               "analyzer": "folding", 
               "fields": {
                  "raw": {
                     "type": "string",
                     "analyzer": "es_sorting"
                  }
               }
            }
         }
      }
   }
}'

folding, LastName, Muñoz Rivera munoz ( ~) rivera. , munoz muñoz .

es_sorting, Muñoz Rivera ( ) -.

:

curl -XGET "http://localhost:9200/my_index/my_type/_search" -d'
{
   "query": {
      "match": {
         "LastName": "rivera"
      }
   },
   "sort": "LastName.raw"
}'
+13

All Articles