【问题标题】:Elastic search mapper-attachments, NEST - throwing error on indexing弹性搜索映射器附件,NEST - 索引时抛出错误
【发布时间】:2015-06-04 06:35:55
【问题描述】:

我最近开始使用弹性搜索,我正在尝试使用 mapper-attachment 插件索引 pdf 文档,索引时我遇到错误值不能为空参数名称:索引,有人可以帮助解决这个问题..

这是索引的代码:

    static void Main(string[] args)
    {

        var connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200/"));
        var elasticClient = new ElasticClient(connectionSettings);

        elasticClient.CreateIndex("pdf-index", c => c.AddMapping<Document>(m => m.MapFromAttributes()));

        var attachment = new Attachment
        {
            Content = Convert.ToBase64String(File.ReadAllBytes("test.pdf")),
            ContentType = "application/pdf",
            Name = "test.pdf"
        };

        var doc = new Document()
        {
            Id = 1,
            Title = "test",
            File = attachment
        };

        elasticClient.Index(doc);
    }

    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; }
    }

    public class Document
    {
        public int Id { get; set; }

        public string Title { get; set; }

        [ElasticProperty(Type = FieldType.Attachment, TermVector = TermVectorOption.WithPositionsOffsets, Store = true)]
        public Attachment File { get; set; }

    }

【问题讨论】:

    标签: elasticsearch attachment nest elasticsearch-plugin


    【解决方案1】:

    我猜您忘记在弹性搜索连接设置中添加默认索引。

    var uri = new Uri("http://localhost:9200/");
    var connectionSettings = new ConnectionSettings(uri, defaultIndex: "my-application");
    

    var elasticClient = new ElasticClient(connectionSettings);

    更多信息在这里http://nest.azurewebsites.net/nest/connecting.html

    当然,默认索引是可选的。那么你必须在索引文档时指定索引。 例如

    client.Index(doc, i => i
         .Index(index)
         .Type(type)     
    );
    

    【讨论】:

      猜你喜欢
      • 2016-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-18
      • 1970-01-01
      • 2015-07-21
      • 2011-10-30
      • 1970-01-01
      相关资源
      最近更新 更多