---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://mixpeek.com/.well-known/search?q={query}"
  method: GET
  documentation: "https://mixpeek.com/llms.txt"
---

What is Mixpeek?

[Back to Blog](/blog)

[](https://twitter.com/intent/tweet?text=Searching%20PDFs%20in%20S3%20Using%20OpenSearch%20and%20Tika&url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fcreating-a-searchable-pdf-repository)[](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fcreating-a-searchable-pdf-repository&title=Searching%20PDFs%20in%20S3%20Using%20OpenSearch%20and%20Tika)[](https://www.reddit.com/submit?url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fcreating-a-searchable-pdf-repository&title=Searching%20PDFs%20in%20S3%20Using%20OpenSearch%20and%20Tika)

This was originally in our newsletter.

Get Updates

Jan 6, 2023•3 min read

# Searching PDFs in S3 Using OpenSearch and Tika

In this tutorial, we walked through the process of building a Python script that is able to search the contents of PDF files in an Amazon S3 bucket using Apache Tika and OpenSearch.

![Searching PDFs in S3 Using OpenSearch and Tika](https://blog.mixpeek.com/content/images/2025/04/ChatGPT-Image-Apr-13--2025--08_05_04-AM.png)

Tutorials

TABLE OF CONTENTS

## Introduction

In this tutorial, we will be walking through the process of building a simple Python script that is able to search the contents of PDF files in an Amazon S3 bucket using Apache Tika and OpenSearch. Apache Tika is a library for extracting text and metadata from various types of documents, including PDF files. OpenSearch is a search server that is able to index and search document contents using Tika.

## Prerequisites

Before we begin, make sure that you have the following prerequisites:

*   An AWS account and credentials with access to an S3 bucket.
*   Apache Tika and OpenSearch installed on your system. You can download the latest version of Tika from the Apache Tika website, and the latest version of OpenSearch from the OpenSearch GitHub page.
*   The `boto3` and `requests` libraries installed on your system. You can install these libraries using `pip install boto3 requests`.

## **Your S3 Bucket is a Black Box**

If your S3 bucket is anything like mine, it contains so many different file types. Text, pictures, audio clips, videos, the list goes on.

How are we supposed to find anything in this mess of files?

To solve this, we're going to build a pipeline for extracting the text from an example binary file: PDFs using OCR. Then we'll store it in a search engine via AWS OpenSearch and finally we'll build a REST API in [Flask](https://flask.palletsprojects.com/en/2.2.x/?ref=blog.mixpeek.com) to "explore" our S3 bucket.

### **Here's what our pipeline will look like:**

![Generated image](https://sdmntpreastus2.oaiusercontent.com/files/00000000-ac9c-61f6-ba48-e217ac4623d1/raw?se=2025-04-13T12%3A57%3A57Z&sp=r&sv=2024-08-04&sr=b&scid=d96ed7df-d621-56db-a3dd-4c09b88f8fbb&skoid=a47cd303-16a2-427e-8efb-2ce406116005&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2025-04-13T11%3A31%3A42Z&ske=2025-04-14T11%3A31%3A42Z&sks=b&skv=2024-08-04&sig=6HeVx6eUn7kRZwB06lUHJs4b4RtyMiJo5pLPiCiHgfk%3D)

**Bonus:** Skip this walkthrough and just download the [code here](https://github.com/mixpeek/pdf-search-s3?ref=blog.mixpeek.com).

## **Retrieve the File from your S3 Bucket**

First we need to download the file locally so we can run our text extraction logic.

```python
import boto3

s3_client = boto3.client(
    's3',
    aws_access_key_id='aws_access_key_id',
    aws_secret_access_key='aws_secret_access_key',
    region_name='region_name'
)
with open(s3_file_name, 'wb') as file:
    s3_client.download_fileobj(
        bucket_name,
        s3_file_name,
        file
    )   
```

## **Use OCR to Extract the Contents**

We’ll use the open source, Apache Tika library, which contains a class: AutoDetectParser that does OCR (optical character recognition):

## Run this on your own content

Point Mixpeek at the storage you already have and search your video, images, audio, and documents the way this post describes. Build starts at $25/mo for up to 1M vectors.

[Search your own files](https://studio.mixpeek.com/namespaces/create?mode=managed&utm_source=homepage&utm_medium=blog_onramp_mid&utm_campaign=mvs_onramp)[Talk to us](/demo)

```python
from tika import parser

parsed_pdf_content = parser.from_file(s3_file_name)['content']
```

## **Insert the Contents into AWS OpenSearch**

We’re using a self-managed OpenSearch node here, but you can use Lucene, SOLR, ElasticSearch or Atlas Search.

_Note: if you don’t have OpenSearch locally you must install it first, then run it:_

```shell
brew update
brew install opensearch
opensearch
```

OpenSearch will now be accessible here: `http://localhost:9200` Let’s build the index and insert the file contents:

```python
from opensearchpy import OpenSearch

os = OpenSearch("http://localhost:9200")
index_name="pdf-search"

doc = {
    "filename": s3_file_name,
    "parsed_pdf_content": parsed_pdf_content
}

response = os.index(
    index=index_name,
    body=doc,
    id=1,
    refresh=True
)                        
```

## **Building the Search API**

```python
from flask import Flask, jsonify, request
from opensearchpy import OpenSearch

app = Flask(__name__)
os = OpenSearch("http://localhost:9200/")

@app.route('/search', methods=['GET'])
def search_file():
    # value from the api
    query = request.args.get('q', default = None, type = str)
    # query payload in json forOpenSearch
    payload = {
        'query': {
            'match': {
                'parsed_pdf_content': query
            }
        }
    }
    # run search query
    response = os.search(
        body=payload,
        index=index_name
    )
    return jsonify(response)

if __name__ == '__main__':
    app.run(host="localhost", port=5011, debug=True)
```

You can download the repo here: [https://github.com/mixpeek/pdf-search-s3](https://github.com/mixpeek/pdf-search-s3?ref=blog.mixpeek.com)

### **The easy part is done, now you need to figure out:**

*   **Queuing**: Ensuring concurrent file uploads are not dropped
*   **Security**: Adding end to end encryption to the data pipeline
*   **Enhancements**: Including more features like fuzzy, highlighting and autocomplete
*   **Rate Limiting**: Building thresholds so users don’t abuse the system

## **All This in Two Lines of Code**

```python
from mixpeek import Mixpeek

# init mixpeek class with S3 connection
mix = Mixpeek(
    api_key="mixpeek_api_key",
    access_key="aws_access_key",
    secret_key="aws_secret_key",
    region="region"
)

# index our entire S3 bucket's files
mix.index_bucket("mixpeek-public-demo")    

# full text search across S3 bucket
mix.search("system")
```

[ES

Ethan Steininger

Former lead of MongoDB's Search Team, Ethan noticed the most common problem customers faced was building indexing and search infrastructure on their S3 buckets. Mixpeek was born.



](/blog/authors/ethan)

## Run this on your own content

Point Mixpeek at the storage you already have and search your video, images, audio, and documents the way this post describes. Build starts at $25/mo for up to 1M vectors.

[Search your own files](https://studio.mixpeek.com/namespaces/create?mode=managed&utm_source=homepage&utm_medium=blog_onramp_end&utm_campaign=mvs_onramp)[Talk to us](/demo)

## Continue Learning

[

![AI Video Analysis for Sports: Build Automated Highlight Reels, Archive Search, and Performance Analytics](https://blog.mixpeek.com/content/images/2026/03/sports-blog-hero.jpg)

### AI Video Analysis for Sports: Build Automated Highlight Reels, Archive Search, and Performance Analytics

Sports broadcasters cut 4-8 hour editing sessions to 15 minutes using AI video analysis. Learn how to build automated highlight detection, archive search, and performance analytics pipelines for any sport.

Read More





](/blog/ai-video-analysis-sports)[

![How to Build a Multimodal Search Engine in 2025](https://mixpeek.com/og-image.png)

### How to Build a Multimodal Search Engine in 2025

A practical guide to building search that works across text, images, video, and audio using shared embedding spaces and retrieval pipelines.

Read More





](/blog/how-to-build-multimodal-search-engine)

### Author

ES

Ethan Steininger

![Mixpeek Icon](/brand/logo-dark-icon.webp)

#### Multimodal Search, On Demand

Index, retrieve, and reason over videos, images, audio, and docs, all from a single API.

[Start Building](/start)

### Share

[](https://twitter.com/intent/tweet?text=Searching%20PDFs%20in%20S3%20Using%20OpenSearch%20and%20Tika&url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fcreating-a-searchable-pdf-repository)[](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fcreating-a-searchable-pdf-repository&title=Searching%20PDFs%20in%20S3%20Using%20OpenSearch%20and%20Tika)[](https://www.reddit.com/submit?url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fcreating-a-searchable-pdf-repository&title=Searching%20PDFs%20in%20S3%20Using%20OpenSearch%20and%20Tika)