How To Install Full Text Search Using Elastic Search And Nextcloud

We also install Java from ubuntu launchpad which is much easier than installing java manually

1. Install https support for apt

$ sudo apt install apt-transport-https ca-certificates

2. Install Java

Install java 8 installer from ubuntu launchpad. Add java repository

Import Ubuntu GPG key:

$ sudo 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:

$ sudo apt-get update

Installing java

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

When asked accept the “Oracle Binary Code” license.

Set Oracle JDK8 as default:

$ sudo apt install oracle-java8-set-default

Check java version:

$ java -version

output:

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)

3. Install elasticsearch

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

$ sudo apt update
$ sudo apt install elasticsearch

Enable elasticsearch service

$ sudo systemctl daemon-reload
$ sudo systemctl enable elasticsearch
$ sudo systemctl start elasticsearch

Install elasticsearch ingest-attachment plugin

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

When asked to “Continue with installation”, enter ‘y’

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:

$ sudo nano /etc/elasticsearch/elasticsearch.yml

Inside the ‘Network’ section, delete the ‘#’ to uncomment the lines that starts with ‘cluster.name’, ‘node.name’ and ‘network.host’, and assign a custom name for each. For ‘network.host’, change the ip from 192.168.0.1 to 127.0.0.1 as shown below:

# [...]
# ---------------------------------- Cluster ------------------------------$
#
# Use a descriptive name for your cluster:
#
cluster.name: nextcloud
#
# ------------------------------------ Node -------------------------------$
#
# Use a descriptive name for the node:
#
node.name: home.lan-1
#

...

# ------------------------------ Network -------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 127.0.0.1
# [...]

The first variables to customize on any Elasticsearch server are node.name and cluster.name in elasticsearch.yml. As their names suggest, node.name specifies the name of the server (node) and the cluster to which the latter is associated.

If you don’t customize these variable, a node.name will be assigned automatically in respect to the Droplet hostname. The cluster.name will be automatically set to the name of the default cluster.

The cluster.name value is used by the auto-discovery feature of Elasticsearch to automatically discover and associate Elasticsearch nodes to a cluster. Thus, if you don’t change the default value, you might have unwanted nodes, found on the same network, in your cluster.

These the minimum settings you can start with using Elasticsearch. However, it’s recommended to continue reading the configuration part for more thorough understanding and fine-tuning of Elasticsearch.

More info: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsearch-on-ubuntu-16-04

Restart elasticsearch:

$ sudo systemctl start elasticsearch

Check if elasticsearch is running

curl -XGET 'localhost:9200/?pretty'

You should see output similar to below:

{
  "name" : "JTa9iro",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "jHEFy-V5Qgq8_V0FArNDcA",
  "version" : {
    "number" : "6.2.1",
    "build_hash" : "7299dc3",
    "build_date" : "2018-02-07T19:34:26.990113Z",
    "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"
}

4. Nextcloud configuration

Install full text search apps:

Full text search – Elasticsearch Platform (BETA) Full text search (BETA) Full text search – Files (BETA)

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/html/nextcloud/occ fulltextsearch:index

ERRORS & SOLUTIONS:

indexing.


  [OCA\FullTextSearch_ElasticSearch\Exceptions\ConfigurationException]
  please add ingest-attachment plugin to elasticsearch


fulltextsearch:index [--output [OUTPUT]]

1. I tried to re-install the ingest-attachment plugin:

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

It returned another error stating that the plugin was already installled. So I just re-ran the first index again and the indexing started:

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

References

https://fribeiro.org/tech/2018/02/07/nextcloud-full-text-elasticsearch/
How to Install JAVA 8 (JDK/JRE 8u111) on Debian 8 & 7 via PPA
Install Elasticsearch with Debian Package

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.