Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Say hello to redesigned Cloudways, an empowering Startup Program, enhanced Staging, a new Let’s Encrypt Wildcard SSL certificate feature, and more. READ MORE

Elasticsearch is now available on Cloudways

Updated on October 13, 2015

3 Min Read
Reading Time: 3 minutes

Cloudways recently added one of the most famous Search and Analytics engine, Elasticsearch. It’s written in Java and comes with the awesome RESTful API.

elastic-search

The Cloudways Platform offers 1-click installation and configuration of ElasticSearch for its Agile fans. Developers can now quickly deploy and test Elasticsearch based backends and web services, along with managing important configurations of Elasticsearch from the console (like memory allocation) at the ease of a click.

There are lots of businesses using Elasticsearch for their varying big data and search needs. Content companies, like Deezer, SoundCloud and The Guardian use Elasticsearch to make feature-rich search systems. Here you will find many interesting use cases of Elasticsearch.

In Elasticsearch, we have Cluster which may contain one or multiple Nodes. (To know more, here is a comprehensive Glossary for ElasticSearch.) The current Default configuration of Cloudways supports 1 Cluster with 1 Node.

Just like we have Databases and Tables in MySQL, we have Indexes and Types in Elasticsearch.

MySQL ⇒ Databases ⇒ Tables ⇒ Columns/Rows
Elasticsearch ⇒ Indices ⇒ Types ⇒ Documents with Properties

Data in Index is stored in the form of Primary Shards and Replica Shards. When creating an index, you define how many Primary shards this index will use. By default, they are 5. So, on the Cloudways Platform when you create an index, it will be distributed on 5 shards on the same node.

Since we are not using multiple nodes, replica shards will not be created with Cloudways.

Here is a nice walk through of PHP API for ElasticSearch. Using that you can expose a web service or API to collect data into ElasticSearch from multiple external resources. We have tested it on the Cloudways Platform and they work perfectly fine.

Let’s look at an example on how simply you can stash your data into elasticsearch, and then retrieve it. This is a little program on python which gives you a little overview, just make sure you have ElasticSearch installed and enabled on your Cloudways Platform.
First install a simple php app on your Cloudways server and use pip to meet your dependencies inside your application folder:

$pip install --target=/mnt/data/home/master/applications/<your_app_folder>/public_html elasticsearch

$pip install --target=/mnt/data/home/master/applications/<your_app_folder>/public_html PySocks

Now create a simple python application name it Elastic_python.py and let’s play with it a little bit.
from datetime import datetime

#pulling elasticsearch library
from elasticsearch import Elasticsearch
es = Elasticsearch()

#preparing the object to stash
doc = {
'author': 'J. R. R. Tolkien',
'text': 'Not all those who wander are lost',
'timestamp': datetime.now(),
}

#preparing indexes
res = es.index(index="quote-index", doc_type='tweet', id=1, body=doc)
print(res['created'])

res = es.get(index="quote-index", doc_type='tweet', id=1)
print(res['_source'])

es.indices.refresh(index="quote-index")

#fetching results
res = es.search(index="quote-index", body={"query": {"match_all": {}}})
print("Got %d Hits:" % res['hits']['total'])
for hit in res['hits']['hits']:
print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])

There you go, a pretty outcome of your stashed results:

Share your opinion in the comment section. COMMENT NOW

Aaqib Gadit

As Co-founder and Director of Cloudways, Aaqib is responsible for the services portfolio, strategic planning, product and business development.

Start Creating Web Apps on Managed Cloud Servers Now

Easy Web App Deployment for Agencies, Developers and E-Commerce Industry.

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

THERE’S MORE TO READ.