If you landed here is that you probably have a keen interest in bringing a more powerful search engine into your WordPress site and you have heard about Elasticsearch, the relatively new document oriented, RESTful search server based on Lucene.

There are many reasons why one uses Elasticsearch so I won’t get into much details, I will only show you the steps to get up and running¬†with WordPress + Elasticsearch on your VPS server running ubuntu (or whatever linux distro you prefer but I will only show ubuntu commands)*.

Here we go!

Step 1: Install Java and Elasticsearch (and you thought you could get rid of Java didn’t you?)

# Install on ubuntu trusty tahr 14.04
# I do this with root user, but if you sudo access with your user it will work too!
sudo su
# Update apt-get 
apt-get update
# Install java jdk 7 or java jdk 8 or oracle jdk
apt-get install openjdk-7-jre-headless
# Make sure java is installed
java -version
# This should output: java version "1.7.XX"

# Navigate to the installation folder you want (for me /opt/)
cd /opt/
# Download elasticsearch and untar
wget -qO- https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.2.tar.gz | tar xvz

# In /opt/elasticsearch-1.4.2.tar.gz/config/elasticsearch.yml
# Uncomment and change those lines to the following: 
# network.host: localhost
# cluster.name: YOUR-CLUSTER-NAME

# Start elasticsearch in the background (reference here for those who wants a service http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-service.html)
/opt/elasticsearch-1.4.2/bin/elasticsearch -d
# Check if the server is running
curl -XGET http://localhost:9200
# Sample output: 
#{
#  "status" : 200,
#  "name" : "Nicholas Scratch",
#  "cluster_name" : "elasticsearch",
#  "version" : {
#    "number" : "1.4.2",
#    "build_hash" : "927caff6f05403e936c20bf4529f144f0c89fd8c",
#    "build_timestamp" : "2014-12-16T14:11:12Z",
#    "build_snapshot" : false,
#    "lucene_version" : "4.10.2"
#  },
#  "tagline" : "You Know, for Search"
#}

# DONE!

Step 2: Install Elasticpress and start the index process.

# Download from wordpress.org repository into your plugins folder
# https://wordpress.org/plugins/elasticpress/
# Make sure you have wp-cli installed (otherwise it won't work) http://wp-cli.org/

# Add config line to wp-config.php:
# define( 'EP_HOST', 'http://127.0.0.1:9200' );

# In your docroot (WordPress root folder) 
wp plugin activate elasticpress --network

# Start the indexation process
wp elasticpress index --setup

# All done (everytime a post is updated, the index will be refreshed)!

Step 3: Relax. The search just got a thousand time better!

 

* You can do this on Windows if you really like the trouble. It’s up to you really.

 

PSSST! Leave a comment if you are interesting in searching non published posts in the WordPress admin.