# Indexing articles with attachments

**URL:** <https://discuss.elastic.co/t/indexing-articles-with-attachments/207419>\
**Category:** Elasticsearch\
**Created:** [November 11, 2019, 11:03pm UTC](https://discuss.elastic.co/t/indexing-articles-with-attachments/207419 "2019-11-11T23:03:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruinjoe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bruinjoe/32/30046_2.png) [@bruinjoe](https://discuss.elastic.co/u/bruinjoe)\
**Post date:** [November 11, 2019, 11:03pm UTC](https://discuss.elastic.co/t/indexing-articles-with-attachments/207419/1 "2019-11-11T23:03:00Z")

</div>

We are using a knowledge management system that allows authors to write articles and attach  
documents. The article contains the following fields.

title  
description  
content  
locale  
categories  
issue date  
attachment\_01  
attachment\_02

We are able to index the first six article properties without any issues with Elasticsearch. We know that we will need to use the ingest-attachment plugin for the last two properties. The problem we face is that the data will be in two different indexes. How do we preserve search results so that all the data as defined from above come back as one search hit?

---

<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:** [November 12, 2019, 1:32am UTC](https://discuss.elastic.co/t/indexing-articles-with-attachments/207419/2 "2019-11-12T01:32:28Z")

</div>

Why the data is in 2 different indices?  
If you want to get that back as one hit, it needs to be in the same document.

---

<div class="post-metadata">

**Author:** ![bruinjoe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bruinjoe/32/30046_2.png) [@bruinjoe](https://discuss.elastic.co/u/bruinjoe)\
**Post date:** [November 13, 2019, 2:27am UTC](https://discuss.elastic.co/t/indexing-articles-with-attachments/207419/4 "2019-11-13T02:27:07Z")

</div>

Here is a sample of my document.

Listing A

```
{
    "title": "Example document with multiple attachments",
    "description" : "Some description here...",
    "content": "Main document content",
    "locale": "en_US".
    "categories": [
           {
              "refkey" : "NOSQL",
              "name" : "NoSQL",
              "objectid" : "016.001.001",
              "guid" : "091ed45fc58045a2b03df1b6d7763ec5"
           },
           {
              "refkey" : "ELASTICSEARCH_NOSQL",
              "name" : "Elasticsearch (NoSQL)",
              "objectid" : "016.001.001.001",
              "guid" : "3a8e36597efe4439bebf7bb0c9297b98"
           }
    ],
    "attachments" : [
           {
                "title" : "Word example",
                "data" : "VGhpcyBpcyBhIHRlc3Qgd29yZCBkb2N1bWVudAo=",
                "content" : "test.docx",
                "size" : 4094,
                "description" : "Word example description goes here."
            },
            {
                "title" : "PDF example",
                "data" : "CkZpbGU6IC9ob21lL2p0YW5nL3RtcC90ZXN0MDEudHh0IFBhZ2UgMSBvZiAxCgogCkhlbGxvIHdvcmxkCgoK",
                "content" : "test01.pdf",
                "size" : 11595,
                "description" : "PDF example description goes here."
           }
     ]
}

```

I created a pipeline with the following  
Listing B

```
PUT /_ingest/pipeline/attachment
{
  "description" : "Extract attachment information from arrays",
  "processors" : [
    {
      "foreach": {
        "field": "attachments",
        "processor": {
          "attachment": {
            "target_field": "_ingest._value.attachment",
            "field": "_ingest._value.data"
          }
        }
      }
    }
  ]
}

```

Do I send my whole document to Elasticsearch like the following:

```
PUT howto_en/_doc/howto1005?pipeline=attachment
{
  //Listing A
}
```

---

<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:** [November 13, 2019, 8:24am UTC](https://discuss.elastic.co/t/indexing-articles-with-attachments/207419/5 "2019-11-13T08:24:46Z")

</div>

Thanks for the detailed script. It helps.

I did not test it but it looks good to me.

---

<div class="post-metadata">

**Author:** ![bruinjoe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bruinjoe/32/30046_2.png) [@bruinjoe](https://discuss.elastic.co/u/bruinjoe)\
**Post date:** [November 13, 2019, 6:44pm UTC](https://discuss.elastic.co/t/indexing-articles-with-attachments/207419/6 "2019-11-13T18:44:16Z")

</div>

Thank you for the assistance. I got it to work.

---

<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:** [December 11, 2019, 6:44pm UTC](https://discuss.elastic.co/t/indexing-articles-with-attachments/207419/7 "2019-12-11T18:44:22Z")

</div>

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