# Read text from pdf file

**URL:** <https://discuss.elastic.co/t/read-text-from-pdf-file/266530>\
**Category:** Elasticsearch\
**Created:** [March 8, 2021, 10:14am UTC](https://discuss.elastic.co/t/read-text-from-pdf-file/266530 "2021-03-08T10:14:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arefin](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@arefin](https://discuss.elastic.co/u/arefin)\
**Post date:** [March 8, 2021, 10:14am UTC](https://discuss.elastic.co/t/read-text-from-pdf-file/266530/1 "2021-03-08T10:14:00Z")

</div>

```
String filePath = "C://x.pdf";
	String encodedfile = null;
	RestHighLevelClient restHighLevelClient = null;
	File file = new File(filePath);
	try
	{
		FileInputStream fileInputStreamReader = new FileInputStream(file);
		byte[] bytes = new byte[(int) file.length()];
		fileInputStreamReader.read(bytes);
		encodedfile = new String(Base64.getEncoder().encodeToString(bytes));
	}
	catch (IOException e)
	{
	}
	try
	{
		restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));
	}
	catch (Exception e)
	{
	}

	Map<String, Object> jsonMap = new HashMap<>();
	jsonMap.put("Name", "samanvi");
	jsonMap.put("postDate", new Date());
	jsonMap.put("hra", encodedfile);
	IndexRequest request = new IndexRequest("index", "_doc", "56")
			.index("index")
			.source("field", jsonMap);
	try
	{
		IndexResponse response = restHighLevelClient.index(request, RequestOptions.DEFAULT);
	}
	catch (ElasticsearchException | IOException e)
	{
	}

```

'I am indexing file this way, now I want to read text from this pdf file, can anyone please describe how could i read text by elasticsearch query.'

---

<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 8, 2021, 10:16am UTC](https://discuss.elastic.co/t/read-text-from-pdf-file/266530/2 "2021-03-08T10:16:00Z")

</div>

This is not going to work unless you use the ingest attachment plugin to extract the text from your file.

See: [Ingest Attachment Processor Plugin | Elasticsearch Plugins and Integrations [7.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/plugins/current/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:** [April 5, 2021, 10:16am UTC](https://discuss.elastic.co/t/read-text-from-pdf-file/266530/3 "2021-04-05T10:16:01Z")

</div>

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