# Problem ingesting PDF

**URL:** <https://discuss.elastic.co/t/problem-ingesting-pdf/196811>\
**Category:** Elasticsearch\
**Created:** [August 26, 2019, 4:40pm UTC](https://discuss.elastic.co/t/problem-ingesting-pdf/196811 "2019-08-26T16:40:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtgajda](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jtgajda](https://discuss.elastic.co/u/jtgajda)\
**Post date:** [August 26, 2019, 4:40pm UTC](https://discuss.elastic.co/t/problem-ingesting-pdf/196811/1 "2019-08-26T16:40:15Z")

</div>

I have installed Elasticsearch 7.3 and am trying to index pdf files using the ingest-attachement plug-in and python to convert the pdf to base64 and the request library to load the data. I am able to successfully create the pipeline. However, when I try to index the PDF, I receive a 500 error and the log file shows an error stating:  
Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes

Following is the code, output, and the relevant log file information.  
Any help would be greatly appreciated, thank you in advance!

**Code:**  
#!/usr/local/bin/python3.7

import sys  
import os  
import json  
import base64  
import requests  
from elasticsearch import Elasticsearch  
es = Elasticsearch()

# open up a pipeline so that documents may be ingested

cpipe = '''  
curl -XPUT "localhost:9200/\_ingest/pipeline/attachment" -H "Content-Type: application/json" -d '  
{  
"description" : "Field for processing file attachments",  
"processors" : [  
{ "attachment" : { "field" : "data", "indexed\_chars" : -1 } }  
]  
}  
'  
'''  
print(cpipe)  
cout = os.popen(cpipe).read()  
print (cout)

file = 'PDFS/880905.pdf'  
print("file = {}".format(file))  
with open(file, "rb") as pdf\_file:  
print(pdf\_file)  
enc\_pdf = base64.b64encode(pdf\_file.read())

putstr = "[http://localhost:9200/cdocs/\_doc/880905?pipeline=attachment](http://localhost:9200/cdocs/_doc/880905?pipeline=attachment)"  
headers = {  
'Content-type': 'application/json'  
}  
print("headers={}".format(headers))  
print("putstr={}".format(putstr))  
response = requests.put(putstr, headers=headers, data=enc\_pdf)  
print(response)

**Output with 500 error:**  
curl -XPUT "localhost:9200/\_ingest/pipeline/attachment" -H "Content-Type: application/json" -d '  
{  
"description" : "Field for processing file attachments",  
"processors" : [  
{  
"attachment" : { "field" : "data", "indexed\_chars" : -1 }  
}  
]  
}  
'

% Total % Received % Xferd Average Speed Time Time Time Current  
Dload Upload Total Spent Left Speed  
100 184 100 21 100 163 723 5618 --:--:-- --:--:-- --:--:-- 5821  
{"acknowledged":true}  
file = PDFS/880905.pdf  
\<\_io.BufferedReader name='PDFS/880905.pdf'\>  
headers={'Content-type': 'application/json'}  
putstr=http://localhost:9200/cdocs/\_doc/880905?pipeline=attachment  
\<Response [500]\>

**Log file snippet:**  
[2019-08-26T10:29:48,416][DEBUG][o.e.a.b.TransportBulkAction] [host-1] failed to execute pipeline [attachment] for document [cdocs/\_doc/868612]  
org.elasticsearch.common.compress.NotXContentException: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes

More log file data:  
[2019-08-26T10:29:48,416][DEBUG][o.e.a.b.TransportBulkAction] [host-1] failed to execute pipeline [attachment] for document [cdocs/\_doc/868612]  
org.elasticsearch.common.compress.NotXContentException: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes  
at org.elasticsearch.common.compress.CompressorFactory.compressor(CompressorFactory.java:56) ~[elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.common.xcontent.XContentHelper.convertToMap(XContentHelper.java:101) ~[elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.action.index.IndexRequest.sourceAsMap(IndexRequest.java:356) ~[elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.ingest.IngestService.innerExecute(IngestService.java:425) ~[elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.ingest.IngestService.access$100(IngestService.java:70) ~[elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.ingest.IngestService$3.doRun(IngestService.java:355) [elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:758) [elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-7.3.0.jar:7.3.0]  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]  
at java.lang.Thread.run(Thread.java:835) [?:?]  
[2019-08-26T10:29:48,417][WARN][r.suppressed] [host-1] path: /cdocs/\_doc/868612, params: {pipeline=attachment, index=cdocs, id=868612}  
org.elasticsearch.common.compress.NotXContentException: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes  
at org.elasticsearch.common.compress.CompressorFactory.compressor(CompressorFactory.java:56) ~[elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.common.xcontent.XContentHelper.convertToMap(XContentHelper.java:101) ~[elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.action.index.IndexRequest.sourceAsMap(IndexRequest.java:356) ~[elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.ingest.IngestService.innerExecute(IngestService.java:425) ~[elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.ingest.IngestService.access$100(IngestService.java:70) ~[elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.ingest.IngestService$3.doRun(IngestService.java:355) [elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:758) [elasticsearch-7.3.0.jar:7.3.0]  
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-7.3.0.jar:7.3.0]  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]  
at java.lang.Thread.run(Thread.java:835) [?:?]

---

<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:** [September 23, 2019, 4:40pm UTC](https://discuss.elastic.co/t/problem-ingesting-pdf/196811/2 "2019-09-23T16:40:21Z")

</div>

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