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/


Hosting

This web app has been tested on DigitalOcean. This app can also be installed using other hosts such as Amazon AWS, Google Cloud, Microsoft Azure, Vultr and others.

Installation & Maintenance

If you would like to get this app installed, maintained or need training, Contact Me to get current rates.

10 thoughts on “How To Install Full Text Search Using Elastic Search And Nextcloud

  1. >> sudo -u www-data php /var/www/html/nextcloud/occ fulltextsearch:index

    Reply is

    There are no commands defined in the “fulltextsearch” namespace.

    Installation was done via *.deb für Ubuntu 18.04 LTS headless.

    Any hint?

    1. Hello, It’s been a while since I first wrote this but the install of Full Text Search doesn’t appear to have changed much. I’m not sure what you mean by “no commands defined” as you referenced the command ending with “occ fulltextsearch:index” to initiate/run the first index. I can only reference the official github repo https://github.com/nextcloud/fulltextsearch/issues but I’m sure you’ve been there too. Good luck!

    2. >> sudo -u www-data php /var/www/html/nextcloud/occ fulltextsearch:index
      You have to modify the path of your installation after php in my case I have to modify it like this:
      >> sudo -u www-data php /var/www/nextcloud/occ fulltextsearch:index
      that’s because I don’t used the html folder

    1. I believe the instructions above should be enough to get Elastic Search and Nextcloud working together. I also believe that it depends on how much information/users you have in Nextcloud that will determine if you really need Elastic Search installed or not. For a “smaller” number of files, Elastic Search is not necessary at all as the default search functionality will do.

  2. Hi, does ElasticSearch fully replaces the Nextcloud Search? Technically speaking and to be specific, does it offload the database of search queries?

    Also, you don’t tak about ‘occ fulltextsearch:live’, is this necesary?

    Thanks.

    1. ElasticSearch is used to extend the core Nextcloud fulltextsearch app. ElasticSearch will index all of your files when first installed using `./occ fulltextsearch:index` (or `sudo -u www-data php ./occ fulltextsearch:index`). ElasticSearch indexes the contents of files so it is a lot more powerful than the core fulltextsearch app which does not. `occ fulltextsearch:live` can be used if you don’t want to wait for the cron to run – so it is not really necessary but useful. You can find info on this command and the rest here: https://github.com/nextcloud/fulltextsearch/wiki/Commands and https://github.com/nextcloud/fulltextsearch/wiki/Basic-Installation

  3. Any suggestion how to set up fulltext search on nextcloud 23.0 with elastic 8?
    Elastic now has security enabled, with certs and https.

    Seems I cannot get fulltextsearch to find elastic.

Leave a Reply to Emanuele Cancel 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.