0

我正在尝试使用 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映射如下

{
    "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 日志中不断收到以下错误

[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...

我真的被困在这一点上。无法找到解决方案。感谢您对进一步进行的任何帮助。

4

1 回答 1

0

我发现了我正在做的错误

在这行代码中

 Dim jsonData As String = serializer.ToJson(data)

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

当我在以下代码行中传递“数据”而不是“jsonData”时

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

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

于 2013-06-07T11:11:21.870 回答