【发布时间】:2016-08-26 07:55:55
【问题描述】:
好的,如果这是一个愚蠢的问题,我很抱歉,但我花了一天时间浏览文档并尝试了 3 个不同的 NEST 版本,最终结果是相同的。
基本上,当我使用 Elasticsearch 的 REST api 为一个类型创建映射时,我可以在我的映射上使用 GET 请求,我会收到我想要的:
"properties": {
"date": {
"type": "date",
"format": "basic_date"
},
"id": {
"type": "long",
"index": "no"
},
"name": {
"type": "string"
},
"slug": {
"type": "string",
"index": "no"
}
}
但是,如果我从头开始,并在 c# 中使用以下类:
[Number(Index = NonStringIndexOption.No)]
public long Id { get; set; }
[String(Name = "name")]
public string Name { get; set; }
[String(Name = "slug", Index = FieldIndexOption.No)]
public string Slug { get; set; }
[Date(Format = "dd-MM-yyyy", Index = NonStringIndexOption.No)]
public DateTime Date { get; set; }
并像这样创建和填充索引:
node = new Uri("http://localhost:9200");
settings = new ConnectionSettings(node);
settings.DefaultIndex("searchable-items");
//retrieve stuff from relational db
client.IndexMany(allItemsRetrievedFromRelDb);
我的类型默认如下(基本上忽略所有属性值,除了 Name=)
"date": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"id": {
"type": "long"
},
"name": {
"type": "string"
},
"slug": {
"type": "string"
}
基本上我希望实现的是:
- “basic_date”类型的日期格式
- 只能分析和搜索“名称”
- 最终,“名称”的自定义分析器
我的问题是 - 我做错了什么,为什么 NEST 会忽略我在属性中添加的任何内容?当前代码是 v2.4.4,虽然我也尝试了 5.0.0 预发行版(那里的语法略有不同,但结果相同)。
【问题讨论】:
标签: c# elasticsearch nest