# Odd error creating index via Rest API (ES 6.2.2)

**URL:** https://discuss.elastic.co/t/odd-error-creating-index-via-rest-api-es-6-2-2/132602
**Category:** Elasticsearch
**Created:** [May 20, 2018, 8:05pm UTC](https://discuss.elastic.co/t/odd-error-creating-index-via-rest-api-es-6-2-2/132602 "2018-05-20T20:05:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![atulsudhalkar](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@atulsudhalkar](https://discuss.elastic.co/u/atulsudhalkar)
#### Post date: [May 20, 2018, 8:05pm UTC](https://discuss.elastic.co/t/odd-error-creating-index-via-rest-api-es-6-2-2/132602/1 "2018-05-20T20:05:16Z")

</div>

I'm trying to use the ES High-level Rest Client to integrate to ES (6.2.2) from my Java code. Here's the test class I wrote to re-create the problem. The code works as written, but the commented out code doesn't work. But I patterned it faithfully on the manual: [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.2/java-rest-high-create-index.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.2/java-rest-high-create-index.html)

## Any advice/help would be greatly appreciated!

```
@Test
public void DoCreateJobIndex () throws IOException {
    RestHighLevelClient client = new RestHighLevelClient (
            RestClient.builder (
                    new HttpHost (esHost, 0, "https")));
    String index = "my_job_profiles";
    CreateIndexRequest request = new CreateIndexRequest (index);
    request.source("{\n" +
            " \"settings\":{\"number_of_shards\":1},\n" +
            " \"mappings\":{\n" +
            " \"JobProfileDTO\":{\n" +
            " \"properties\":{\n" +
            " \"jobDetails\":{\n" +
            " \"type\":\"text\",\n" +
            " \"analyzer\":\"english\"\n" +
            " }\n" +
            " }\n" +
            " }\n" +
            " }\n" +
            "}", XContentType.JSON);

```

// request.settings (Settings.builder ()  
// .put ("index.number\_of\_shards", 1)  
// .put ("index.number\_of\_replicas", 1));  
// request.mapping (index,  
// "{\n" +  
// " "JobProfileDTO":{\n" +  
// " "properties":{\n" +  
// " "jobDetails":{\n" +  
// " "type":"text",\n" +  
// " "analyzer":"english"\n" +  
// " }\n" +  
// " }\n" +  
// " }\n" +  
// "}",  
// XContentType.JSON  
// );

```
    request.timeout (TimeValue.timeValueMinutes (1));
    CreateIndexResponse response = client.indices ().create (request);
    logger.info (response.toString ());
    client.close ();
}

```

The above code works (looked up the index via postman):

{  
"my\_job\_profiles": {  
"aliases": {},  
"mappings": {  
"JobProfileDTO": {  
"properties": {  
"jobDetails": {  
"type": "text",  
"analyzer": "english"  
}  
}  
}  
},  
"settings": {  
"index": {  
"creation\_date": "1526843609577",  
"number\_of\_shards": "1",  
"number\_of\_replicas": "1",  
"uuid": "xr2LC2vxQpGbHw3hBbgm8w",  
"version": {  
"created": "6020299"  
},  
"provided\_name": "my\_job\_profiles"  
}  
}  
}  
}

But the commented-out code gets the following exception:

ElasticsearchStatusException[Elasticsearch exception [type=mapper\_parsing\_exception, reason=Failed to parse mapping [my\_job\_profiles]: Root mapping definition has unsupported parameters: [JobProfileDTO : {properties={jobDetails={analyzer=english, type=text}}}]]  
]; nested: ElasticsearchException[Elasticsearch exception [type=mapper\_parsing\_exception, reason=Root mapping definition has unsupported parameters: [JobProfileDTO : {properties={jobDetails={analyzer=english, type=text}}}]]];

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [May 26, 2018, 11:45am UTC](https://discuss.elastic.co/t/odd-error-creating-index-via-rest-api-es-6-2-2/132602/2 "2018-05-26T11:45:51Z")

</div>

> [@atulsudhalkar](#):
>
> // request.mapping (index,  
> // "{\n" +  
> // " "JobProfileDTO":{\n" +  
> // " "properties":{\n" +  
> // " "jobDetails":{\n" +  
> // " "type":"text",\n" +  
> // " "analyzer":"english"\n" +  
> // " }\n" +  
> // " }\n" +  
> // " }\n" +  
> // "}",  
> // XContentType.JSON  
> // );

The first argument of the request.mapping() function takes the mapping type, not the index (see javadocs). So this would be:

```auto
request.mapping("JobProfileDTO", 
      "{ \"properties\": {\"jobDetails\":{ \"type\":\"text\", \"analyzer\":\"english\"}}}",
      XContentType.JSON
    );

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 23, 2018, 11:45am UTC](https://discuss.elastic.co/t/odd-error-creating-index-via-rest-api-es-6-2-2/132602/3 "2018-06-23T11:45:53Z")

</div>

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