# Index PDF with Ingest Attachement Plugin using NodeJS Client

**URL:** <https://discuss.elastic.co/t/index-pdf-with-ingest-attachement-plugin-using-nodejs-client/288870>\
**Category:** Elasticsearch\
**Created:** [November 10, 2021, 9:51am UTC](https://discuss.elastic.co/t/index-pdf-with-ingest-attachement-plugin-using-nodejs-client/288870 "2021-11-10T09:51:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BE-CH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/be-ch/32/96947_2.png) [@BE-CH](https://discuss.elastic.co/u/BE-CH)\
**Post date:** [November 10, 2021, 9:51am UTC](https://discuss.elastic.co/t/index-pdf-with-ingest-attachement-plugin-using-nodejs-client/288870/1 "2021-11-10T09:51:56Z")

</div>

I am having a hard time understanding how I can index files such PDF and .RTF files using the [Ingest Attachment Processor Plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/current/ingest-attachment.html) and make them **searchable**.

My main problem seems to be that I can't search for the files after I did the following steps;

**First i created a pipeline**

```auto
client.ingest.putPipeline({
  id: 'attachment',
  body: {
    description: 'Extract attachment information',
    processors: [
      {
        attachment: {
          field: 'data',
        },
      },
    ],
  },
});

```

**Then i inserted my Lorem Ipsum .rtf file**

```auto
client.index({
  index: 'books',
  pipeline: 'attachment',
  body: {
    data: 'e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0=',
  },
});

```

**Lastly i searched for it:**

```auto
client.search({
  index: 'books',
  body: {
    query: {
      match: { content: "Lorem ipsum" },
    },
  },
});

```

The problem is that the **search returns no matches**! 😢

I tried checking if the document was there by getting it by id and it does indeed find it. Even with the attachment data decoded from the bas64 data. See the JSON response below.

```auto
"attachment": {
      "content_type": "application/rtf",
      "language": "ro",
      "content": "Lorem ipsum dolor sit amet",
      "content_length": 28
    }

```

---

<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 10, 2021, 10:32am UTC](https://discuss.elastic.co/t/index-pdf-with-ingest-attachement-plugin-using-nodejs-client/288870/2 "2021-11-10T10:32:34Z")

</div>

Welcome!

Try:

```auto
client.search({
  index: 'books',
  body: {
    query: {
      match: { attachment.content: "Lorem ipsum" },
    },
  },
});

```

---

<div class="post-metadata">

**Author:** ![BE-CH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/be-ch/32/96947_2.png) [@BE-CH](https://discuss.elastic.co/u/BE-CH)\
**Post date:** [November 10, 2021, 10:47am UTC](https://discuss.elastic.co/t/index-pdf-with-ingest-attachement-plugin-using-nodejs-client/288870/3 "2021-11-10T10:47:35Z")

</div>

Thank you! It works.

Quick follow up question; Am I doing it the intended and correct way? and does the `attachment` in

```auto
match: { attachment.content: "Lorem ipsum" },

```

refer to the name of my pipeline called `attachment`?

---

<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 10, 2021, 11:04am UTC](https://discuss.elastic.co/t/index-pdf-with-ingest-attachement-plugin-using-nodejs-client/288870/4 "2021-11-10T11:04:34Z")

</div>

Yes. You are doing it correctly.

`attachment` refers to the field name in the document:

```json
{
   // ...,
   "attachment": {
      "content_type": "application/rtf",
      "language": "ro",
      "content": "Lorem ipsum dolor sit amet",
      "content_length": 28
    }
}

```

This field and the inner fields are generated by the ingest attachment processor which you put in an ingest pipeline named `attachment` as well but that's a coincidence.

You could define your ingest attachment like this:

```auto
client.ingest.putPipeline({
  id: 'foo',
  body: {
    description: 'Extract attachment information',
    processors: [
      {
        attachment: {
          field: 'data',
        },
      },
    ],
  },
});

```

And use it:

```auto
client.index({
  index: 'books',
  pipeline: 'foo',
  body: {
    data: 'e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0=',
  },
});

```

It will still generate the same data structure:

```json
{
   // ...,
   "attachment": {
      "content_type": "application/rtf",
      "language": "ro",
      "content": "Lorem ipsum dolor sit amet",
      "content_length": 28
    }
}

```

You can change the default target field name using `target_field`. See [Using the Attachment Processor in a Pipeline | Elasticsearch Plugins and Integrations [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/plugins/current/using-ingest-attachment.html)

---

<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 8, 2021, 11:05am UTC](https://discuss.elastic.co/t/index-pdf-with-ingest-attachement-plugin-using-nodejs-client/288870/5 "2021-12-08T11:05:01Z")

</div>

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