2016-07-06 93 views
0

我使用Elasticsearch 2.3 - Nest API来搜索数据。我正在使用文档的属性映射。我想知道如何使用属性映射使用语音分析器。Elasticsearch 2.3 - Nest - 使用语音分析器

文档类:

[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" 
      } 
     } 
     } 
    } 
    } 
} 

我还安装Phonetic Analysis Plugin

回答

0

Take a look at the automapping documentation;你需要分析仪的名称分配给Analyzer财产的属性

public class Document 
{ 
    [String(Analyzer="phonetic")] 
    public string Name {get; set;} 
} 

然后调用AutoMap()映射文档类型例如,当当您创建索引

client.CreateIndex("index-name", c => c 
    .Mappings(m => m 
     .Map<Document>(d => d 
      .AutoMap() 
     ) 
    ) 
); 

产生

{ 
    "mappings": { 
    "document": { 
     "properties": { 
     "name": { 
      "type": "string", 
      "analyzer": "phonetic" 
     } 
     } 
    } 
    } 
} 
+0

感谢您的答复,但上面的代码没有产量“拼音”分析,我收到同样的文件映射。 –

+0

@ShahidAzim你可以在问题中显示你正在做什么的代码? –

+0

我已经包含了所有必需的代码。 –