gpt4 book ai didi

java - 如何在 Elasticsearch 中使用 Java API 在单个索引(db)中创建多个类型(表)

转载 作者:太空宇宙 更新时间:2023-11-04 10:46:51 24 4
gpt4 key购买 nike

我正在使用java api学习elasticsearch

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

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

我尝试过的代码是:

创建名为“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 复杂的新类型

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"}}}}}***

上面给了我一个错误

Exception in thread "main" MapperParsingException[Root mapping definition has unsupported parameters: [mappings : {complex_doc={properties={id={type=long}, name={type=text}, phNo={type=text}, weight={type=float}, height={type=float}}}}]] at

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

)

最佳答案

关于java - 如何在 Elasticsearch 中使用 Java API 在单个索引(db)中创建多个类型(表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48316233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com