# Elasticsearch - attachment using Ingest - with node.js

**URL:** <https://discuss.elastic.co/t/elasticsearch-attachment-using-ingest-with-node-js/86680>\
**Category:** Elasticsearch\
**Created:** [May 22, 2017, 2:07pm UTC](https://discuss.elastic.co/t/elasticsearch-attachment-using-ingest-with-node-js/86680 "2017-05-22T14:07:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjans](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@anjans](https://discuss.elastic.co/u/anjans)\
**Post date:** [May 22, 2017, 2:07pm UTC](https://discuss.elastic.co/t/elasticsearch-attachment-using-ingest-with-node-js/86680/1 "2017-05-22T14:07:35Z")

</div>

Hi,  
Facing problem to index a pdf document using elasticsearch Ingest plugin.

I have done the following,

1. Created the pipline -  
PUT \_ingest/pipeline/attachment  
{  
"description" : "Extract attachment information",  
"processors" : [  
{  
"attachment" : {  
"field" : "data"  
}  
}  
]  
}

2. Created my index reading pdf file and inserted in to the created pipeline.

function indexfile(tUrl)  
{  
return new Promise(function (resolve, reject) {  
request(tUrl, function(error, response, body){  
if(!error){   
let arr = new Buffer(body, 'binary').toString('base64');  
insertDocIngest(base64.encode(arr));   
}else{  
console.log(body);  
reject(error);  
}  
});  
});  
}

function insertDocIngest(fileData){  
esClient.index({index:'repo\_index', type:'rec\_type', id:'13', pipeline:'attachment',  
body:{  
"data": fileData  
}  
})  
.then(response =\> {  
console.log('Successfully created the index');  
})  
.catch(error =\> {  
console.log(error.message);  
});  
}

indexfile('[http://www.cbu.edu.zm/downloads/pdf-sample.pdf](http://www.cbu.edu.zm/downloads/pdf-sample.pdf)');

1. It can create the index successfully, but while I ty to search the document, as  
function search(query, index\_val){  
return esClient.search({  
q: query,  
index: index\_val  
}).catch(error =\> {  
console.log(error.message);  
});  
}

function test()  
{  
let index = 'repo\_index';  
let query = 'always';  
search(query, index)  
.then(results =\> {  
console.log(`found ${results.hits.total} items in ${results.took}ms`);  
})  
.catch(console.error);  
}

test();

I am not able to find the document.

I know I am missing something, could anyone help me in this?

Thanks in advance,  
Anjan

---

<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 24, 2017, 12:35pm UTC](https://discuss.elastic.co/t/elasticsearch-attachment-using-ingest-with-node-js/86680/2 "2017-05-24T12:35:11Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

What does a document that you indexed is looking like?  
I mean if you do a `GET indexname/typename/id`?

---

<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 21, 2017, 12:40pm UTC](https://discuss.elastic.co/t/elasticsearch-attachment-using-ingest-with-node-js/86680/3 "2017-06-21T12:40:26Z")

</div>

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