How to install full text search with elastic search on Nextcloud 13 on a Debian 9 system.

0. Install https support for apt

apt install apt-transport-https ca-certificates

1. Install Java

Install java 8 installer from ubuntu launchpad.

Add java repository

Import Ubuntu GPG key:

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886

Add java repository:

echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu zesty main" | sudo tee -a /etc/apt/sources.list.d/java-8-debian.list

Update apt database:

apt update

Install java

apt update && sudo apt install oracle-java8-installer

When asked accept the “Oracle Binary Code” license.

Set Oracle JDK8 as default:

apt install oracle-java8-set-default

Check java version:

$ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

2. Install elasticsearch

Install Elasticsearch from elastic.co.

Add elasticsearch repository

Import elasticsearch GPG key:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

Add elasticsearch repository:

echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list

Install elasticsearch package

apt update && sudo apt install elasticsearch

Enable elasticsearch service

systemctl daemon-reload
systemctl enable elasticsearch
systemctl start elasticsearch

Install elasticsearch ingest-attachment plugin

/usr/share/elasticsearch/bin/elasticsearch-plugin install ingest-attachment

Bind elasticsearch to localhost only:

To force elasticsearch to listen only on localhost edit the file /etc/elasticsearch/elasticsearch.yml and set network.host to 127.0.0.1:

# File: /etc/elasticsearch/elasticsearch.yml
# [...]
# ------------------------------ Network -------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: 127.0.0.1
# [...]

Restart elasticsearch:

systemctl restart elasticsearch

Check if elasticsearch is running

curl -XGET 'localhost:9200/?pretty'
{
  "name" : "6nUMzto",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "ChcVg"HEzSTtqKJSGMbVhuI,
  "version" : {
    "number" : "6.2.0",
    "build_hash" : "37cdac1",
    "build_date" : "2018-02-01T17:31:12.527918Z",
    "build_snapshot" : false,
    "lucene_version" : "7.2.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

3. Nextcloud configuration

Install full text search apps:

Config Full text search on Nextcloud

Navigate to Settings -> Full text search and set:

  • Full text search ->Search Platform to Elasticsearch
  • Elastic Search -> Address of the Servlet to http://localhost:9200
  • Elastic Search -> Index to nextcloud

Run first index:

This may take a while:

sudo -u www-data php /var/www/nextcloud/occ fulltextsearch:index

Enjoy your new Nextcloud search engine :-)

References