elasticsearch 如何将日期数组映射到弹性搜索?
我有一个日期数组,我想按嵌套创建映射。 但我当前的映射搜索不起作用。查询示例为:elasticsearch 如何将日期数组映射到弹性搜索?,elasticsearch,nest,elasticsearch,Nest,我有一个日期数组,我想按嵌套创建映射。 但我当前的映射搜索不起作用。查询示例为: publicationDates: '1995-01-11' 我的映射: [ElasticsearchType(Name = "doc-index", IdProperty = "Id")] public class DocumentIndex { [Keyword(Index = false)] public string Id { get; set; } [Text] publ
publicationDates: '1995-01-11'
我的映射:
[ElasticsearchType(Name = "doc-index", IdProperty = "Id")]
public class DocumentIndex
{
[Keyword(Index = false)]
public string Id { get; set; }
[Text]
public string Title { get; set; }
[Date(Format = "yyyy-MM-dd")]
public IEnumerable<DateTime> PublicationDates { get; set; }
}
[ElasticsearchType(Name=“doc index”,IdProperty=“Id”)]
公共类文档索引
{
[关键字(索引=false)]
公共字符串Id{get;set;}
[正文]
公共字符串标题{get;set;}
[日期(格式=“yyyy-MM-dd”)]
public IEnumerable PublicationDates{get;set;}
}
参数Format
告诉Elasticsearch如何在服务器端将传入字符串解析为日期
,但它不影响客户端序列化日期时间
的方式,它使用Json.NET内部DateTime
序列化处理将DateTime
序列化为ISO8601格式
如果希望以不同的方式序列化POCO的DateTime
,最简单的方法是实现JsonConverter
并将PublicationDates
属性指定为使用此转换器。这就是NEST 5.x和以前版本所需的全部内容
在NEST 6.x中,Json.NET依赖关系是内部化的,因此如果使用NEST 6.x,还需要使用and,以便将类型的序列化委托给Json.NET。谢谢!我花了几个小时试图解决这个问题。我不断收到一个“无效日期时间格式”的
意外LasticSearchClientException
错误。将sourceSerializer:(x,y)=>新的JsonNetSerializer(x,y)
添加到我的ConnectionSettings
构造函数为我修复了它。