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?
Edit
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 ->
2022-01-03
- 2021 ->
2021-01-04
- 2020 ->
2019-12-30
- 2019 ->
2018-12-31
- 2018 ->
2018-01-01
- 2017 ->
2017-01-02
- 2016 ->
2016-01-04
- 2015 ->
2014-12-29
- 2014 ->
2013-12-30
- 2013 ->
2012-12-31
- 2012 ->
2012-01-02
- 2011 ->
2011-01-03
- 2010 ->
2010-01-04
CodePudding user response:
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"
}
}
}
}