Sorting problems

Hello

I'm having problems with sorting. I want to get the latest data (with the
biggest date_created).

So I curl like this:

curl -vsX GET myelastic.com/notifications/notification/_search -d '{

"query": {
"bool": {
"must": [
{
"term": {
"type": "config_withdraw"
}
}
],
"must_not": [],
"should": []
}
},
"sort": [
{
"date_created": "desc"
}
],
"size": 1
}'|python -mjson.tool

RESULT:

{
"_shards": {
"failed": 0,
"successful": 10,
"total": 10
},
"hits": {
"hits": [
{
"_id": "a3Rks7DNTYWGDRZzVg5g8Q",
"_index": "notifications",
"_score": null,
"_source": {
"date_created": "2024-02-01T13:49:52.454-04:00",
"expiration_date": "2024-02-01T13:49:52.452-04:00",
"level": null,
"model": {
"user_id": 80843387
},
"reference_id": null,
"status": "new",
"type": "config_withdraw",
"user_id": "80843387"
},
"_type": "notification",
"sort": [
1706809792454
]
}
],
"max_score": null,
"total": 10533937
},
"timed_out": false,
"took": 163
}

But this is not the latest data becouse in another search I get a bigger date_created:

curl -vsX GET myelastic.com/notifications/notification/_search -d '{
"query": {
"bool": {
"must": [
{
"term": {
"user_id": "153423413"
}
}
],
"must_not": [],
"should": []
}
},
"sort": [
{
"date_created": "desc"
}
],
"size": 1
}'|python -mjson.tool

RESULT:
{
"_shards": {
"failed": 0,
"successful": 10,
"total": 10
},
"hits": {
"hits": [
{
"_id": "PfWSkIDxSk2ou62Yiqbudw",
"_index": "notifications",
"_score": null,
"_source": {
"date_created": "2014-02-03T13:48:11.524-04:00",
"expiration_date": "2024-02-01T13:48:11.524-04:00",
"level": null,
"model": {
"user_id": 153423413
},
"reference_id": null,
"status": "new",
"type": "config_withdraw",
"user_id": "153423413"
},
"_type": "notification",
"sort": [
1391449691524
]
}
],
"max_score": null,
"total": 2
},
"timed_out": false,
"took": 36
}

So I don't know what is the problem, maybe you can give me some pointer.

BTW this is the mapping of the type

curl -vsX GET myelastic.com/notifications/notification/_mapping

RESULT:

{
"notification": {
"properties": {
"date_created": {
"format": "dateOptionalTime",
"type": "date"
},
"expiration_date": {
"format": "dateOptionalTime",
"type": "date"
},
"id": {
"type": "string"
},
"model": {
"properties": {
"bank": {
"type": "string"
},
"new_status": {
"type": "string"
},
"status": {
"type": "string"
},
"user_id": {
"type": "long"
}
}
},
"reference_id": {
"type": "long"
},
"status": {
"type": "string"
},
"type": {
"type": "string"
},
"user_id": {
"type": "string"
}
}
}
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/30763a38-3b05-4c22-a910-f24b0f8e35d4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi,

Can you try following syntax for sorting the date value?
"sort": [
{
"date_created": {
"order": "desc"
}
}
]

Let me know if this solves your problem.

I was using this syntax succesfully for integer value

Regards,
Jayesh Bhoyar
http://www.linkedin.com/in/jayeshbhoyar

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a0dbad62-9561-48ca-bc1e-eb96f1a72c2a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi, thanks for the answer. It does the same thing. It gaves me data 2 days
old

On Wednesday, February 5, 2014 12:39:24 AM UTC-3, Jayesh Bhoyar wrote:

Hi,

Can you try following syntax for sorting the date value?
"sort": [
{
"date_created": {
"order": "desc"
}
}
]

Let me know if this solves your problem.

I was using this syntax succesfully for integer value

Regards,
Jayesh Bhoyar
http://www.linkedin.com/in/jayeshbhoyar

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8358bfc4-6939-4419-8927-aa296fa42745%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.