【发布时间】:2016-06-03 18:40:01
【问题描述】:
我正在使用 ElasticSearch 和 NEST 版本 2 来索引数据。我的数据对象可以有相同类型的子对象。我使用注释来表示不分析某些字段。发生的事情是这个注释被应用到父对象,而不是子对象。我正在尝试弄清楚如何修改我的注释以包含子实例。
我有这样的事情:
public class Person {
public int Id {get; set;}
[String(Index = FieldIndexOption.NotAnalyzed)]
public string Code {get; set;}
public Person child {get; set;}
}
当我第一次创建索引时如下:
client.Map<Person>(d => d.AutoMap());
映射如下所示:
"people": {
"mappings": {
"person": {
"properties": {
"id": {
"type": "integer"
},
"code": {
"type": "string",
"index": "not_analyzed"
},
"child": {
"type": "object"
}
}
}
}
}
我索引一些文档后如下:
client.Index(person);
映射更改为:
"people": {
"mappings": {
"person": {
"properties": {
"id": {
"type": "integer"
},
"code": {
"type": "string",
"index": "not_analyzed"
},
"child": {
"properties": {
"id": {
"type": "integer"
},
"code": {
"type": "string"
}
}
}
}
}
}
}
假设我有这样的文件:
{
"id": 100,
"code": "ABC100",
"child": {
"id": 123,
"code": "ABC123"
}
}
发生的情况是顶级人的Code字段没有分析,这很好,所以我可以这样搜索:
GET people/_search
{
"query": {
"term": {
"code": "ABC100"
}
}
}
但是child上的code字段是用默认分析器分析的,所以ABC123变成了abc123。
因此,所有这些都会找到我的文档:
GET people/_search
{
"query": {
"term": {
"child.id": 123
}
}
}
GET people/_search
{
"query": {
"term": {
"child.code": "abc123"
}
}
}
GET people/_search
{
"query": {
"match": {
"child.id": "ABC123"
}
}
}
但这不是:
GET people/_search
{
"query": {
"term": {
"child.code": "ABC123"
}
}
}
我需要对我的对象注释进行哪些更改才能将相同的字段选项应用于子人员? (顺便说一句,在现实生活中,我有几个没有分析的领域,以及几个层次的深度。)
【问题讨论】:
-
你能展示你用
curl -XGET localhost:9200/people得到的映射吗? -
编辑了我的问题以包含此信息。
标签: elasticsearch nest