# Sorting is not giving accurate result

**URL:** <https://discuss.elastic.co/t/sorting-is-not-giving-accurate-result/60029>\
**Category:** Elasticsearch\
**Created:** [September 8, 2016, 2:01am UTC](https://discuss.elastic.co/t/sorting-is-not-giving-accurate-result/60029 "2016-09-08T02:01:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amajumdarinfa](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@amajumdarinfa](https://discuss.elastic.co/u/amajumdarinfa)\
**Post date:** [September 8, 2016, 2:01am UTC](https://discuss.elastic.co/t/sorting-is-not-giving-accurate-result/60029/1 "2016-09-08T02:01:51Z")

</div>

I am trying some simple sort on an Elasticsearch 2.3.1 index.

The index mapping contains an object named "user" which has a few embedded keys.. one of them is also called "user". So I tried to search by "user.user". But the search result is not accurate at all. However sort results based on any key which is not inside an embedded object is fine.

What am I missing ?

Part of index mapping:

"mappings": {  
"detail": {  
"properties": {  
...  
. ...  
"user": {  
"properties": {  
"department": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"location": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"user": {  
"type": "string",  
"index": "not\_analyzed"  
},  
}  
"

Excerpt from the java code:

> ```
> SearchRequestBuilder requestBuilder = client.prepareSearch().setIndices("ua_sensitive").setTypes("detail")
> .setFetchSource(new String[]{"eventUid", "timeOfEventMilli", "user.user"}, null)
> addSort(SortBuilders.fieldSort("user.user").order(SortOrder.ASC));
> 
> ```

> ```
> SearchResponse response = requestBuilder.execute().actionGet();
> 
> ```

Thanks  
Abhijit

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [September 8, 2016, 8:26am UTC](https://discuss.elastic.co/t/sorting-is-not-giving-accurate-result/60029/2 "2016-09-08T08:26:43Z")

</div>

Just tried to recreate your problem and it looks to be working for me.

Can you post example docs that show the error?

---

<div class="post-metadata">

**Author:** ![amajumdarinfa](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@amajumdarinfa](https://discuss.elastic.co/u/amajumdarinfa)\
**Post date:** [September 9, 2016, 6:41pm UTC](https://discuss.elastic.co/t/sorting-is-not-giving-accurate-result/60029/3 "2016-09-09T18:41:45Z")

</div>

Thanks Mark. I found the reason. In my mapping the field was "not\_analyzed", so Elasticsearch was performing case-sensitive sort.  
Now I am using a custom analyzer to make the comparison case-insensitive.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:21pm UTC](https://discuss.elastic.co/t/sorting-is-not-giving-accurate-result/60029/4 "2017-07-05T22:21:28Z")

</div>


