使用NEST

时间:2016-01-27 13:45:50

标签: nest elasticsearch-net

我的第一篇SO帖子! 我试图为字符串字段设置一个Stempel Analyzer(用于抛光语言的ES分析器)。我可以通过PUT请求来做到这一点:

{
   "doc": {
      "_source": {
         "enabled": false
      },
      "properties": {
         "file": {
            "type": "attachment",
            **"analyzer": "polish"**,
            "fields": {
               "content": {
                  "type": "string",
                  "term_vector": "with_positions_offsets"
               }
            }
         }
      }
   }
}

它工作正常。试图通过NEST做同样的事情。

 [ElasticProperty(Name = "_content", TermVector = TermVectorOption.WithPositionsOffsets, Analyzer = "polish")]
 public string Content { get; set; }

不能正常工作:

            client.CreateIndex(index, b => b.AddMapping<DocInES>(m => m
            .MapFromAttributes()
            .Properties(props => props
                .String(s => s
                    .Name(p => p.File.Content)
                    .Analyzer("polish")
                     ))));

当我使用

var result = client.Analyze(a => a.Index("doc").Analyzer("polish").Text("...text..."));

它工作正常,因此.NET正在检测此分析器。 我使用的是ES 2.1.1。 &安培; NEST 1.7.1

编辑: 根据我的检查,似乎NEST没有在.NET中创建Attachment属性的映射。它执行Document类的Map Attributes

[ElasticType(Name = "docInES")]
public class DocInES {
    public int InstitutionId { get; set;}
    public int DocumentId { get; set; }
    [ElasticProperty(Store = true, Analyzer = "polish")]
    public string Title { get; set; }

    [ElasticProperty(Type = FieldType.Attachment)]
    public Attachment File { get; set; }

}

但不是附件类:

public class Attachment {
    [ElasticProperty(Name = "content2", Store = true)]
    public string Content { get; set; }

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

    [ElasticProperty(Name = "name2", Analyzer = "english")]
    public string Name { get; set; }
}

1 个答案:

答案 0 :(得分:0)

您应该检查Github上的兼容性矩阵。

Nest 1.7.1与ES 2.1.1不兼容