3

我有一个 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
    ]
}'

堆栈跟踪 :

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

4

2 回答 2

1

json 对象不正确。

您的 _id 属性似乎有些奇怪,因此 ElasticSearch 无法解析它。

于 2012-12-20T11:41:55.593 回答
0

要从索引的 MongoDB 文档中删除字段,您需要使用脚本:

  1. 安装 Javascript 插件 ES_HOME\bin\plugin -install elasticsearch/elasticsearch-lang-javascript/1.2.0
  2. 在河流设置中添加一个脚本属性:delete ctx.document._id;

无法使用自定义映射删除字段。

于 2013-04-16T10:45:03.923 回答