0

I have recently started to use elastic search, i am trying to index a pdf document with mapper-attachment plug-in, when indexing i am hitting error value cannot be be null parameter name: index, can someone help in fixing this..

enter image description here

Here is the code for indexing:

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

    }
remo
  • 3,326
  • 6
  • 32
  • 50

1 Answers1

0

i guess you have forget to add default index in your elastic search connection settings.

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

var elasticClient = new ElasticClient(connectionSettings);

more info here http://nest.azurewebsites.net/nest/connecting.html

Of'course default index is optional. then you have to specify index when indexing doc. e.g.

client.Index(doc, i => i
     .Index(index)
     .Type(type)     
);
vijay shiyani
  • 766
  • 7
  • 19