In this presentation I will show you how to setup Laravel and Elasticsearch to quickly build a search engine. This was given at a local meetup in Groningen (Netherlands).
3. What I am about to cover
• Benefits of ElasticSearch
• ElasticSearch Basics
• Examples of Searchengines
• Installing the tools
• Analyzing and feeding the data
• Searching with Laravel and ElasticSearch through VueJS
4. What I do NOT cover
• Type of queries
• Analyzers
• Filters
• Percolator
• Internals of Elasticsearch (Lucene Index)
• Talk of Elze Kool - GroningenPHP
https://bitbucket.org/elzekool/talk-solr-elasticsearch-internals/src
The internals will cover how a score is determined in the background.
6. What is a “powerful search”?
• Fast
Search in milliseconds, not in seconds.
• Relevant
If you search for a Hotel in California, don’t return Hotels in
Groningen. Or a black Audi, you don’t want to see a white Peugeot
107.
• Scalable
If your data grows, then you need more resources. It could mean by
vertical scaling or (better) horizontal scaling of capacity.
7. MySQL Drawbacks for searching through text
• LIKE %%
• Fast? No, try searching for millions of records with multiple joins to combine
all the information needed.
• Relevant? No, Try search for “PHP programmeur” or “PHP developer”, or
“Audi A8 zwart” or “zwarte Audi A8“.
• Scalable? Could be, but with much hassle in configurations in production and
backing up.
• Facets / Counts – How many Audi’s? How many black cars? Takes
multiple query’s for the calculation of those counts.
NB: FULL TEXT not noted here, gave a bit better result but not great.
10. Usage of the Elastic stack
• Time-series data
Log files, searched queries, view count of document
• Insights in your data
• Machine-Learning capabilities
• Reversal of search queries with percolator (storing search queries)
• Zero-downtime* index swapping
Last 7 days, Last 30 days, or products => products-20180327
11. Components of ElasticSearch
• Node
Instance of ElasticSearch.
• Cluster
One or more nodes that work together to serve the same data and
API requests.
• Document
A piece of stored data you want to search for. (MySQL Row)
• Index
A collection of documents that have somewhat similar characteristics.
(MySQL Table)
21. First up: installation of the following tools
• MySQL (ElasticSearch does not support transactions!)
• ElasticSearch
• Laravel
• VueJS / VueX
22. Setting up / Starting MySQL on OSX
• Default credentials
User: root
Password: <empty>
Port: 3301
> Now create a Database called “coolshop”
23. Installing laravel
• We use composer for the installation
• If you don’t have it, get it from here: https://getcomposer.org
Run the following in your terminal: Laravel Installer:
24. Setting up / Starting ElasticSearch on OSX
Settings / name, cluster_name:
/usr/local/etc/elasticsearch/elasticsearch.yml
Java Virtual Machine options:
/usr/local/etc/elasticsearch/jvm.options
-Xms2g => -Xms256m
-Xmx2g => -Xmx256m
Maximum of 32GB per node is recommended
NB: 256m is for small dev boxes and not production!!
25. Installing additional packages
• ElasticSearch composer package
• Guzzle (optional)
• VueX for using Store
• Setup default FrontEnd scaffold
44. Compile the front-end
In the console run:
• Development
npm run dev one-time build
npm run watch listener for changes
• Production
npm run production