【问题标题】:How to Create more than one type(table) in single Index(db) using Java API in Elasticsearch如何在 Elasticsearch 中使用 Java API 在单个索引(db)中创建多个类型(表)
【发布时间】:2018-01-18 19:07:23
【问题描述】:

我正在使用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

)

【问题讨论】:

    标签: java elasticsearch


    【解决方案1】:

    在 6.0 中,索引的多种类型已被删除!!!

    https://www.elastic.co/guide/en/elasticsearch/reference/6.0/breaking-changes-6.0.html

    【讨论】:

      猜你喜欢
      • 2018-09-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-17
      • 2017-06-03
      • 1970-01-01
      • 2019-06-19
      • 2018-05-29
      • 2022-10-07
      相关资源
      最近更新 更多