saveToEsWithMeta with Json values

I have my values already formatted as strings, but I can't use saveJsonToES since I want to pass in meta.

My code is like this:

val cfg: Map[String, String] = Map(
  ES_INPUT_JSON -> true.toString
)

def metaMap(id: String, version: Long): Map[Metadata, String] = Map(
  Metadata.ID -> id,
  Metadata.VERSION -> version.toString,
  Metadata.VERSION_TYPE -> "external")

 myRdd.map(v => (metaMap(v.id, v.version), v.jsonString)
    .writeToESWithMeta(resource, cfg)

I am getting this exception:

Caused by: org.elasticsearch.hadoop.rest.EsHadoopInvalidRequest: JsonParseException[Unexpected character ('d' (code 100)): was expecting comma to separate OBJECT entries
 at [Source: [B@768a0173; line: 1, column: 24]]; fragment[{"_id":813751de68ef4]

Maybe hadoop-es tries to interpret both the key and value as Json?

I'm not sure I follow.

If I understand the issue correctly, you are trying to save metadata while setting the input as JSON. The metadata itself is not in JSON format hence why you are getting the errors.
You either let ES-Hadoop use its extractors (which can understand if the input is JSON or not) or handle everything by yourself - namely in this case properly escape the key as a JSON string with quotes.