求解 org.elasticsearch.index.mapper.MapperParsingException

来源:互联网 发布:访客网络什么意思 编辑:程序博客网 时间:2024/05/21 22:54

Exception in thread "main" org.elasticsearch.index.mapper.MapperParsingException: Root type mapping not empty after parsing! Remaining fields:   [test : {properties={id={type=long, store=yes}, type={type=string, index=not_analyzed}, catIds={type=integer}}}]
 at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:278)
 at org.elasticsearch.index.mapper.DocumentMapperParser.parseCompressed(DocumentMapperParser.java:192)
 at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:449)
 at org.elasticsearch.cluster.metadata.MetaDataMappingService$4.execute(MetaDataMappingService.java:505)
 at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:374)
 at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:188)
 at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:158)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at java.lang.Thread.run(Thread.java:745)



下面是代码


private static XContentBuilder getMapping() throws Exception {
  
  XContentBuilder mapping =jsonBuilder().startObject();
  mapping=mapping.startObject("test")
    
      .startObject("properties")
      
      .startObject("id")
      .field("type", "long")
      .field("store", "yes")
      .endObject()
      
      .startObject("type")
      .field("type", "string")
      .field("index", "not_analyzed")
      .endObject()
      
      .startObject("catIds")
      .field("type", "integer")
      .endObject()
      
      .endObject()
      .endObject();
  
  mapping=mapping.endObject();
  return mapping;
 }




public static void main(String[] args) throws Exception {
  // TODO Auto-generated method stub
  Client client = ESUtils.getClient();
  
  PutMappingRequestBuilder builder = client.admin().indices()
    .preparePutMapping("esindex");
 
  builder.setType("testMapping");
  XContentBuilder mapping = getMapping();
  
  builder.setSource(mapping);
   
  PutMappingResponse response = builder.execute().actionGet();
  
  System.out.println(response.isAcknowledged());

 }

0 0
原创粉丝点击