Skip to content
Advertisement

Spring Elasticsearch sorting by field with whitespace

I need to sort my documents by some fields, one sorting – one field. But every time I’m getting wrong sorting. In document I have uid and title. Uid in document looks like ‘AAA-100’ and title could be just a text with spaces. And when i’m trying to sort by those fields i’m getting wrong order. For example when i’m trying to sort by title in ASC order i’m getting this:

JavaScript

and when order is DESC

JavaScript

for uid ASC order looks good but DESC is looking like

JavaScript

This is fields from my entity class for my document:

JavaScript

where INDEX_ANALYZER and SEARCH_ANALYZER:

JavaScript

What is wrong? Why sorting is not working properly?

Advertisement

Answer

Just create one field for sort, new mapping and set type “keyword” for field you want to sort. It seem like

JavaScript

Dont set another type on field sort. Its may be make wrong sort result. I use this way on vietnamese string and still get success.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement