# Attachment is not getting parsed

**URL:** <https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721>\
**Category:** Elasticsearch\
**Created:** [May 11, 2016, 3:52am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721 "2016-05-11T03:52:58Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 11, 2016, 3:52am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/1 "2016-05-11T03:52:58Z")

</div>

//using iTextSharp.text;  
//using iTextSharp.text.pdf;  
using Nest;  
using System;  
using System.Collections.Generic;  
using [System.IO](http://System.IO);  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
namespace ConsoleApplication10  
{  
class Program  
{  
[ElasticsearchType(Name = "pdfs")]  
public class Case  
{  
public string Author { get; set; }  
public string CaseName { get; set; }  
[Attachment(Store = true)]  
public string attachfile { get; set; }  
//[String(Name = "\_content\_type")]  
public string Content { get; set; }  
public Case()  
{

```
        }

        //public override string ToString()
        //{
        // return "Case: " + Author + " - " + File.Name;
        //}
    }

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

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

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

    //}
    static void Main(string[] args)
    {
        var index = "pg";
        var node = new Uri("http://localhost:9200");
        var settings = new ConnectionSettings(node).DefaultIndex(index);
        var client = new ElasticClient(settings);

       // var attachment = new Attachment();
        string path = @"C:\Elasticsearch_The Definitive Guide.pdf";
       // attachment.Name = path;
        //attachment.Content = Convert.ToBase64String(File.ReadAllBytes(path));
        
        //Case.ContentType = "application/json";
        //obj.attachfile= Convert.ToBase64String(File.ReadAllBytes(path));
        
        Case obj = new Case();
        obj.Content = Convert.ToBase64String(File.ReadAllBytes(path));
        

        var doc2 = new Case()
        {
            Author = "Martin Luther 2",
            CaseName = "Bank vs Martin",
            attachfile = obj.attachfile

        };

        client.Map<Case>(m => m
.Properties(ps => ps
        .String(s => s
            .Name(f => f.CaseName)
            .Index(FieldIndexOption.Analyzed)
            .Store(true))

```

.Attachment(atm =\> atm  
.Name(p =\> p.attachfile)  
.FileField(f =\> f  
.Name(p =\> p.attachfile)  
.Index(FieldIndexOption.Analyzed)  
.Store(true)  
.TermVector(TermVectorOption.WithPositionsOffsets))  
.AuthorField(af =\> af  
.Name(p =\> p.Author)  
.Store(true)  
.Index(FieldIndexOption.Analyzed)  
.TermVector(TermVectorOption.WithPositionsOffsets))))  
);

```
        var indexingthedoc = client.Index<Case>(doc2);
        
        
        Console.Write(indexingthedoc.CallDetails);
        Console.Read();
    }
   
}

```

}

---

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 11, 2016, 3:54am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/2 "2016-05-11T03:54:22Z")

</div>

I am using elasticsearch-5.0.0-alpha2 ES.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 11, 2016, 5:22am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/3 "2016-05-11T05:22:22Z")

</div>

Please format your code.

Could you write a curl script which could help to understand?

What is the mapping?  
Is the plugin installed?

BTW, as you are using 5.0, prefer using the ingest attachment plugin.

---

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 11, 2016, 5:52am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/4 "2016-05-11T05:52:58Z")

</div>

Yes the plugin is installed.I want to use ES-2.3.2 in order to index my pdf file and I want to do text search after mapping is done.

Could you please give me the link to install mapper-attachments plugin zip file for ES-2.3.2..from cmd prompt I am facing issues to install for ES-2.3.2. I have win 7

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 11, 2016, 6:09am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/5 "2016-05-11T06:09:19Z")

</div>

[https://www.elastic.co/guide/en/elasticsearch/plugins/current/mapper-attachments.html](https://www.elastic.co/guide/en/elasticsearch/plugins/current/mapper-attachments.html)

---

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 11, 2016, 6:18am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/6 "2016-05-11T06:18:28Z")

</div>

Verifying [https://download.elastic.co/elasticsearch/release/org/elasticsearch/pl](https://download.elastic.co/elasticsearch/release/org/elasticsearch/pl)  
ugin/mapper-attachments/2.3.2/mapper-attachments-2.3.2.zip checksums if availabl  
e ...  
Downloading .DONE  
ERROR: Could not load plugin descriptor for existing plugin [elasticsearch-mappe  
r-attachments-2.4.3]. Was the plugin built before 2.0?

I am getting this error, as it is saying the plugin is for 2.0 not for 2.3.2

---

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 11, 2016, 6:19am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/7 "2016-05-11T06:19:58Z")

</div>

