Elasticsearch Nest:索引附件类型

时间:2015-07-21 13:06:42

标签: mapping attachment nest elasticsearch

我是elasticsearch的新手,我正在尝试使用elasticsearch / NEST索引pdf文档。我对此非常陌生,这个问题可能令人困惑。我尝试了所有可以找到的解决方案,没有任何效果。

这是我的模特:

public class Lecture
{
    public int Id { get; set; }
    public DateTime PostDate { get; set; }
    public string Title { get; set; }
    [ElasticProperty(Name = "document", Type = FieldType.Attachment, TermVector = TermVectorOption.WithPositionsOffsets, Store = true)]
    public Attachment Document { get; set; }
    //public string Document { get; set; }
    public string Filepath { get; set; }
    public int CourseId { get; set; }
}

public class Attachment
{
    [ElasticProperty(Name = "_content")]
    public string Content { get; set; }

    [ElasticProperty(Name = "_content_type")]
    public string ContentType { get; set; }

    [ElasticProperty(Name = "_name")]
    public string Name { get; set; }
}

这是从我从数据库中检索的数据创建该模型的实例:

Type t = data.GetType();
        if (t.Name.Contains("Lecture"))
        {
            PropertyInfo p = t.GetProperty("Document");
            object propDocument = p.GetValue(data, null);
            p = t.GetProperty("PostDate");
            object propPostDate = p.GetValue(data, null);
            p = t.GetProperty("Title");
            object propTitle = p.GetValue(data, null);
            p = t.GetProperty("CourseId");
            object propCourseId = p.GetValue(data, null);
            p = t.GetProperty("Filepath");
            object propFilepath = p.GetValue(data, null);
            Lecture lecture = new Lecture();
            lecture.Id = id;
            lecture.CourseId = Int32.Parse(propCourseId.ToString());
            lecture.Title = propTitle.ToString();
            lecture.PostDate = DateTime.Parse(propPostDate.ToString());
            lecture.Filepath = propFilepath.ToString();
            //lecture.Document = Convert.ToBase64String(ObjectToByteArray(propDocument));
            lecture.Document = new Attachment();
            lecture.Document.Content= Convert.ToBase64String(ObjectToByteArray(propDocument));
            lecture.Document.ContentType = "aplication/pdf";
            lecture.Document.Name = propFilepath.ToString();

然后我将其编入索引:

var result = this.client.Index<Lecture>(lecture, i => i.Index(indexName.ToLower())
                    .Id(id));

在索引元数据信息中,我有文档映射,包含所有三个属性,但没有指定的文档类型。我想它应该是&#34;附件&#34;,但也许我错了。问题是我无法搜索pdf文件,elasticsearch只能看到base64编码的字符串值,并且它不会将其解释为文本。我安装了mapper-attachments插件2.6.0,我有弹性搜索1.6.0。请问有什么建议?谢谢!

0 个答案:

没有答案