# Nest ingest a list of attachments

**URL:** <https://discuss.elastic.co/t/nest-ingest-a-list-of-attachments/222360>\
**Category:** Elasticsearch\
**Created:** [March 5, 2020, 7:11pm UTC](https://discuss.elastic.co/t/nest-ingest-a-list-of-attachments/222360 "2020-03-05T19:11:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gutospinelli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gutospinelli/32/65633_2.png) [@gutospinelli](https://discuss.elastic.co/u/gutospinelli)\
**Post date:** [March 5, 2020, 7:11pm UTC](https://discuss.elastic.co/t/nest-ingest-a-list-of-attachments/222360/1 "2020-03-05T19:11:32Z")

</div>

Hi everyone!

I am trying to index an object called "News" who has a list of "NewsFiles" using NEST/C#

The simplified code for my news class follows:

```
public class News
{
(...)
public List<NewsFiles> Files { get; set; }
}    

```

and the simplified code of my NewsFiles class also follows:

```
public class NewsFiles 
{
        public int Id { get; set; }
        public string Content { get; set; } 
        public Attachment File{ get; set; }
}

```

\*the attachment type above refers to the Nest.Attachment class.

I can't index an instance of News class containing one or more file attachments, using the pipeline I've created (possibly the source of the error)

The code I use to index the object follows:

```
var response = nest.ElasticClient.Index(news, p => p
                        .Index("intranet")
                        .Pipeline("attachmentsnewsfiles")
                    );

```

The pipeline used:

```
ElasticClient.Ingest.PutPipeline("attachmentsnewsfiles", p => p
              .Description("news files attachment pipeline")
              .Processors(pr => pr
                .Foreach<News>(fe => fe
                        .Field(f => f.Files)
                        .Processor(fep => fep
                            .Attachment<NewsFiles>(a => a
                                .Field(f => f.Content)
                                .TargetField(f => f.File)
                            )
                        )
                    )
                )
            );

```

and the error I get : "field [content] not present as part of path [content]"

Can someone give me a hand? Thanks a lot!

---

<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:** [March 6, 2020, 7:52am UTC](https://discuss.elastic.co/t/nest-ingest-a-list-of-attachments/222360/2 "2020-03-06T07:52:48Z")

</div>

Welcome!

I'm not a .Net dev so I'm not sure my answer will be accurate or not. If not, it would be great if you could translate your code to a recreation script that we can run in the Kibana dev console.

But, I believe that you are putting the "binary" content in `File` field and you want to extract the text to `Content` field.  
If so, I believe you should write:

```
.Field(f => f.File)
.TargetField(f => f.Content)
```

---

<div class="post-metadata">

**Author:** ![gutospinelli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gutospinelli/32/65633_2.png) [@gutospinelli](https://discuss.elastic.co/u/gutospinelli)\
**Post date:** [March 6, 2020, 3:06pm UTC](https://discuss.elastic.co/t/nest-ingest-a-list-of-attachments/222360/3 "2020-03-06T15:06:00Z")

</div>

Hi friend!

First of all, thank you for your time and your response.

Unfortunatlly it didn't worked. The error only changed  
from:  
"field [content] not present as part of path [content]"  
to:  
"field [attachment] not present as part of path [attachment]"

In fact I believe that the following relation is correct, since it works when I map in a 1:1 relation (one Attachment attribute directly in one News class).

```
.Field(f => f.Content)
.TargetField(f => f.File)

```

My guess is that I am missing something in the use of the Foreach, since aparently the request is trying to find a path to "attachment" and the Field can't be found. Since there's a field called attachment in the NewsFiles class, maybe the processor is looking on the News class, not on the NewsFiles.

Hope my poor explanation is clear enough.

---

<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:** [March 6, 2020, 3:43pm UTC](https://discuss.elastic.co/t/nest-ingest-a-list-of-attachments/222360/4 "2020-03-06T15:43:21Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. Then we can try to translate the solution to the .Net world.

You can use the `_simulate` API for that.

---

<div class="post-metadata">

**Author:** ![gutospinelli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gutospinelli/32/65633_2.png) [@gutospinelli](https://discuss.elastic.co/u/gutospinelli)\
**Post date:** [March 6, 2020, 7:37pm UTC](https://discuss.elastic.co/t/nest-ingest-a-list-of-attachments/222360/5 "2020-03-06T19:37:14Z")

</div>

Problem Solved!

```
ElasticClient.Ingest.PutPipeline("attachments", p => p
              .Description("Document attachments pipeline")
              .Processors(pp => pp
                .Foreach<News>(fe => fe
                    .Field(f => f.Files)
                    .Processor(fep => fep
                        .Attachment<Attachment>(a => a
                            .Field("_ingest._value.content")
                            .TargetField("_ingest._value.file")
                        )
                    )
                )
              )
            );
```

---

<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:** [April 3, 2020, 7:37pm UTC](https://discuss.elastic.co/t/nest-ingest-a-list-of-attachments/222360/6 "2020-04-03T19:37:16Z")

</div>

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