# \[ES 1.7.1\] Sort is not working for mapped field (long)

**URL:** <https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720>\
**Category:** Elasticsearch\
**Created:** [September 21, 2015, 4:25pm UTC](https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720 "2015-09-21T16:25:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaKro](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@MaKro](https://discuss.elastic.co/u/MaKro)\
**Post date:** [September 21, 2015, 4:25pm UTC](https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720/1 "2015-09-21T16:25:35Z")

</div>

Hi.

I've got field mapping:

```
"created":{"type":"float","include_in_all":true}

```

I'm executing a bool query which ha sort part:

```
  "sort" : [ 
              {
                "created" : {
                              "order" : "desc"
                            }
              } 
]

```

And in the response I get:

```
Parse Failure [No mapping found for [created] in order to sort on]];

```

Why I get this? If I'm adding a "unmapped\_type":"long", I don't get that error but I get results in wrong order

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 21, 2015, 4:39pm UTC](https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720/2 "2015-09-21T16:39:59Z")

</div>

Can you reproduce that with a simple script ?

May be incorrect mapping?

---

<div class="post-metadata">

**Author:** ![MaKro](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@MaKro](https://discuss.elastic.co/u/MaKro)\
**Post date:** [September 21, 2015, 5:30pm UTC](https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720/3 "2015-09-21T17:30:33Z")

</div>

What do you mean with a simple script ?

Mapping is correct (in my opionion) as I checked it with mapping API and in the response I get what I pasted in the first post.

This is my mapping:

```
"mappings": {
		"myIndex": {
			"_id": {
				"path": "documentId"
			},
			"properties": {
				"documentId": {
					"type": "string",
					"include_in_all": false,
					"index": "not_analyzed"
				}
				"created": {
					"type": "float",
					"include_in_all": true
				}
			}
 		}
	}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 21, 2015, 5:42pm UTC](https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720/4 "2015-09-21T17:42:50Z")

</div>

I meant that: [https://www.elastic.co/help](https://www.elastic.co/help)

---

<div class="post-metadata">

**Author:** ![MaKro](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@MaKro](https://discuss.elastic.co/u/MaKro)\
**Post date:** [September 21, 2015, 5:57pm UTC](https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720/5 "2015-09-21T17:57:37Z")

</div>

[https://gist.github.com/Emteka/561d08ba081108d46afa](https://gist.github.com/Emteka/561d08ba081108d46afa)

This is a simple script, and sorting is not working for me.  
Result should be:  
4  
1  
2  
3  
And I get them in the same order all the time

UPDATE:  
To get the error from post one please use thise query:

```
curl -XPOST 'author.local.telegraph.co.uk:9200/_search' -d '{
"query" : {
			"match_phrase_prefix": {"field1":"kimchy"}
},
"sort" : [
   {"fieldForSort" : {"order" : "desc"}}
]
}'
```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 21, 2015, 6:36pm UTC](https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720/6 "2015-09-21T18:36:17Z")

</div>

> [@MaKro](#):
>
> "mappings" : {  
> "asset" : {

The mapping you provided applies to type 'asset' but you are indexing into type 'tweet', and 'fieldForSort' is therefore mapped as a string. Once I changed 'asset' to 'tweet' in the template it seemed to work and return the expected order.

---

<div class="post-metadata">

**Author:** ![MaKro](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@MaKro](https://discuss.elastic.co/u/MaKro)\
**Post date:** [September 21, 2015, 7:22pm UTC](https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720/7 "2015-09-21T19:22:35Z")

</div>

Good spot. I checked mine applicaiton code, (I'm using java Search API), and type is set properly. Can I check if the mapping was used for certain query?

I tried to add explain to the query but results say nothing to me.

---

<div class="post-metadata">

**Author:** ![MaKro](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@MaKro](https://discuss.elastic.co/u/MaKro)\
**Post date:** [September 21, 2015, 7:53pm UTC](https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720/8 "2015-09-21T19:53:27Z")

</div>

Ehh kill me.

My field was set to float, instead of long. Sorting wasn't working because of that (I saved my documents with long value instead of float, so the mapping didn't applied).

Tahnk you everyone for help and tips!

---

<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, 11:48pm UTC](https://discuss.elastic.co/t/es-1-7-1-sort-is-not-working-for-mapped-field-long/29720/9 "2017-07-05T23:48:57Z")

</div>


