我使用的是elasticsearc 2.3.3和Nest 2.3.2,我需要创建索引 . 需要使用在类文件中添加的属性映射属性 .

public class IndexDocument
{
    [Number(Store = true)]
    public long Id { get; set; }
    [String(Store = true, Index = FieldIndexOption.Analyzed, TermVector = TermVectorOption.WithPositionsOffsets)]
    public string Title { get; set; }
    public Attachment File { get; set; }
    [String(Store = true, Index = FieldIndexOption.Analyzed)]
    public string DocumentType { get; set; }
    [String(Store = true, Index = FieldIndexOption.NotAnalyzed)]
    public string DocLocation { get; set; }
    [String(Store = true, Index = FieldIndexOption.Analyzed)]
    public DateTime LastModifiedDate { get; set; }

}

public class Attachment
{
    public Attachment()
    {

    }
    [String(Name = "_content_length", Store = true, Index = FieldIndexOption.Analyzed)]
    public long ContentLength { get; set; }
    [String(Store = true, Index = FieldIndexOption.Analyzed, TermVector = TermVectorOption.WithPositionsOffsets, Name = "_content")]
    public string Content { get; set; }

}

另外我想在 File 字段中添加 completion suggest . 我是这个弹性搜索的新手 . 有人可以帮忙吗?

我创建了我的附件索引如下 . 如何附加完成建议和词干代码?

this.client.CreateIndex("mydocs", c => c.Mappings(mp => mp.Map<IndexDocument>
                (m => m.Properties(ps => ps.Attachment
                        (a => a.Name(o => o.File)
                               .TitleField(t => t.Name(x => x.Title).TermVector(TermVectorOption.WithPositionsOffsets))
                               )))));