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.

📣 Try the fastest hosting platform with pay-as-you-go pricing & 24/7 expert support! MIGRATE NOW →

Elasticsearch is now available on Cloudways

Updated on February 15, 2018

3 Min Read

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

Share This Article

Aaqib Gadit

Aaqib Gadit is the Co-founder and CEO of Cloudways, a multi-cloud managed application hosting platform for SMBs to save them time and money and allow them to grow their business with peace of mind and improved productivity without worrying about infra and application management hassles. He is a hands-on, execution-oriented leader and a serial entrepreneur with expertise in product, growth, tech, customer support, and customer success, particularly in the context of SaaS, Infrastructure, and Open Source where he founded multiple companies since 2008.

×

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

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now