我有一个JSON文档。当我尝试使用弹性搜索进行索引时,我会遇到异常。
index1没有默认映射。
curl -XPOST localhost:9200/index1/talk?pretty=1 -d '
{
"_id" : ObjectId("503b29efe4b032e338f0581b"),
"_oid" : NumberLong(1182053),
"_ugc" : false,
"_v" : 22,
"c" : [
"Destination"
],
"cc" : "AD",
"co" : "andorra",
"e" : true,
"f" : [
"Destination"
],
"gi" : "3038999",
"h" : 0,
"i" : [ ],
"k" : [
"soldeu",
"parroquia de canillo"
],
"kv" : [
"soldeu"
],
"la" : 42.57688,
"lc" : 0,
"ln" : 1.66769,
"ns" : [
{
"n" : "Soldeu",
"l" : "en",
"t" : "p"
}
],
"po" : 0,
"point" : [
42.57688,
1.66769
]
}'
STACKTRACE:
org.elasticsearch.index.mapper.MapperParsingException: Failed to parse
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:509)
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:438)
at org.elasticsearch.index.shard.service.InternalIndexShard.prepareCreate(InternalIndexShard.java:287)
at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:210)
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:532)
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:430)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.elasticsearch.common.jackson.core.JsonParseException: Unexpected character ('O' (code 79)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: [B@5e7d093a; line: 4, column: 10]
at org.elasticsearch.common.jackson.core.JsonParser._constructError(JsonParser.java:1284)
at org.elasticsearch.common.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:588)
at org.elasticsearch.common.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:509)
at org.elasticsearch.common.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2094)
at org.elasticsearch.common.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:561)
at org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:48)
at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:461)
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:494)
... 8 more
JSON是来自mongodb的文档。我已经安装了以下插件:
ES_HOME/bin/plugin -install elasticsearch/elasticsearch-mapper-attachments/1.4.0
ES_HOME/bin/plugin -install richardwilly98/elasticsearch-river-mongodb/1.4.0
有人可以告诉我哪里出错了吗?
更新:
错误似乎是因为ObjectId()和NumberLong()。但是,我不希望将这些字段编入索引,因此我定义了一个自定义映射来发出这些字段。 自定义映射:
curl -XPUT localhost:9200/index1?pretty=1 -d '{
"mappings" : {
"type1" : {
"_all" : {"enabled" : false},
"properties" : {
"ns" : {
"dynamic" : "true",
"properties" : {
"n" : {
"type" : "string"
},
"l" : {
"type" : "string"
},
"t" : {
"type" : "string"
}
}
}
}
}
}
}'
理想情况下,分析器应该省略_id和_oid,但仍然可以为这些对象提供映射。
ObjectId = org.bson.types.ObjectId and NumberLong = java.lang.Double
答案 0 :(得分:1)
json对象不正确。
似乎是你的_id属性发生了奇怪的事情,而ElasticSearch因此无法解析它。
答案 1 :(得分:0)
要从索引的MongoDB文档中删除字段,您需要使用脚本:
无法使用自定义映射删除字段。