-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Why save epoch_millis
as string?
#2318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
epoli_millis
as string?epoch_millis
as string?
The documentation you already linked explicitly states:
Elasticsearch stores the values in the But when fields for example are retrieved with the Consider this mapping for two fields with the same date format: {
"epoch-millis": {
"mappings": {
"properties": {
"date1": {
"type": "date",
"format": "epoch_millis"
},
"date2": {
"type": "date",
"format": "epoch_millis"
}
}
}
}
} We store this document: {
"date1": 1664641434,
"date2": "1664641434"
} The search it with {
"fields": [
"date1",
"date2"
],
"_source": true
} The response is: {
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "epoch-millis",
"_id": "1",
"_score": 1.0,
"_source": {
"date1": 1664641434,
"date2": "1664641434"
},
"fields": {
"date2": [
"1664641434"
],
"date1": [
"1664641434"
]
}
}
]
}
} In the If Spring Data Elasticsearch would convert If you got mixed data in your _source of the documents, you'd probably better use One possibility would be to add a new format value |
Thanks very much for your detailed response! It really helps me a lot. Does spring-data-elasticsearch support query with |
Support for Support for For |
Thanks~ I'll consider using these in the future. Appreciated! |
I've noticed that if a field is
Instant
withepoch_millis
format:spring-data-elasticsearch will convert this object as a json with string value like
"timestamp":"1644234181000"
rather than long value"timestamp":1644234181000
. After digging into the code, I find that it'sDateFormatter#format
that returns only string value, so timestamp inInstant
is converted into a string value rather long.epoch_mills
is accepted by elasticsearch, it's not mentioned in the doc;epoch_millis
before(without using spring-data-elasticsearch), so now after using spring-data-elasticsearch, both string and long exist fortimestamp
field;epoch_millis
as long or string, not both.Any ideas to support to convert
epoch_millis
andepoch_second
for date type as long rather than string? or at least supply an option to determine it as long or string, rather than just use string whatever the real date type is.The text was updated successfully, but these errors were encountered: