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

(Marek K) #1


I've got field mapping:


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

(David Pilato) #2

Can you reproduce that with a simple script ?

May be incorrect mapping?

(Marek K) #3

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

(David Pilato) #4

I meant that: https://www.elastic.co/help

(Marek K) #5


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

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"}}

(Christian Dahlqvist) #6

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.

(Marek K) #7

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.

(Marek K) #8

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!

(system) #9