Query and receive response in alphabetic order

Hello everyone, i'm doing a query like this:

query : { match_all: {}}, _source: 'titulo'};

And what I receive as response in hits.hits is:

[{"_index":"xtrorigem","_type":"empresas_publicas","_id":"licencas_ambientais_ibama","_score":1,"_source":{"titulo":"Licenças Ambientais - IBAMA"}},{"_index":"xtrorigem","_type":"empresas_publicas","_id":"empresas_publicas","_score":1,"_source":{"titulo":"Empresas Brasil"}},{"_index":"xtrorigem","_type":"empresas_publicas","_id":"telefones_celulares","_score":1,"_source":{"titulo":"Telefones"}},{"_index":"xtrorigem","_type":"empresas_publicas","_id":"suframa_pessoas","_score":1,"_source":{"titulo":"SUFRAMA - Pessoas"}},{"_index":"xtrorigem","_type":"empresas_publicas","_id":"e105","_score":1,"_source":{"titulo":"Domicílios por Bens Duráveis"}}]

The thing is, is there a parameter or something to receive that awnser in an alphabetic order? Based on the field "titulo" for example.

Thanks in advance.

Yes, you can add a sort clause to your request. The documentation has some examples.

Something that you want to keep in mind is that if you went with default mappings, then you will want to sort on titulo.keyword instead of titulo.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.