Define parent / child mapping via Java API

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?

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

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