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-certificates2. 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 EEA14886Add java repository:
$ echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu zesty main" | sudo tee -a /etc/apt/sources.list.d/java-8-debian.listUpdate apt database:
$ sudo apt-get updateInstalling java
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installerWhen asked accept the “Oracle Binary Code” license.
Set Oracle JDK8 as default:
$ sudo apt install oracle-java8-set-defaultCheck java version:
$ java -versionoutput:
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.listInstall elasticsearch package
$ sudo apt update
$ sudo apt install elasticsearchEnable elasticsearch service
$ sudo systemctl daemon-reload
$ sudo systemctl enable elasticsearch
$ sudo systemctl start elasticsearchInstall elasticsearch ingest-attachment plugin
$ sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install ingest-attachmentWhen 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.ymlInside 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.
Restart elasticsearch:
$ sudo systemctl start elasticsearchCheck 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:indexERRORS & SOLUTIONS:
indexing.
[OCAFullTextSearch_ElasticSearchExceptionsConfigurationException]
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-attachmentIt 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:indexReferences
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.