# Create index mapping with jest and transport client

**URL:** <https://discuss.elastic.co/t/create-index-mapping-with-jest-and-transport-client/84522>\
**Category:** Elasticsearch\
**Created:** [May 4, 2017, 9:32am UTC](https://discuss.elastic.co/t/create-index-mapping-with-jest-and-transport-client/84522 "2017-05-04T09:32:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zegdene](https://avatars.discourse-cdn.com/v4/letter/z/76d3ee/32.png) [@zegdene](https://discuss.elastic.co/u/zegdene)\
**Post date:** [May 4, 2017, 9:32am UTC](https://discuss.elastic.co/t/create-index-mapping-with-jest-and-transport-client/84522/1 "2017-05-04T09:32:28Z")

</div>

Hi,  
I need to create and update index mapping using jest and transport client , i don't find a simple example  
can help please  
thank you

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 4, 2017, 1:57pm UTC](https://discuss.elastic.co/t/create-index-mapping-with-jest-and-transport-client/84522/2 "2017-05-04T13:57:24Z")

</div>

About Jest. I don't know.

About the transport client, I believe it's here: [https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-admin-indices.html#java-admin-indices-put-mapping](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-admin-indices.html#java-admin-indices-put-mapping)

---

<div class="post-metadata">

**Author:** ![zegdene](https://avatars.discourse-cdn.com/v4/letter/z/76d3ee/32.png) [@zegdene](https://discuss.elastic.co/u/zegdene)\
**Post date:** [May 4, 2017, 2:50pm UTC](https://discuss.elastic.co/t/create-index-mapping-with-jest-and-transport-client/84522/3 "2017-05-04T14:50:06Z")

</div>

Hi david,  
I try with this code but error

> Multiple markers at this line
> 
> - Syntax error on token ")", delete this token
> - Syntax error on token ".", @ expected after  
> This is my code:

```
import java.net.InetAddress;

import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.beans.factory.annotation.Autowired;

public class esconfig {
	
	
	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" +
              " \"properties\": {\n" +
              " \"id\": {\n" +
              " \"type\": \"string\"},\n" +
              " \"number\": {\n" +
              " \"type\": \"string\"},\n" +
              " \"name\": {\n" +
              " \"type\": \"string\"}\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();

}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 4, 2017, 3:30pm UTC](https://discuss.elastic.co/t/create-index-mapping-with-jest-and-transport-client/84522/4 "2017-05-04T15:30:52Z")

</div>

Well... It's a java compilation question I guess.  
May be fix the Java problem?

At least tell us which line has a problem if you can't solve that by yourself.

---

<div class="post-metadata">

**Author:** ![zegdene](https://avatars.discourse-cdn.com/v4/letter/z/76d3ee/32.png) [@zegdene](https://discuss.elastic.co/u/zegdene)\
**Post date:** [May 4, 2017, 3:42pm UTC](https://discuss.elastic.co/t/create-index-mapping-with-jest-and-transport-client/84522/5 "2017-05-04T15:42:05Z")

</div>

in this line : indicesAdminClient.prepareCreate("calls") and get();

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 5, 2017, 8:42am UTC](https://discuss.elastic.co/t/create-index-mapping-with-jest-and-transport-client/84522/6 "2017-05-05T08:42:55Z")

</div>

I don't know. The code looks correct. May be a bad character?

---

<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 2, 2017, 8:45am UTC](https://discuss.elastic.co/t/create-index-mapping-with-jest-and-transport-client/84522/7 "2017-06-02T08:45:38Z")

</div>

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