Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

432
Visualizações
How to sort on field type ''text" in Elastic search

I am working on elastic search multiple field sort query, I have data in the following format:

{
  "person_name" : "Abraham Benjamin deVilliers",
  "created_on": "Tue, 02 Apr 2018 16: 17: 54 GMT",
  "name": "Abraham",
  "office":{
     "name":"my_office"
  }
},
{
  "person_name" : "John Bradshaw",
  "created_on": "Thu Apr 05 2018 14:42:30 GMT",
  "name": "jhon",
  "office": {
     "name":"Abraham deVilliers"
  }
},
{
  "person_name" : "John Bradshaw",
  "created_on": "Tue, 03 Apr 2018 11: 39: 17 GMT",
  "name": "Abraham deVilliers",
  "office": {
     "name":"blabla"
  }
}

Where the field person_name is of type text and created_on is of type string. I have to sort the above response based on the fields person_name and created_on.

The query we tried is as follows:

GET /my_index/_search

{
    sort: [{ 
             "person_name": { "order": "asc" },
             "created_on": { "order": "desc" }
    }]
}

While sorting response with the above query I am getting the following error:

message: '[illegal_argument_exception] Fielddata is disabled on text fields by default. Set fielddata=true on [person_name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.'

On searching, we found we need to modify the mapping of the field person_name from type text to of type keyword. But we can't modify existing mapping as it already contains millions of records.

Is there any other way to perform a sort query on the text field without altering the existing mapping of elastic search?.

Any help will be appreciated.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

There are two ways to achieve what you need.

  1. Add a new multi-field field . When using multiple fields, each time you index a new field, elasticsearch will automatically apply different parser logic for the field it refers to. The field without raw will not be parsed, which means it will be a term in total, so it can be used for sorting. To do this you'll need to update your mapping and then use the reindex api to update your data (it basically creates a new index and then changes your app to use the new index instead of the old one, to do this without downtime you can use a aliases ). Another way to update the index without creating a new one is to use the update_by_query API .
  2. If you just want this type to work without changing anything, you can use scripting . Basically, it will pick the saved value and sort based on that. But this is not effective for long time use. This is quick and dirty, so treat it with care.

All links point to the official elasticsearch documentation.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda