Hi, I am facing one issue related to date format in ES response. When I index data, it is mapped as text, how can I specify the mappings before or at the time of indexing the data.
If I call the mappings api before indexing, then it says indices not found.
Thanks...
This is the code I am using to insert the index :
BulkRequest request = new BulkRequest();
request.timeout(TimeValue.timeValueMinutes(2));
try {
records.forEach(record -> {
IndexRequest indexRequest = new IndexRequest("index", "prd", record.id()).source(record);
request.add(indexRequest);
});
restHighLevelClient.bulk(request);
} catch (ElasticsearchException e) {
e.printStackTrace();
logger.info("@ElasticSearch Index error ", e.getMessage());
} catch (java.io.IOException ex) {
ex.printStackTrace();
logger.info("@ElasticSearch io Index error ", ex.getMessage());
}
When index are inserted all the date fields like start_datetime, end_datetime, created_at are mapped as text. In the json, date comes in format like
"start_datetime": "2017-11-30T10:30-08:00[America/Los_Angeles]",
I tried to send put request to update the mappings too by using below request.
URL : https://$ES_URL/index/prd/_mapping
{
"properties": {
"start_datetime": {
"type": "date",
"format": "strict_date_optional_time"
}
}
}
But it did not work. Error thrown -> "mapper [start_datetime] of different type, current_type [text], merged_type [date]"
What changes I need to get the date in proper format. I mean without zone info.
Thanks
dadoonet
(David Pilato)
May 1, 2018, 6:23pm
4
record
seems to be an object. Not a String.
BTW use .source(jsonString, XContentType.JSON)
instead.
system
(system)
Closed
May 29, 2018, 6:33pm
5
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.