Failed to put mappings on indices [[[]]], type [string] java.lang.IllegalArgumentException: Rejecting mapping update to [] as the final mapping would have more than 1 type: [_doc, string]

I am getting this error only when I define an Index template on Kibana. I define an index template in order to define a lifecylce policy.
The error is "
failed to put mappings on indices [[]], type [string]
java.lang.IllegalArgumentException: Rejecting mapping update to as the final mapping would have more than 1 type: [_doc, string]"

The index is auto created when first index is created, but as soon as the the data is loaded this error is thrown. I use Java Springboot to push the events to Elastic.

Here is extract of code

>        private void sendToElasticSearch(WMQIStatisticsAccounting event) {
>     	String stringOut = "";
>     	// Local date time instance
>     	LocalDateTime localDateTime = LocalDateTime.now();
> 
>     	// Get formatted String
>     	String ldtString = localDateTime.format(indexDateFormatter);
>     	String elasticIndexName = indexName + "_" + ldtString;
> 
>     	ObjectMapper objectMapper = new ObjectMapper();
>     	WMQIStatisticsAccounting eventOut = setEventOut(event);
> 
>     	try {
>     	    stringOut = objectMapper.writeValueAsString(eventOut);
>     	} catch (JsonProcessingException e2) {
>     	    e2.printStackTrace();
>     	}
> 
>     	try {
>     	    GetIndexRequest idexRequest = new GetIndexRequest();
>     	    idexRequest.indices(elasticIndexName);
> 
>     	    IndexRequest request = new IndexRequest(elasticIndexName);
>     	    request.create(true);
>     	    request.id(UUID.randomUUID().toString());
>     	    request.type("string");
>     	    request.opType(DocWriteRequest.OpType.CREATE);
>     	    request.source(stringOut, XContentType.JSON);
>     	    client.index(request, RequestOptions.DEFAULT);
>     	    log.info("Id : " + request.id());
>     	} catch (Exception e) {
>     	    throw new RuntimeException("Unable to push event to Elastic : " + e.getMessage());
>     	}
>         }

I have read through all the previous comments that relates to this error and none are applicable.

This is your first post here. So welcome!

I'm not sure this comment adds anything.

Coming back to the question:

Change:

request.type("string");

To:

request.type("_doc");

This might help. Also have a look at this demo code I wrote. Might help:

And here is a "full" project:

1 Like

Thanks, I have deployed this change and it assigned the lifecycle policy correctly and no longer gave the error in initial post.

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