我正在使用Elasticsearch 2.3 (服务器和Java客户端)
准备索引的代码:
private TransportClient txClient;
// client intialization
Map<String, String> values = new HashMap<String, String>();
values.put("name", "Dev");
values.put("id", "2f3cc5d4-9c4c-4a49-9ebd-c8cd86758118");
values.put("salary", "50000");
IndexResponse response = txClient
.prepareIndex("novel","books", "1de90f05-7cc8-4796-9e92-5b766e8bb0d1")
.setSource(values).execute().actionGet();
错误:
引起:MapperParsingException [无法解析[id]];嵌套:NumberFormatException [输入字符串:&#34; 2f3cc5d4-9c4c-4a49-9ebd-c8cd86758118&#34;]; 在org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:329) at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:309) 在org.elasticsearch.index.mapper.DocumentParser.parseAndMergeUpdate(DocumentParser.java:738) 在org.elasticsearch.index.mapper.DocumentParser.parseDynamicValue(DocumentParser.java:625) 在org.elasticsearch.index.mapper.DocumentParser.parseValue(DocumentParser.java:442) at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:262) 在org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:122) at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:309) 在org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:580) at org.elasticsearch.index.shard.IndexShard.prepareIndexOnPrimary(IndexShard.java:559) at org.elasticsearch.action.index.TransportIndexAction.prepareIndexOperationOnPrimary(TransportIndexAction.java:212) at org.elasticsearch.action.index.TransportIndexAction.executeIndexRequestOnPrimary(TransportIndexAction.java:224) at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:158) at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:66) at org.elasticsearch.action.support.replication.TransportReplicationAction $ PrimaryPhase.doRun(TransportReplicationAction.java:639) 在org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) at org.elasticsearch.action.support.replication.TransportReplicationAction $ PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:279) at org.elasticsearch.action.support.replication.TransportReplicationAction $ PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:271) at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:75) at org.elasticsearch.transport.TransportService $ 4.doRun(TransportService.java:376) 在org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:745) 引起:java.lang.NumberFormatException:对于输入字符串:&#34; 2f3cc5d4-9c4c-4a49-9ebd-c8cd86758118&#34; at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) 在java.lang.Long.parseLong(Long.java:589) 在java.lang.Long.parseLong(Long.java:631) 在org.elasticsearch.common.xcontent.support.AbstractXContentParser.longValue(AbstractXContentParser.java:145) at org.elasticsearch.index.mapper.core.LongFieldMapper.innerParseCreateField(LongFieldMapper.java:275) at org.elasticsearch.index.mapper.core.NumberFieldMapper.parseCreateField(NumberFieldMapper.java:241) 在org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:321) ......还有23个
答案 0 :(得分:1)
如果您第一次插入具有ID字段的文档并且其值在任何数字类型中,那么如果它在映射中找不到ID字段的任何映射,则它将Long类型设置为ID字段。
因此,如果您希望将id字段作为String,则应在将任何文档插入索引之前将其显式映射到映射中的字符串数据类型。