Date format high level rest client 6.2

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...

Share what you tried

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

record seems to be an object. Not a String.

BTW use .source(jsonString, XContentType.JSON) instead.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.