# Java Client fail to insert index with mapping

**URL:** <https://discuss.elastic.co/t/java-client-fail-to-insert-index-with-mapping/73390>\
**Category:** Elasticsearch\
**Created:** [January 31, 2017, 3:59pm UTC](https://discuss.elastic.co/t/java-client-fail-to-insert-index-with-mapping/73390 "2017-01-31T15:59:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharongur](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@sharongur](https://discuss.elastic.co/u/sharongur)\
**Post date:** [January 31, 2017, 3:59pm UTC](https://discuss.elastic.co/t/java-client-fail-to-insert-index-with-mapping/73390/1 "2017-01-31T15:59:24Z")

</div>

Hi,  
I worte a java client to insert indexes into elasticsearch.  
After succsufuly doing it i wanted to ad a new index with mapping.  
where i ran into problem

> Exception in thread "main" MapperParsingException[Failed to parse mapping [call]: Root mapping definition has unsupported parameters: [number : {type=long}]]; nested: MapperParsingException[Root mapping definition has unsupported parameters: [number : {type=long}]];  
> at org.elasticsearch.index.mapper.MapperService.merge(MapperService.java:254)  
> at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:357)  
> at org.elasticsearch.cluster.ClusterStateUpdateTask.execute(ClusterStateUpdateTask.java:45)  
> at org.elasticsearch.cluster.service.ClusterService.runTasksForExecutor(ClusterService.java:581)  
> at org.elasticsearch.cluster.service.ClusterService$UpdateTask.run(ClusterService.java:920)  
> at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:458)  
> at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:238)  
> at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:201)  
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  
> at java.lang.Thread.run(Thread.java:745)  
> Caused by: MapperParsingException[Root mapping definition has unsupported parameters: [number : {type=long}]]  
> at org.elasticsearch.index.mapper.DocumentMapperParser.checkNoRemainingFields(DocumentMapperParser.java:145)  
> at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:134)  
> at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:90)  
> at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:517)  
> at org.elasticsearch.index.mapper.MapperService.merge(MapperService.java:282)  
> at org.elasticsearch.index.mapper.MapperService.merge(MapperService.java:252)  
> ... 10 more

my code is very simple and i a POC

> ```
> Settings settings = Settings.builder()
> .put("cluster.name", "sharongur").build();
> 
> ```

> ```
> Client client = new PreBuiltTransportClient(settings)
> .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
>   	
> IndicesAdminClient indicesAdminClient = client.admin().indices();
>   	
> indicesAdminClient.prepareCreate("calls")
> .setSettings(Settings.builder()             
> .put("index.number_of_shards", 10)
> )
> .addMapping("call", "{\n" +                
> 
> ```

```
                " \"call\": {\n" +
                " \"properties\": {\n" +
                " \"id\": {\n" +
                " \"type\": \"string\"}\n" +
                " },\n" +
                " \"number\": {\n" +
                " \"type\": \"string\"}\n" + 
                " },\n" +
                " \"name\": {\n" +
                " \"type\": \"string\"\n" +
                " }\n" +
                " }\n" +
                " }\n" +
                " }")

```

> ```
> .get();              
>   	
> String json = "{" +
> 
> ```

> ```
> "\"id\":\"1\"," +
> "\"number\":\"123333333\"," +
> "\"name\":\"Sharon Tries Elastic\"" +
> "}";
>   	
> IndexResponse response = client.prepareIndex("calls", "call")
> .setSource(json)
> .get();
>   
> // Index name
> String _index = response.getIndex();
> // Type name
> String _type = response.getType();
> // Document ID (generated or not)
> String _id = response.getId();
> // Version (if it's the first time you index this document, you will get: 1)
> long _version = response.getVersion();
> client.close();
> 
> ```
> 
> }

EDIT : was working accoridng to this example

> **[Indices Administration | Java Transport Client (deprecated) \[7.17\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-admin-indices.html)**

---

<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:** [January 31, 2017, 6:00pm UTC](https://discuss.elastic.co/t/java-client-fail-to-insert-index-with-mapping/73390/2 "2017-01-31T18:00:19Z")

</div>

Hi,

it's a bit hard to spot, but your Json is broken (e.g. too much closing brackets after the id-type line) . Try something like this:

```auto
.addMapping("call", "{\n" +
                  " \"properties\": {\n" +
                  " \"id\": {\n" +
                  " \"type\": \"string\"},\n" +
                  " \"number\": {\n" +
                  " \"type\": \"string\"},\n" +
                  " \"name\": {\n" +
                  " \"type\": \"string\"}\n" +
                  " }\n" +
                  " }")

```

---

<div class="post-metadata">

**Author:** ![sharongur](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@sharongur](https://discuss.elastic.co/u/sharongur)\
**Post date:** [January 31, 2017, 6:21pm UTC](https://discuss.elastic.co/t/java-client-fail-to-insert-index-with-mapping/73390/3 "2017-01-31T18:21:26Z")

</div>

That was indeed the problem thanks!

But now i have a different problem.  
the document i entered is inside ES but for some reason when i try to get it the source field is empty like so

> {  
> "\_index" : "calls",  
> "\_type" : "call",  
> "\_id" : "AVn1sA1Wp3NOn\_HGg7UZ",  
> "\_score" : 1.0,  
> "\_source" : { }  
> }

and when i do a GET /\_search  
i can see all the other indexes i entered ( ones without mapping) their source field is there with the data i inserted.  
Any idea of why that problem is occuring?

---

<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:** [January 31, 2017, 6:41pm UTC](https://discuss.elastic.co/t/java-client-fail-to-insert-index-with-mapping/73390/4 "2017-01-31T18:41:02Z")

</div>

Can you please open a new thread for this so we can stay with one topic? Makes it easier for others to follow id they encounter this in the future.

---

<div class="post-metadata">

**Author:** ![sharongur](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@sharongur](https://discuss.elastic.co/u/sharongur)\
**Post date:** [January 31, 2017, 6:51pm UTC](https://discuss.elastic.co/t/java-client-fail-to-insert-index-with-mapping/73390/5 "2017-01-31T18:51:25Z")

</div>

yeah i thought about it but anyway i found the problem, something stupid. ill leave this thread as it is then 😛

Thanks!

---

<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:** [February 28, 2017, 6:51pm UTC](https://discuss.elastic.co/t/java-client-fail-to-insert-index-with-mapping/73390/6 "2017-02-28T18:51:24Z")

</div>

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