"object type" and "string type" "error MapperParsingException"

Objectif : put the 2 items in the same type _mappings !


Is there another possibility to do this? (*)
without to disable parsing and indexing a named object.
**

curl -XPUT localhost:9200/test/type1/1 -d '{
"person" : {
"name": {
"first_name" : "ard",
"last_name" : "oise"
}
}
}' && echo

**

curl -XPUT localhost:9200/test/type1/2 -d '{
"person" : {
"name": "ardoise"
}
}' && echo

(*) I don't want to use the flag "enabled" : false,

because the "enabled" flag allows to disable parsing and indexing a named object
completely. This is handy when a portion of the JSON document contains
arbitrary JSON which should not be indexed, nor added to the mapping

**

curl -XPUT localhost:9200/test -d '
{
"settings" : {
"index" : {
"number_of_shards" : "1",
"number_of_replicas" : "0"
}
},
"mappings" : {
"type1" : {
"properties" : {
"person" : {
"type" : "object",
"properties" : {
"name" : {
"type" : "object",
"enabled": false
}
}
}
}
}
}
}' && echo

"error":"MapperParsingException[object mapping for [type1] tried to parse field [person] as object, but got EOF, has a concrete value been provided to it?]","status":400}

So you want the same field to be either a String or an object ?
Not doable.

You can use dynamic templates to disable indexation of fields like "x.*" for example. Have a look at them to see if it could help.