Sorting on date field issue

I'm having an issue with sorting on a date field. The field is defined
in my mapping as:

        "created_on" : {"type" : "date", "format" : "YYYY-MM-DD

HH:mm:ss"},

When I do a simple matchAll + sort query, the first result is way
newer than I'd expect:

$ curl 'http://localhost:9200/places/_search?pretty=true' -d'{"sort":
["created_on"], "query": {"match_all": {}}, "fields": ["created_on"],
"size": 1}'

{
"took" : 1,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1788,
"max_score" : null,
"hits" : [ {
"_index" : "places",
"_type" : "place",
"_id" : "436",
"_score" : null,
"fields" : {
"created_on" : "2010-12-01 00:33:34"
},
"sort" : [ 1262306014000 ]
} ]
}
}

But there're clearly docs that are older. For example, the one with
_id 435:

$ curl 'http://localhost:9200/places/place/435'

{"_index":"places","_type":"place","_id":"435", "_source" : {....,
"created_on": "2010-11-30 23:01:25", ......}}

Am I doing something wrong?

Gist a curl recreation.
On Friday, February 18, 2011 at 9:17 PM, Andrei wrote:

I'm having an issue with sorting on a date field. The field is defined
in my mapping as:

"created_on" : {"type" : "date", "format" : "YYYY-MM-DD
HH:mm:ss"},

When I do a simple matchAll + sort query, the first result is way
newer than I'd expect:

$ curl 'http://localhost:9200/places/_search?pretty=true' -d'{"sort":
["created_on"], "query": {"match_all": {}}, "fields": ["created_on"],
"size": 1}'

{
"took" : 1,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1788,
"max_score" : null,
"hits" : [ {
"_index" : "places",
"_type" : "place",
"_id" : "436",
"_score" : null,
"fields" : {
"created_on" : "2010-12-01 00:33:34"
},
"sort" : [ 1262306014000 ]
} ]
}
}

But there're clearly docs that are older. For example, the one with
_id 435:

$ curl 'http://localhost:9200/places/place/435'

{"_index":"places","_type":"place","_id":"435", "_source" : {....,
"created_on": "2010-11-30 23:01:25", ......}}

Am I doing something wrong?

Never mind, I had a wrong date format in the field mapping - used DD
instead of dd for the day of the month. :slight_smile:

On Feb 18, 12:16 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Gist a curl recreation.

On Friday, February 18, 2011 at 9:17 PM, Andrei wrote:

I'm having an issue with sorting on a date field. The field is defined
in my mapping as:

"created_on" : {"type" : "date", "format" : "YYYY-MM-DD
HH:mm:ss"},

When I do a simple matchAll + sort query, the first result is way
newer than I'd expect:

$ curl 'http://localhost:9200/places/_search?pretty=true'-d'{"sort":
["created_on"], "query": {"match_all": {}}, "fields": ["created_on"],
"size": 1}'

{
"took" : 1,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1788,
"max_score" : null,
"hits" : [ {
"_index" : "places",
"_type" : "place",
"_id" : "436",
"_score" : null,
"fields" : {
"created_on" : "2010-12-01 00:33:34"
},
"sort" : [ 1262306014000 ]
} ]
}
}

But there're clearly docs that are older. For example, the one with
_id 435:

$ curl 'http://localhost:9200/places/place/435'

{"_index":"places","_type":"place","_id":"435", "_source" : {....,
"created_on": "2010-11-30 23:01:25", ......}}

Am I doing something wrong?