Create index mapping with jest and transport client

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

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

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();

}

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.

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

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

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