Elasticsearch exception: Root mapping definition has unsupported parameters

When I used curl to create my template, it works fine. But when I used High Level REST it gave me the exception:

org.elasticsearch.ElasticsearchException: Elasticsearch exception [type=mapper_parsing_exception, reason=Root mapping definition has unsupported parameters:  [document : {properties={cx_date={index=false, type=date}, doi_derived_from_publication={type=text}, publishing_poc={type=text}, sources={type=text}, cat_id={type=keyword}, title={type=text, fields={keyword={type=keyword}}}, coverages={type=text}, content={type=text}, DOI_end={type=date}, original_filename={type=text}, title_classification={type=text}, source_numbers={type=text}, summary={type=text}, requirements={type=text}, types={type=keyword}, identifiers={type=text}, topics={type=text}, cat_processed={type=date}, serial_number={type=text}, published={type=date}, classification={type=keyword}, url={type=text, fields={keyword={type=keyword}}}, publishing_organization={type=keyword}, cx={index=false, type=text}, special_instruction={type=text}, DOI_start={type=date}, contains_attachments={type=text}, cat_source={type=keyword}}}]]
	at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:509) ~[elasticsearch-6.8.3.jar!/:6.8.3]
	at org.elasticsearch.ElasticsearchException.fromXContent(ElasticsearchException.java:420) ~[elasticsearch-6.8.3.jar!/:6.8.3]
	at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:450) ~[elasticsearch-6.8.3.jar!/:6.8.3]
	at org.elasticsearch.ElasticsearchException.failureFromXContent(ElasticsearchException.java:616) ~[elasticsearch-6.8.3.jar!/:6.8.3]
	at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:169) ~[elasticsearch-6.8.3.jar!/:6.8.3]
	at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:2053) ~[elasticsearch-rest-high-level-client-6.8.3.jar!/:6.8.3]
	at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:2030) ~[elasticsearch-rest-high-level-client-6.8.3.jar!/:6.8.3]
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1777) ~[elasticsearch-rest-high-level-client-6.8.3.jar!/:6.8.3]
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1734) ~[elasticsearch-rest-high-level-client-6.8.3.jar!/:6.8.3]
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1696) ~[elasticsearch-rest-high-level-client-6.8.3.jar!/:6.8.3]
	at org.elasticsearch.client.IndicesClient.putTemplate(IndicesClient.java:1539) ~[elasticsearch-rest-high-level-client-6.8.3.jar!/:6.8.3]
...
curl -s -H 'Content-Type: application/json' -X PUT 'http://<elasticsearch>:9200/_template/<templateName>' -d @templates/documentTemplate.json
try {
    PutIndexTemplateRequest request = new PutIndexTemplateRequest(<templateName>);
    request.source(documentTemplateJsonAsString, XContentType.JSON);
    client.indices().putTemplate(request, RequestOptions.DEFAULT).isAcknowledge())
} catch (final IOException e) {
...
}
{
   "order": 0,
   "version": 2,
   "index_patterns": [
      "documents_*"
   ],
   "settings": {
      "codec": "best_compression",
      "index": {
         "unassigned": {
            "node_left": {
               "delayed_timeout": "10m"
            }
         },
         "number_of_shards": "5",
         "number_of_replicas": "1",
         "blocks": {
            "read_only_allow_delete": "false"
         }
      }
   },
   "mappings": {
      "document": {
         "properties": {...}
   }
}

Elasticsearch version: 6.8.7
Thank you for your help!

which version of the HLRC are you using in your java project?

1 Like

6.8.3

can you share the whole snippet including the data you put into the request, so that others can reproduce?

Not sure if this exception gives any more clues ...

"message": "Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [document : {properties={cx_date={index=false, type=date}, doi_derived_from_publication={type=text}, publishing_poc={type=text}, sources={type=text}, cat_id={type=keyword}, title={type=text, fields={keyword={type=keyword}}}, coverages={type=text}, content={type=text}, DOI_end={type=date}, original_filename={type=text}, title_classification={type=text}, source_numbers={type=text}, summary={type=text}, requirements={type=text}, types={type=keyword}, identifiers={type=text}, topics={type=text}, cat_processed={type=date}, serial_number={type=text}, published={type=date}, classification={type=keyword}, url={type=text, fields={keyword={type=keyword}}}, publishing_organization={type=keyword}, cx={index=false, type=text}, special_instruction={type=text}, DOI_start={type=date}, contains_attachments={type=text}, cat_source={type=keyword}}}]]"
    @Bean(destroyMethod = "close")
    public RestHighLevelClient client() {
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(
                new HttpHost(this.host, this.port, this.scheme),
                new HttpHost(this.backupHost, this.port, this.scheme)));
        return client;
    }

