简体   繁体   English

JsonReaderException为Elasticsearch创建批量索引

[英]JsonReaderException creating bulk index for elasticsearch

This is my first attempt using elasticsearch. 这是我第一次使用elasticsearch。 I'm not sure how to troubleshoot the JsonReaderException error below. 我不确定如何解决以下JsonReaderException错误。

var result = client.Bulk(d => descriptor);

results in an exception error 导致异常错误

An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll but was not handled in user code Newtonsoft.Json.dll中发生了类型为'Newtonsoft.Json.JsonReaderException'的异常,但未在用户代码中处理

Additional information: Error reading string. 附加信息:读取字符串时出错。 Unexpected token: StartObject. 意外的令牌:StartObject。 Path 'items[0].index.error', line 1, position 108. 路径“ items [0] .index.error”,第1行,位置108。

var client = new ElasticClient();
client.DeleteIndex("Tracks");
client.CreateIndex("Tracks", c => c
.NumberOfReplicas(1)
.NumberOfShards(6)
.AddMapping<vw_MusicTracks>(m => m.MapFromAttributes()));

var descriptor = new BulkDescriptor();
var context = new MerchEntities();
var sqlTracks = context.vw_MusicTracks.ToList<vw_MusicTracks>();

foreach (var order in sqlTracks)
{
    descriptor.Index<vw_MusicTracks>(op => op.Index("Tracks").Document(order).Type("Track").Id(order.IMUTrackId));
}
    var result = client.Bulk(d => descriptor);
Console.WriteLine("job's done");
Console.ReadKey();

vw_MusicRules.cs vw_MusicRules.cs

using Nest;
using System.ComponentModel.DataAnnotations;
using System;
using System.Collections.Generic;
namespace MusicStore
{

      [ElasticType(Name = "Track", IdProperty = "IMUTrackId")]
    public partial class vw_MusicTracks
    {
          [Key]
        public int IMUTrackId { get; set; }
        public int IMUTrackTypeId { get; set; }
        public int AreaId { get; set; }
        public int GenreId { get; set; }
        public int CityId { get; set; }
        public int ArtistId { get; set; }
        public System.DateTime Live { get; set; }
        public Nullable<System.DateTime> LiveThrough { get; set; }
        public decimal Value { get; set; }
        public short Priority { get; set; }
        public System.DateTime LastModified { get; set; }
        public int LastModifierId { get; set; }
        public System.DateTime Created { get; set; }
        public string IMUTrackType { get; set; }
        public string ModifierUserName { get; set; }
        public string ModifierFirstName { get; set; }
        public string ModifierLastName { get; set; }
        public string ModifierEmail { get; set; }
        public string AreaName { get; set; }
        public Nullable<int> Department { get; set; }
        public Nullable<int> Class { get; set; }
        public Nullable<int> SubClass { get; set; }
        public string Class { get; set; }
        public string GenreName { get; set; }
        public string ArtistName { get; set; }
        public string CityName { get; set; }
    }
}

Serialized sqlTracks 序列化的sqlTracks

[
    {
        "IMUTrackId": 3,
        "IMUTrackTypeId": 1,
        "AreaId": 1,
        "GenreId": -1,
        "CityId": -1,
        "ArtistId": -1,
        "Live": "2014-01-01T00:00:00",
        "LiveThrough": "2015-11-11T00:00:00",
        "Value": 1.2195,
        "Priority": 1,
        "LastModified": "2014-02-25T00:00:00",
        "LastModifierId": 218,
        "Created": "2014-02-25T00:00:00",
        "IMUTrackType": "Mult",
        "ModifierUserName": "SystemUser",
        "ModifierFirstName": "First",
        "ModifierLastName": "",
        "ModifierEmail": "dev@email.ex",
        "AreaName": "Pl",
        "Department": 1,
        "Class": 1a,
        "SubClass": 0,
        "GenreName": "",
        "ArtistName": "",
        "CityName": ""
    }
]

将索引更改为所有小写字母即可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM