使用mongo river和PlainElastic.Net进行弹性搜索索引时出错

时间:2013-06-07 09:46:35

标签: mongodb elasticsearch plainelastic.net elasticsearch-plugin

我正在尝试使用PlainElastic.Net客户端并使用CURL索引我的mongodb集合。但是我在这两次尝试中都失败了。

我的.net对象如下

<BsonIgnoreExtraElements>
Public Class QueryReadyProduct

<BsonIgnore()>
<JsonIgnore()>
Property _id As Object
Property CustomerId As Guid
Property ProductId As Guid
Property CategoryId As Guid
Property CustomHierarchyId As Guid

<BsonRepresentation(BsonType.String)>
Property Name As String

结束班

迁移到mongodb后,我会获得额外的_id属性字段

使用PlainElastic.net,以下是我尝试执行的步骤

Dim data As String = "{
  \"type\": \"mongodb\",
  \"mongodb\": {
    \"db\": \"brandviewdata\",
    \"collection\": \"queryreadyproducts\"
  },
  \"index\": {
    \"name\": \"mongoindex\",
    \"type\": \"products\"
  }
}"

Dim jsonData As String = serializer.ToJson(data)

Dim indexR As String = connection.Put(New IndexCommand("_river", "mongodb", "_meta"), "{}")
Dim mappingResult As String = connection.Put(New PutMappingCommand("_river", "mongodb"), jsonMapping)
Dim indexResult As String = connection.Put(New IndexCommand("_river", "mongodb", "_meta"), jsonData)

JSON Mapping如下

{
    "queryreadyproduct": {
        "type": "object",
        "_all": {
            "enabled": false
        },
        "dynamic": false,
        "properties": {
            "Name": {
                "type": "string",
                "analyzer": "standard"
            },
            "CustomerId": {
                "type": "binary",
                "index": "not_analyzed"
            },
            "ProductId": {
                "type": "binary",
                "index": "not_analyzed"
            },
            "CategoryId": {
                "type": "binary",
                "index": "not_analyzed"
            },
            "CustomHierarchyId": {
                "type": "binary",
                "null_value": "",
                "index": "not_analyzed"
            }
        }
    }
}

我在ElasticSearch Log中不断收到以下错误

[2013-06-07 10:42:21,763][DEBUG][action.index             ] [Ranger] [_river][0], node[hKe8cliXSPmHcySUUmhJLg], [P], s[STARTED]: Failed to execute [index {[_river][mongodb][_meta], source["{ \"type\": \"mongodb\", \"mongodb\": { \"db\": \"brandviewdata\", \"collection\": \"queryreadyproducts\"}, \"index\": {\"name\": \"mongoindex\", \"type\": \"products\" }}\""]}]
org.elasticsearch.index.mapper.MapperParsingException: Malformed content, must start with an object
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:477)
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:450)
    at org.elasticsearch.index.shard.service.InternalIndexShard.prepareIndex(InternalIndexShard.java:327)
    at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:203)
    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.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

在弹性搜索日志中也有一些时间

[2013-06-07 09:42:04,122][WARN ][river.routing            ] [Ranger] no river type provided for [_river], ignoring...

我真的被困在这一点上。无法找到解决方案。任何进一步的帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

我发现了我正在做的错误

在这行代码中

 Dim jsonData As String = serializer.ToJson(data)

我正在尝试序列化有效的Json对象“数据”

当我在下面的代码行中传递“data”而不是“jsonData”

 Dim indexResult As String = connection.Put(New IndexCommand("_river", "mongodb", "_meta"), jsonData)

它正在执行索引而没有任何错误。