Java Client fail to insert index with mapping

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

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:

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

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?

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.

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

Thanks!

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