Custom type field example not work in Elasticsearch 7.6

Hi everyone, I got a problem when I try to run an example of Custom type field section in this tutorial: https://www.elastic.co/guide/en/elasticsearch/reference/7.6/removal-of-types.html#_custom_type_field

I executed this query:
PUT twitter
{
"mappings": {
"user": {
"properties": {
"name": { "type": "text" },
"user_name": { "type": "keyword" },
"email": { "type": "keyword" }
}
},
"tweet": {
"properties": {
"content": { "type": "text" },
"user_name": { "type": "keyword" },
"tweeted_at": { "type": "date" }
}
}
}
}

The result is an error:
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "Root mapping definition has unsupported parameters: [tweet : {properties={tweeted_at={type=date}, user_name={type=keyword}, content={type=text}}}] [user : {properties={user_name={type=keyword}, name={type=text}, email={type=keyword}}}]"
}
],
"type" : "mapper_parsing_exception",
"reason" : "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [tweet : {properties={tweeted_at={type=date}, user_name={type=keyword}, content={type=text}}}] [user : {properties={user_name={type=keyword}, name={type=text}, email={type=keyword}}}]",
"caused_by" : {
"type" : "mapper_parsing_exception",
"reason" : "Root mapping definition has unsupported parameters: [tweet : {properties={tweeted_at={type=date}, user_name={type=keyword}, content={type=text}}}] [user : {properties={user_name={type=keyword}, name={type=text}, email={type=keyword}}}]"
}
},
"status" : 400
}

Can anyone help me with that, thanks in advance!

I updated the query I got the error:

PUT twitter

{
"mappings": {
"user": {
"properties": {
"name": { "type": "text" },
"user_name": { "type": "keyword" },
"email": { "type": "keyword" }
}
},
"tweet": {
"properties": {
"content": { "type": "text" },
"user_name": { "type": "keyword" },
"tweeted_at": { "type": "date" }
}
}
}
}

This is supposed to not work on newer versions, as it resembles the old way of using types. The next snippet shows you the working alternative.

1 Like

Thanks @spinscale for your quick reply. Can you show me more detail? I'm still confusing.

So in the document show that:

Blockquote
Of course, there is a limit to how many primary shards can exist in a cluster so you may not want to waste an entire shard for a collection of only a few thousand documents. In this case, you can implement your own custom type field which will work in a similar way to the old _type .

Yes, I don't want to waste a shard for a few documents, thus I have to implement "Custom type field". If you show me more detail, it would be great, thanks :slight_smile:

Hi @spinscale Ha now I got it. Thanks :slight_smile:

1 Like

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