Create index mapping with jest and transport client

(salma) #1

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

Java Client to insert index with mapping
(David Pilato) #2

About Jest. I don't know.

About the transport client, I believe it's here:

(salma) #3

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 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("", "sharongur").build();

		Client client = new PreBuiltTransportClient(settings)
							.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(""), 9300));

		IndicesAdminClient indicesAdminClient = client.admin().indices();

              .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" +
              "  }")     

		String json = "{" +

              "\"id\":\"1\"," +
              "\"number\":\"123333333\"," +
              "\"name\":\"Sharon Tries Elastic\"" +

	IndexResponse response = client.prepareIndex("calls", "call")

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


(David Pilato) #4

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.

(salma) #5

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

(David Pilato) #6

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

(system) #7

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