The actual code is very simple:

@Service
public class MyService {

    @Value("classpath:elasticsearch-scripts/templates/MyTemplate.json")
    Resource defaultTemplateResource;

    @Autowired
    private RestHighLevelClient client;

   public void createIndexTemplate() 
   {
      try {
         String defaultTemplateJsonStr = IOUtils.toString(
                    defaultTemplateResource.getInputStream(), "UTF-8");
         PutIndexTemplateRequest request = new PutIndexTemplateRequest(<templateName>);
         request.source(defaultTemplateJsonStr, XContentType.JSON);
         client.indices().putTemplate(request, RequestOptions.DEFAULT).isAcknowledge())
      } catch (final IOException e) {
         System.out.println("Exception: " + e);
      }
}

MyTemplate.json:

{
   "order": 0,
   "version": 2,
   "index_patterns": [
      "documents_*-v2*"
   ],
   "settings": {
      "codec": "best_compression",
      "index": {
         "unassigned": {
            "node_left": {
               "delayed_timeout": "10m"
            }
         },
         "number_of_shards": "5",
         "number_of_replicas": "1",
         "blocks": {
            "read_only_allow_delete": "false"
         }
      }
   },
   "mappings": {
      "document": {
         "properties": {
            "CAT_end": {
               "type": "date"
            },
            "CAT_start": {
               "type": "date"
            },
            "classification": {
               "type": "keyword"
            },
            "contains_attachments": {
               "type": "text"
            },
            "content": {
               "type": "text"
            },
            "coverages": {
               "type": "text"
            },
            "cx": {
               "type": "text",
               "index": false
            },
            "cx_date": {
               "type": "date",
               "index": false
            },
            "doi_derived_from_publication": {
               "type": "text"
            },
            "cat_id": {
               "type": "keyword"
            },
            "cat_processed": {
               "type": "date"
            },
            "cat_source": {
               "type": "keyword"
            },
            "identifiers": {
               "type": "text"
            },
            "original_filename": {
               "type": "text"
            },
            "published": {
               "type": "date"
            },
            "publishing_organization": {
               "type": "keyword"
            },
            "publishing_poc": {
               "type": "text"
            },
            "requirements": {
               "type": "text"
            },
            "serial_number": {
               "type": "text"
            },
            "source_numbers": {
               "type": "text"
            },
            "sources": {
               "type": "text"
            },
            "special_instruction": {
               "type": "text"
            },
            "summary": {
               "type": "text"
            },
            "title": {
               "type": "text",
               "fields": {
                  "keyword": {
                     "type": "keyword"
                  }
               }
            },
            "title_classification": {
               "type": "text"
            },
            "topics": {
               "type": "text"
            },
            "types": {
               "type": "keyword"
            },
            "url": {
               "type": "text",
               "fields": {
                  "keyword": {
                     "type": "keyword"
                  }
               }
            }
         }
      }
   }
}

I am confused. the exception mentions _doc but it is nowhere mentioned in your code snippets.

Just to be sure: Are those JSON snippets the right ones?

Those are the correct one.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.