Define parent / child mapping via Java API


(Chris) #1

I want to define the following parent child mapping in Java:

PUT my_index
{
"mappings": {
"my_parent": {},
"my_child": {
"_parent": {
"type": "my_parent"
}
}
}
}

My problem is that the "preparePutMapping(...)" method in the Java API only accepts a single type and a single source. So I can call the method either on the "my_parent" or on the "my_child" object. Executing the methods one after the other obviously returns the error that a parent / child mapping can only be created on non existing types. Any advice how to do that in Java?


(Chris) #2

Found a way around ... I am using index templates now ... there I can assign more types at once without creating them directly


(Yannick Welsch) #3

In the Java API, you don't need to specify the type. It can be left empty ( = null).


(system) #4