I am trying to add some documents to my opensearch instance with the Python client SDK like so:
import opensearchpy
host = 'my_remote_host.com'
port = 9200
auth = ('admin', 'admin')
client = opensearchpy.OpenSearch(
hosts=[{'host': host, 'port': port}],
http_compress=True,
http_auth=auth,
use_ssl=False,
verify_certs=False,
)
index_name = 'loggerheads'
# Add a document to the index.
document = {
'timestamp': '2022-02-09 11:11:11.111',
'message': 'some random ship'
}
response = client.index(
index = index_name,
body = document,
refresh = True
)
I have previously configured my mapping like this:
PUT loggerheads
{
"mappings": {
"properties": {
"timestamp": {
"type": "date",
"format": ["YYYY-MM-DD HH:mm:ss.SSS"]
},
"message": {
"type": "text"
}
}
}
}
The timestamp gets displayed wrong:
Am I doing something wrong or is this a bug?
I sent a series of documents to opensearch. The observation is that any date in 2023 is being displayed as 2023-01-02
. Furthermore:
2022-01-03
2021-01-04
2019-12-30
2018-12-31
2018-01-01
2017-01-02
2016-01-04
2014-12-29
2013-12-30
2012-12-31
2012-01-02
2011-01-03
2010-01-04
It looks like there is a problem in the format
with uppercase and lowercase. Please try the following.
PUT loggerheads
{
"mappings": {
"properties": {
"timestamp": {
"type": "date",
"format": ["yyyy-MM-dd HH:mm:ss.SSS"]
},
"message": {
"type": "text"
}
}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html#multiple-date-formats