Sorting of fields with special charecters


(Sawyer Ford) #1

Currently we have used the elastic sort sorting capability in our Java application for sorting or a field called description, but the sort does not return a correct order.

Our field consists of special charecters, (#,$,%,&, and so on)...

What changes should we make, we have added the below code for sorting

 nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort(ElasticsearchFieldConstant.ELASTIC_BROADCAST_DESCRIPTION)
                            .order("Description");
                    return nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("_score").order(SortOrder.ASC))
                            .build();

(David Pilato) #2

Please format your code using </> icon as explained in this guide. It will make your post more readable.

Or use markdown style like:

```
CODE
```

but the sort does not return a correct order.

What does it return? Why do you think it's not the correct order? What would you expect?

Could you provide a full recreation script as described in

It will help to better understand what you are doing.
Please, try to keep the example as simple as possible.

Anyway, it's often a question of analyzers. You can analyze the same text for different purposes with subfields (aka multifields) and use one method for searching and the other for sorting.


(Sawyer Ford) #3

As expected in the sense, the sorting should be with order for the following example

If the list of description are

{#Hirekrekre, $fmsdklfmsklfs, Hi I am fine, Hi $190 for you, subscribe me on #hash tag}

Then I like to know what will be the sorted order returned by the current default elastic search sorting , if the list of description are above.

If it does implement asciifolding by default, then is the sorting order I am recieving for strings with special charecters is fine?


(David Pilato) #4

Then I like to know what will be the sorted order returned by the current default elastic search sorting , if the list of description are above.

Just try it and you will get the answer.

Again, if you need more help please provide a full recreation script as I mentioned before. That will help.


(Sawyer Ford) #5

Actually the current problem is on the Production environment that we are facing, We are not getting the sorting results of the description as per the sorting order(ASC/DESC).

Basically the description contains alphabets, special charecters, white spaces, numbers and everything

And we have been trying sorting by description with the above code, which is returning large list of strings which are in a order.

Now I would like to know whether elastic search provides the sorting order(handles the special charecters sorting, numbers inside it everything inside it) by default or should we customize the script

As we are on production and the functionality has gone long ago, I am not able to get the script.


(David Pilato) #6

But you can hopefully start a local test instance and try that with your mapping and settings, can't you?


(system) #7

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