Using Elastic with Magento
Stefan Willkommer CTO and CO-Founder @ TechDivision GmbH
Comparison License Apache License Apache License Index Lucene Lucene API RESTful Webservice RESTful Webservice Scheme no scheme schema.xml Clustering easy and out of the box SolrCloud
Comparison Per-doc/query analyzer chain Yes No Complex Documents Yes Flat doc structure. No native support for nesting docs Multiple document types per schema Yes One set of fields per schema Online schema changes Yes No, only workaround Advanced Faceting Yes No
Conclusion
Our Goal
Compatibility really easy to use and powerful search engine relieve MySQL using ES for catalog and layered navigation use of standard features like catalog price rules, banners and so on integrated on top of the Solr implementation extended with some custom features actuality of data
Features Auto-Complete prioritization alternatives Search-Suggest after search navigation fault tolerance synonyms
But only for Enterprise Edition
Get started with Elastic
Get started Download and extract Run bin/elasticsearch on Unix or bin/elasticsearch.bat on Windows Run curl -X GET http://localhost:9200/
{ "status" : 200, "name" : "Strongarm", "cluster_name" : "elasticsearch", "version" : { "number" : "1.6.0", "build_hash" : "cdd3ac4dde4f69524ec0a14de3828cb95bbb86d0", "build_timestamp" : "2015-06-09T13:36:34Z", "build_snapshot" : false, "lucene_version" : "4.10.4" }, "tagline" : "You Know, for Search" }
Let s put some data into the index
curl -X PUT http://localhost:9200/mybookstore/book/1 { "book" : { "isbn":"1", "name":"picture of dorian gray", "author":{ "first_name":"oscar", "last_name":"wilde" }, "pages":"157", "tag":["philosophical", "novel"] } }
`mybookstore` is the index name curl -X PUT http://localhost:9200/mybookstore/book/1 { "book" : { "isbn":"1", "name":"picture of dorian gray", "author":{ "first_name":"oscar", "last_name":"wilde" }, "pages":"157", "tag":["philosophical", "novel"] } }
`book` is the _type curl -X PUT http://localhost:9200/mybookstore/book/1 { "book" : { "isbn":"1", "name":"picture of dorian gray", "author":{ "first_name":"oscar", "last_name":"wilde" }, "pages":"157", "tag":["philosophical", "novel"] } }
`1` is of course the id curl -X PUT http://localhost:9200/mybookstore/book/1 { "book" : { "isbn":"1", "name":"picture of dorian gray", "author":{ "first_name":"oscar", "last_name":"wilde" }, "pages":"157", "tag":["philosophical", "novel"] } }
Searching the index
get all data indexed curl -XGET 'localhost:9200/mybookstore/_search' -d ' { "query" : { "match_all" : {} } }'
hitting the book by tag curl -X POST http://localhost:9200/mybookstore/book/_search?q=tag:novel { took":15,"timed_out":false,"_shards": { total":5,"successful":5,"failed":0},"hits": {"total":1,"max_score":0.19178301,"hits":[{"_index":"mybookstore","_type":"book... "book" : { "isbn":"1", "name":"picture of dorian gray", "author":{ "first_name":"oscar", "last_name":"wilde" }, "pages":"157", "tag":["philosophical", "novel"] } }
a lot of possibilities curl -XPOST "http://localhost:9200/_search" -d' { "query": { "query_string": { "query": "dorian", "fields": ["name"] } } } Returns the book with the search word `dorian` in the field name
You see elastic is easy and powerful
great browser tools to administer Elastic
great browser tools to administer Elastic
Architectural Approach
Architecture ES uses the flat table index every change on product data will be triggered no rewriting, just using events extensible through own events Magento compliant
Show the machine
Show the frontend
Extensibility
The suggest
The suggest class Namespace_ElasticSearch_Model_Suggest_Type_Brand extends TechDivision_ElasticSearch_Model_Suggest_Type_Abstract implements TechDivision_ElasticSearch_Interface_Suggest_Type { }
The suggest public function construct() { $this->_datahelper = Mage::helper('techdivision_elasticsearch'); $this->_confighelper = Mage::helper('techdivision_elasticsearch/config'); $this->_engine = Mage::getResourceModel('techdivision_elasticsearch/engine'); } /** * Generate and return suggestions for the given term. * * @param string $term * @return array */ public function suggest($term) { // implement your logic here to get results }
Examples
Customer Cases
Thank you Questions?