Type cannot be specified during template creation

Hi everyone,

I want to create a template using the PutIndexTemplateRequest API.
But when the template was created, I found that the mapping.type was "_doc".
I try to add type in the mapping json string as follows:

{
"mytype":{
"properties":{
"NAME":{
"type":"keyword"
},
"AGE":{
"type":"keyword"
},
"ADDRESS":{
"type":"text"
}
}
}
}

Then I got a error:
MapperParsingException: Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [imsiimei : {properties={ADDRESS={type=text}, NAME={type=keyword}, AGE={type=keyword}}}]

How can I customize the type name using JAVA Template Api?

Types are going to be removed so you should not try to change the behavior.

Hi @dadoonet

I know the type will be removed in 7.x.

However, I am using ES 6.8 now, so I hope the value of type can be more explicit.

Don't do it. Just use the default value.

So that's the only way I can write in my code:

BulkRequest request = new BulkRequest();
for (Map<String, Object> map: mapList) {
request.add(new IndexRequest(String.valueOf(map.get("INDEX")), "_doc").source(map));
}
BulkResponse responses = client.bulk(request, RequestOptions.DEFAULT);

That's the way to go.

In 7.x you'll write:

request.add(new IndexRequest("test").id("1").source("{\"foo\":\"bar\"}", XContentType.JSON));

Instead of:

request.add(new IndexRequest("test").type("_doc").id("1").source("{\"foo\":\"bar\"}", XContentType.JSON));

OK, Thanks!

Best regards.

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