# Ingest Attachment: Parse Error using NEST

**URL:** <https://discuss.elastic.co/t/ingest-attachment-parse-error-using-nest/84955>\
**Category:** Elasticsearch\
**Created:** [May 8, 2017, 3:39pm UTC](https://discuss.elastic.co/t/ingest-attachment-parse-error-using-nest/84955 "2017-05-08T15:39:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![PierreFre](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@PierreFre](https://discuss.elastic.co/u/PierreFre)\
**Post date:** [May 8, 2017, 3:39pm UTC](https://discuss.elastic.co/t/ingest-attachment-parse-error-using-nest/84955/1 "2017-05-08T15:39:40Z")

</div>

I got the following error after execute my c#-code

```
`Preformatted text`[2017-05-08T17:34:15,135][DEBUG][o.e.a.b.TransportShardBulkAction] [-h4nwTK] [documents][3] failed to execute bulk item (index) BulkShardRequest [[documents][3]] containing [index {[documents][document][1], source[{"path":"D:\\foo.docx","attachment":{"date":"2017-05-04T15:58:00Z","content_type":"application/vnd.openxmlformats-officedocument.wordprocessingml.document","author":"Pierre","language":"et","content":"Java, C++, C","content_length":13},"id":1}]}]
org.elasticsearch.index.mapper.MapperParsingException: failed to parse [attachment]
	at org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:298) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:450) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:467) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.mapper.DocumentParser.innerParseObject(DocumentParser.java:383) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrNested(DocumentParser.java:373) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.mapper.DocumentParser.internalParseDocument(DocumentParser.java:93) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:66) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:277) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:532) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.shard.IndexShard.prepareIndexOnPrimary(IndexShard.java:509) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.bulk.TransportShardBulkAction.prepareIndexOperationOnPrimary(TransportShardBulkAction.java:447) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.bulk.TransportShardBulkAction.executeIndexRequestOnPrimary(TransportShardBulkAction.java:455) ~[elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.bulk.TransportShardBulkAction.executeBulkItemRequest(TransportShardBulkAction.java:143) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:113) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:69) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryShardReference.perform(TransportReplicationAction.java:939) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryShardReference.perform(TransportReplicationAction.java:908) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.ReplicationOperation.execute(ReplicationOperation.java:113) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.onResponse(TransportReplicationAction.java:322) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.onResponse(TransportReplicationAction.java:264) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction$1.onResponse(TransportReplicationAction.java:888) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction$1.onResponse(TransportReplicationAction.java:885) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.shard.IndexShardOperationsLock.acquire(IndexShardOperationsLock.java:147) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.index.shard.IndexShard.acquirePrimaryOperationLock(IndexShard.java:1654) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction.acquirePrimaryShardReference(TransportReplicationAction.java:897) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction.access$400(TransportReplicationAction.java:93) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.doRun(TransportReplicationAction.java:281) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:260) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:252) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:618) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:638) [elasticsearch-5.3.1.jar:5.3.1]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-5.3.1.jar:5.3.1]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_131]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
Caused by: java.lang.IllegalStateException: Can't get text on a START_OBJECT at 1:37

```

Any ideas?

Best regards,  
Pierre

---

<div class="post-metadata">

**Author:** ![PierreFre](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@PierreFre](https://discuss.elastic.co/u/PierreFre)\
**Post date:** [May 8, 2017, 3:40pm UTC](https://discuss.elastic.co/t/ingest-attachment-parse-error-using-nest/84955/2 "2017-05-08T15:40:16Z")

</div>

C# - Code-Snippet:

```
            var indexResponse = client.CreateIndex(index, c => c
                .Settings(s => s
                    .Analysis(a => a
                        .Analyzers(ad => ad
                            .Custom("windows_path_hierarchy_analyzer", ca => ca
                                .Tokenizer("windows_path_hierarchy_tokenizer")
                            )
                         )
                         .Tokenizers(t => t
                            .PathHierarchy("windows_path_hierarchy_tokenizer", ph => ph
                                .Delimiter('\\')
                            )
                         )
                     )
                 )
                 .Mappings(m => m
                    .Map<Document>(mp => mp
                        .AutoMap()
                        .AllField(all => all
                        .Enabled(false)
                    )
                    .Properties(ps => ps
                        .Text(s => s
                            .Name(n => n.Path)
                            .Analyzer("windows_path_hierarchy_analyzer")
                        )
                        .Object<Attachment>(a => a
                            .Name(n => n.Attachment)
                            .AutoMap()
                        )
                    )
                 )
               )
            );

            client.PutPipeline("attachments", p => p
                .Description("Document attachment pipeline")
                .Processors(pr => pr
                    .Attachment<Document>(a => a
                        .Field(f => f.Cv)
                        .TargetField(f => f.Attachment)
                    )
                    .Remove<Document>(r => r
                        .Field(f => f.Cv)
                    )
                )
            );

            client.Index(document, i => i.Pipeline("attachments"));
```

---

<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 9, 2017, 7:06am UTC](https://discuss.elastic.co/t/ingest-attachment-parse-error-using-nest/84955/3 "2017-05-09T07:06:57Z")

</div>

Hey @PierreFre, what does the `Document` type definition look like and where is the instance assigned to `document` constructed? Could you edit your question to add those please?

---

<div class="post-metadata">

**Author:** ![PierreFre](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@PierreFre](https://discuss.elastic.co/u/PierreFre)\
**Post date:** [May 9, 2017, 7:33am UTC](https://discuss.elastic.co/t/ingest-attachment-parse-error-using-nest/84955/4 "2017-05-09T07:33:13Z")

</div>

Hello @forloop ,  
here is the document-class:

```
public class Document
        {
            public int Id { get; set; }
            public string Path { get; set; }
            public string Cv { get; set; }
            public Attachment Attachment { get; set; }
        }

```

Here is the rest of the code:

```
var index = "documents";
            var node = new Uri("http://localhost:9200");
            var settings = new ConnectionSettings(node)
                .InferMappingFor<Document>(m => m.IndexName(index))
                .EnableDebugMode();

            var client = new ElasticClient(settings);

            var file = @"D:\foo.docx";

            var cvBytes = File.ReadAllBytes(file);
            var cvToBase64 = Convert.ToBase64String(cvBytes);

            var document = new Document()
            {
                Id = 1,
                Path = file,
                Cv = cvToBase64
            };
```

---

<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 10, 2017, 7:28am UTC](https://discuss.elastic.co/t/ingest-attachment-parse-error-using-nest/84955/5 "2017-05-10T07:28:41Z")

</div>

do you also have the log of requests and responses from enabling debug mode? If it's long, you can create a [gist](https://gist.github.com/) and link to it .

---

<div class="post-metadata">

**Author:** ![PierreFre](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@PierreFre](https://discuss.elastic.co/u/PierreFre)\
**Post date:** [May 10, 2017, 2:16pm UTC](https://discuss.elastic.co/t/ingest-attachment-parse-error-using-nest/84955/6 "2017-05-10T14:16:24Z")

</div>

Hello Russ,

here is the [Log](https://gist.githubusercontent.com/anonymous/c88961077b3028a0f1dd8070ef230403/raw/1f1f9852c6fa83c03044c72981042923dfc56529/Log.txt)

regards,  
Pierre

---

<div class="post-metadata">

**Author:** ![PierreFre](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@PierreFre](https://discuss.elastic.co/u/PierreFre)\
**Post date:** [May 12, 2017, 9:10am UTC](https://discuss.elastic.co/t/ingest-attachment-parse-error-using-nest/84955/7 "2017-05-12T09:10:24Z")

</div>

@forloop, do you have any ideas or alternatives? I was thinking to extract the text of word and pdf documents by myself and save them in a text field.

best regards,  
Pierre

---

<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:** [June 9, 2017, 9:21am UTC](https://discuss.elastic.co/t/ingest-attachment-parse-error-using-nest/84955/8 "2017-06-09T09:21:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
