Setting Up Nextcloud Fulltext Search With Elasticsearch

In this post, we will be setting up Fulltext Search on Nextcloud using nextcloud-aio container and Elasticsearch. For the purpose of this guide, we will be avoiding the use of the container mentioned in the official Nextcloud documentation as it executes processes as root, which is not ideal for many circumstances.


1. Edit your Docker Compose file with the following configurations for nextcloud-aio container:

image: nextcloud/aio-fulltextsearch:latest
  - ES_JAVA_OPTS=-Xms512M -Xmx512M
  - bootstrap.memory_lock=true
  - discovery.type=single-node
  - http.port=9200
  - xpack.license.self_generated.type=basic
  - ./aio_elasticsearch:/usr/share/elasticsearch/data:rw
restart: unless-stopped
      cpus: '6'
      memory: 8192m

This configuration provides an Elasticsearch platform to run the Fulltext Search in your Nextcloud instance.
The deploy block is just good practice; I was certainly overly generous here :D and you shall decide how much resources you’d like to allocate based on your host or VM config.

2. Create the required folders:

mkdir aio_elasticsearch
chown 1000:0 aio_elasticsearch

This will create a directory for your Elasticsearch data.

3. Run the modified Compose file:

docker compose up -d


CONTAINER ID   NAME                                CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O     PIDS
3d0ae49ee0d5   nextcloud-app-1                     8.23%     172MiB / 8GiB         2.10%     62.1MB / 9.34MB   0B / 0B       11
48e7c3b00ae8   nextcloud-redis-1                   0.59%     4.516MiB / 8GiB       0.06%     5.48MB / 34.1MB   0B / 0B       5
acf8cdf7147d   nextcloud-aio-fulltextsearch-1      0.39%     909.6MiB / 8GiB       11.10%    1.46kB / 0B       0B / 0B       83
12fa5273a92d   nextcloud-db-1                      0.64%     91.67MiB / 8GiB       1.12%     3.08MB / 27.4MB   0B / 0B       7

Now your nextcloud-aio container should take approximately 1GB of RAM while idle.

4. Install the necessary Nextcloud apps:

5. Enter your Elasticsearch server settings in Nextcloud’s Fulltext Search settings in the Admin area.

  • Search platform: http://aio-fulltextsearch:9200
  • Address of the Servlet: http://aio-fulltextsearch:9200

Link to screenshot

6. Test your set-up.

After installation and configuration of the necessary apps, we need to test if our setup works correctly. We can use Nextcloud’s OCC command line tool to do this.
If everything is set up correctly, you should see a series of ‘ok’ messages, and your files should now be indexed and searchable through Nextcloud’s Fulltext Search feature.

> $ docker exec -it -u 33 nextcloud-app-1 php occ fulltextsearch:check
Full text search 27.0.1
- Search Platform:
Elasticsearch 27.0.2 (Selected)
    "elastic_host": [
    "elastic_index": "nextcloud-index",
    "fields_limit": "10000",
    "es_ver_below66": "0",
    "analyzer_tokenizer": "standard"

- Content Providers:
Deck 1.10.0
Files 27.0.1
    "files_local": "1",
    "files_external": "0",
    "files_group_folders": "0",
    "files_encrypted": "0",
    "files_federated": "0",
    "files_size": "20",
    "files_pdf": "1",
    "files_office": "1",
    "files_image": "0",
    "files_audio": "0",
    "files_chunk_size": "2"

And more importantly:

> $ docker exec -it -u 33 nextcloud-app-1 php occ fulltextsearch:test                                                                                           
.Testing your current setup:  
Creating mocked content provider. ok  
Testing mocked provider: get indexable documents. (2 items) ok  
Loading search platform. (Elasticsearch) ok  
Testing search platform. ok  
Locking process ok  
Removing test. ok  
Pausing 3 seconds 1 2 3 ok  
Initializing index mapping. ok  
Indexing generated documents. ok  
Pausing 3 seconds 1 2 3 ok  
Retreiving content from a big index (license). (size: 32386) ok  
Comparing document with source. ok  
Searching basic keywords:  
 - 'test' (result: 1, expected: ["simple"]) ok  
 - 'document is a simple test' (result: 2, expected: ["simple","license"]) ok  
 - '"document is a test"' (result: 0, expected: []) ok  
 - '"document is a simple test"' (result: 1, expected: ["simple"]) ok  
 - 'document is a simple -test' (result: 1, expected: ["license"]) ok  
 - 'document is a simple +test' (result: 1, expected: ["simple"]) ok  
 - '-document is a simple test' (result: 0, expected: []) ok  
 - 'document is a simple +test +testing' (result: 1, expected: ["simple"]) ok  
 - 'document is a simple +test -testing' (result: 0, expected: []) ok  
 - 'document is a +simple -test -testing' (result: 0, expected: []) ok  
 - '+document is a simple -test -testing' (result: 1, expected: ["license"]) ok  
 - 'document is a +simple -license +testing' (result: 1, expected: ["simple"]) ok  
Updating documents access. ok  
Pausing 3 seconds 1 2 3 ok  
Searching with group access rights:  
 - 'license' - [] -  (result: 0, expected: []) ok  
 - 'license' - ["group_1"] -  (result: 1, expected: ["license"]) ok  
 - 'license' - ["group_1","group_2"] -  (result: 1, expected: ["license"]) ok  
 - 'license' - ["group_3","group_2"] -  (result: 1, expected: ["license"]) ok  
 - 'license' - ["group_3"] -  (result: 0, expected: []) ok  
Searching with share rights:  
 - 'license' - notuser -  (result: 0, expected: []) ok  
 - 'license' - user2 -  (result: 1, expected: ["license"]) ok  
 - 'license' - user3 -  (result: 1, expected: ["license"]) ok  
Removing test. ok  
Unlocking process ok

7. Index your files.

Lastly, if you’re coming from a NC version anterior to NC 24, you will need to run fulltextsearch:migration:24 before executing the index command:

docker exec -it -u 33 nextcloud-app-1 php occ fulltextsearch:migration:24
docker exec -it -u 33 nextcloud-app-1 php occ fulltextsearch:index


You can now enjoy near-instant, effective text searching in Nextcloud with Elasticsearch powering the Fulltext Search feature!