Failure in putting template mapping using Java Api

I'm trying to put a template mapping into elasticsearch using the Java api. This is the code I'm using:

Client client = TransportClient.builder()
    .addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(ES_ADDRESS, 9300)));
String indexSettings;
InputStream jsonSettingsIS = Thread.currentThread().getContextClassLoader().getResourceAsStream("" + index +     ".json");
indexSettings = new Scanner(jsonSettingsIS).useDelimiter("\\A").next();
catch (IndexTemplateAlreadyExistsException e)
{"Template index [" + index + "] already exists.");

When executing that snipped of code I get this error:

Exception in thread "main" InvalidIndexTemplateException[index_template [template-*] invalid, cause [Validation    Failed: 1: template must not contain a space;2: template must not contain a ',';3: template must not container the following characters [\, /, *, ?, ", <, >, |,  , ,];]]
at org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService.validate(

The template I'm trying to put is

    "template": "template-*",
    "settings": {
       "index": {
          "analysis": {
             "analyzer": {
                "whitespace": {
                   "type": "whitespace"

Please format better your code. This is ugly to read IMO. </> icon is your friend! :slight_smile:

You need to use setSource instead of setTemplate. setTemplate is used to set the template name only.

Hi, thanks for your answers. Using setSource actually works.
Thanks again!