Thanks it got installed.. I don't know why it was having an issue previously..might be the old version mapping files were there might caused an issue

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 11, 2016, 6:30am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/8 "2016-05-11T06:30:27Z")

</div>

But again please be aware that this plugin has been deprecated.  
It will still exist in 5.0 but will be removed in the future.

---

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 11, 2016, 6:31am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/9 "2016-05-11T06:31:19Z")

</div>

I have a class Case which is having Attachment attribute on it's attachfile object

[ElasticsearchType(Name = "pdfs")]  
public class Case  
{  
public int Id { get; set; }  
public string Author { get; set; }  
public string CaseName { get; set; }  
[Attachment(Store = true)]  
public string attachfile { get; set; }  
public string Content { get; set; }  
public Case()  
{

```
        }
    }

```

This is the Mapping and Indexing I am doing on attachment

client.Map(m =\> m  
.Properties(ps =\> ps  
.String(s =\> s  
.Name(f =\> f.CaseName)  
.Index(FieldIndexOption.Analyzed)  
.Store(true))  
.Attachment(atm =\> atm  
.Name(p =\> p.attachfile)  
.FileField(f =\> f  
.Name(p =\> p.attachfile)  
.Index(FieldIndexOption.Analyzed)  
.Store(true)  
.TermVector(TermVectorOption.WithPositionsOffsets))  
.AuthorField(af =\> af  
.Name(p =\> p.Author)  
.Store(true)  
.Index(FieldIndexOption.Analyzed)  
.TermVector(TermVectorOption.WithPositionsOffsets))))  
);

```
        var indexingthedoc = client.Index<Case>(doc2);

```

But in Sense Beta I am getting an error of parsing.

---

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 11, 2016, 6:32am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/10 "2016-05-11T06:32:10Z")

</div>

{  
"error": {  
"root\_cause": [  
{  
"type": "mapper\_parsing\_exception",  
"reason": "failed to parse, document is empty"  
}  
],  
"type": "mapper\_parsing\_exception",  
"reason": "failed to parse, document is empty"  
},  
"status": 400  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 11, 2016, 6:48am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/11 "2016-05-11T06:48:15Z")

</div>

If you need help please provide something which is readable and that we can reproduce.  
I don't use your coding language so I can't replay / understand it easily.

A curl recreation is more helpful.

---

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 11, 2016, 6:56am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/12 "2016-05-11T06:56:25Z")

</div>

I will try to convert in Curl, but I don't have any idea how to write this code in curl

---

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 11, 2016, 7:05am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/13 "2016-05-11T07:05:52Z")

</div>

curl -XPUT localhost:9200/pg/pdfs/999

{  
"Id": {  
"Author" : {  
"attachfile" : { "type" : "attachment" }  
}

}  
}  
'

{

"files" : [  
{  
"\_content\_type" : "application/pdf",  
"\_name" : "mypdffile.pdf",  
"content" : " ...base64-encoded content.."  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 11, 2016, 7:08am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/14 "2016-05-11T07:08:04Z")

</div>

The original code I have written in C#.Net and I have used NEST [Elasticsearch.Net](http://Elasticsearch.Net) as a refernced API

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 11, 2016, 7:17am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/15 "2016-05-11T07:17:33Z")

</div>

Please format your code.

BTW I can't reproduce your example. I have no mapping here.

Even if this is not a full curl script, this example is much more readable: [Unable to Find Document, Searching Contents - Mapper Attachments Plugin](https://discuss.elastic.co/t/unable-to-find-document-searching-contents-mapper-attachments-plugin/48500)

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [May 11, 2016, 7:41am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/16 "2016-05-11T07:41:22Z")

</div>

@Piyush_Giri, I have [opened an issue](https://github.com/elastic/elasticsearch-net/issues/2085) to make it easier to use the mapper-attachments plugin with NEST.

The plugin is currently supported and tested as part of our CI process ([have a look at the integration tests](https://github.com/elastic/elasticsearch-net/blob/2.x/src/Tests/Document/Single/Attachment/AttachmentApiTests.cs)), but more advanced uses require you to write additional code to handle scenarios such as explicit metadata fields and serialization/deserialization of source data into CLR types.

---

<div class="post-metadata">

**Author:** ![Piyush\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Piyush\_Giri](https://discuss.elastic.co/u/Piyush_Giri)\
**Post date:** [May 13, 2016, 12:50am UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/17 "2016-05-13T00:50:16Z")

</div>

@forloop Thanks russ.. when can we expect the issue #2085 be resolved and plugin can have that fix??

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:51pm UTC](https://discuss.elastic.co/t/attachment-is-not-getting-parsed/49721/18 "2017-07-05T22:51:56Z")

</div>


