如何在Elasticsearch

时间:2018-01-18 07:51:51

标签: java elasticsearch

我正在使用java api学习elasticsearch

我想使用java api在elasticsearch中创建两个或多个具有不同映射的类型。

如何在java api中的弹性搜索中在同一索引中创建多个类型?

我尝试的代码是:

创建名为" alpha"的索引。以下工作正常。

CreateIndexResponse cr =  (ts.admin().indices().prepareCreate("alpha").setSource(*getMapping_simple().string()*, XContentType.JSON).execute().actionGet());

索引中类型simple的映射在" getMapping_simple()。string()" :

 {"mappings":{"simple":{"properties":{"id":{"type":"long"},"message":{"type":"text"}}}}}

现在在此之后我想用nae complex创建一个新的映射和新类型

client.admin().indices().
        preparePutMapping("alpha", "complex_doc").
        setSource(*getMapping_complex().string()*, XContentType.JSON).
        execute().actionGet()

complex_doc类型的映射(新类型):

***{"mappings":{"complex_doc":{"properties":{"id":{"type":"long"},"name":{"type":"text"},"phNo":{"type":"text"},"weight":{"type":"float"},"height":{"type":"float"}}}}}***

以上给我一个错误

  

线程中的异常" main" MapperParsingException [根映射   定义具有不受支持的参数:[映射:   {complex_doc = {properties = {id = {type = long},name = {type = text},   phNo = {type = text},weight = {type = float},height = {type = float}}}}]]

     
    

org.elasticsearch.index.mapper.DocumentMapperParser.checkNoRemainingFields(DocumentMapperParser.java:151)         在     org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:139)         在     org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:91)         在     org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:729)         在     org.elasticsearch.cluster.metadata.MetaDataMappingService $ PutMappingExecutor.applyRequest(MetaDataMappingService.java:264)         在     org.elasticsearch.cluster.metadata.MetaDataMappingService $ PutMappingExecutor.execute(MetaDataMappingService.java:230)         在     org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:640)         在     org.elasticsearch.cluster.service.MasterService.calculateTaskOutputs(MasterService.java:270)         在     org.elasticsearch.cluster.service.MasterService.runTasks(MasterService.java:195)         在     org.elasticsearch.cluster.service.MasterService $ Batcher.run(MasterService.java:130)         在     org.elasticsearch.cluster.service.TaskBatcher.runIfNotProcessed(TaskBatcher.java:150)         在     org.elasticsearch.cluster.service.TaskBatcher $ BatchedTask.run(TaskBatcher.java:188)         在     org.elasticsearch.common.util.concurrent.ThreadContext $ ContextPreservingRunnable.run(ThreadContext.java:568)         在     org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor $ TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:247)         在     org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor $ TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:210)         在     java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)         在     java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:624)         在java.lang.Thread.run(Thread.java:748

  
     

1 个答案:

答案 0 :(得分:0)