【发布时间】:2018-02-18 19:13:07
【问题描述】:
我有一个 C# 对象,用于将文档索引到 Elasticsearch 中的现有类型。
该对象有一个 DateTime 字段,我想使用基于 NEST 客户端属性的映射来配置映射。我希望将格式配置为 DateFormat.basic_date_time_no_millis。我希望这将从日期时间对象中剔除毫秒。用作要索引的文档的类如下。
public class DBQueueDepth
{
public string QueueName { get; set; }
public int ProcessedCount { get; set; }
public int NotProcessedCount { get; set; }
public string Environment { get; set; }
[Date(Format = DateFormat.basic_date_time_no_millis)]
public DateTime SampleTimeStamp { get; set; }
}
在 Elasticsearch 中映射到的类型是;
"dbQueueDepth": {
"properties": {
"environment": {
"type": "text"
},
"notProcessedCount": {
"type": "integer"
},
"processedCount": {
"type": "integer"
},
"queueName": {
"type": "text"
},
"sampleTimeStamp": {
"type": "date",
"format": "date_time_no_millis"
}
}
我的客户代码是
var node = new Uri("http://localhost:9200");
var settings =
new ConnectionSettings(node).MaximumRetries(10)
.MaxRetryTimeout(new TimeSpan(0, 0, 0, 10))
.DefaultIndex("austin_operational_data")
.InferMappingFor<DBQueueDepth>(i => i.TypeName("dbQueueDepth"));
ElasticClient client = new ElasticClient(settings);
var response = client.IndexMany(rows);
当我尝试为文档编制索引时,我收到以下错误。
{index 返回 400 _index:operational_data _type:dbQueueDepth _id:AV5rqc3g6arLsAmJzpLK _version:0 错误:类型:mapper_parsing_exception 原因:“无法解析 [sampleTimeStamp]” CausedBy: 类型:非法参数异常原因:“无效格式:“2017-09-10T12:00:41.9926558Z”格式错误为“.9926558Z””}
我期望 NEST 客户端根据日期属性中的格式去除毫秒是否正确?
InferMappingFor 方法是否指示客户端使用 C# 对象上的属性指定的格式?
【问题讨论】:
标签: c# elasticsearch elasticsearch-net