I have already existing index name test-migrate. I want to add the data into it via custom mapping in order to fulfil parent-child-grandchild relation. I am getting the parse error for my specified index. Can you please point out my mistake.
curl -XPUT 'http://url:9200/test-migrate'
{"acknowledged":true,"shards_acknowledged":true}
Here is how my mapping looks like:
curl -XPUT 'url:9200/test-migrate/type/_mapping' -d '
{
"type" : {
"dynamic": "strict",
"properties" : {
"@timestamp" : {
"type" : "date"
},
"@version" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"sub" : {
"properties" : {
"mnumber" : {
"type" : "long"
},
"pnumber" : {
"type" : "long"
},
"s_id" : {
"type" : "long"
},
"s_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"comp": {
"_parent": {
"type" : "sub"
},
"properties" : {
"comp_id" : {
"type" : "long"
},
"comp_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"we" : {
"_parent" : {
"type" : "comp"
},
"_routing" : {
"type" : "sub"
},
"properties" : {
"we_1" : {
"type" : "float"
},
"we_2" : {
"type" : "float"
}
}
}
}
}
}
'
But when i execute it I get an error message:
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Mapping definition for [comp] has unsupported parameters: [_parent : {type=sub}]"}],"type":"mapper_parsing_exception","reason":"Mapping definition for [comp] has unsupported parameters: [_parent : {type=sub}]"},"status":400}
This should work. There was problem with the structure with the mappings structure, mappings of other types has to defined as seperate mapping object.
PUT parent_index
{
"mappings": {
"type": {
"dynamic": "strict",
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"sub": {
"properties": {
"mnumber": {
"type": "long"
},
"pnumber": {
"type": "long"
},
"s_id": {
"type": "long"
},
"s_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"we": {
"_parent": {
"type": "comp"
},
"_routing": {
"type": "sub"
},
"properties": {
"we_1": {
"type": "float"
},
"we_2": {
"type": "float"
}
}
},
"comp": {
"_parent": {
"type": "sub"
},
"properties": {
"comp_id": {
"type": "long"
},
"comp_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
Note: Other way which specifically you are looking for.
First, create index
PUT test-migrate
Second, Now add mappings for type
POST test-migrate/_mapping/type
{
"type": {
"dynamic": "strict",
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"sub": {
"properties": {
"mnumber": {
"type": "long"
},
"pnumber": {
"type": "long"
},
"s_id": {
"type": "long"
},
"s_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"we": {
"_parent": {
"type": "comp"
},
"_routing": {
"type": "sub"
},
"properties": {
"we_1": {
"type": "float"
},
"we_2": {
"type": "float"
}
}
},
"comp": {
"_parent": {
"type": "sub"
},
"properties": {
"comp_id": {
"type": "long"
},
"comp_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}