【发布时间】:2016-11-08 16:33:52
【问题描述】:
我正在使用 Elasticsearch 2.3 - Nest API 来搜索数据。我正在为文档使用属性映射。我想知道如何通过属性映射来使用语音分析器。
文档类:
[ElasticsearchType(Name = "contact", IdProperty = nameof(EntityId))]
public class ESContactSearchDocument
{
[String(Name = "entityid")]
public string EntityId { get; set; }
[String(Name = "id")]
public string Id { get; set; }
[String(Name = "name")]
public string Name { get; set; }
[String(Name = "domain")]
public string Domain { get; set; }
[String(Name = "description")]
public string Description { get; set; }
[String(Name = "email")]
public string Email { get; set; }
[String(Name = "firstname", Analyzer = "phonetic")]
public string FirstName { get; set; }
[String(Name = "lastname", Analyzer = "phonetic")]
public string LastName { get; set; }
}
索引创建和插入:
var createIndexResponse = serviceClient.CreateIndex(indexName, c => c.Mappings(m => m.Map<ESContactSearchDocument>(d => d.AutoMap())));
var indexManyResponse = await serviceClient.IndexManyAsync(ESMapper.Map<TDocument, ESContactSearchDocument>(documentsBatch), indexName, typeName);
ESMapper 仅用于从一种类型转换为另一种类型。
结果映射:
{
"contact-uklwcl072": {
"mappings": {
"contact": {
"properties": {
"description": {
"type": "string"
},
"domain": {
"type": "string"
},
"email": {
"type": "string"
},
"entityid": {
"type": "string"
},
"firstname": {
"type": "string"
},
"id": {
"type": "string"
},
"lastname": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
}
【问题讨论】:
标签: elasticsearch nest elasticsearch-plugin