Magento search results are not very relevant even with the activation of the MySQL Fulltext search. Here is a module that allows you to use Elasticsearch search engine to optimize the search results of your Magento store.
Be careful, this module is for Magento 1.7+ only!
What is Elasticsearch?
Elasticsearch is a very powerful search engine written in Java and based on Apache Lucene. It allows to index millions of documents by replicating data automatically on Elasticsearch nodes you create. He thus manages to make the load distribution. Requests are made in JSON through HTTP requests, which makes it usable with any programming language.
Elasticsearch installation
To install Elasticsearch, simply follows instructions on GitHub: https://github.com/elasticsearch/elasticsearch#installation.
I also recommend installing the plugin elasticsearch-head that will allow you to use Elasticsearch from a web browser.
Installation of Elasticsearch module for Magento 1.7+
Extension is available on GitHub: https://github.com/jreinke/magento-elasticsearch
You have 2 ways to install it:
- Manual installation: download package here, unzip in Magento root folder, then clean cache.
- Installation with modgit:
modgit -e README.md clone elasticsearch https://github.com/jreinke/magento-elasticsearch.git
See a full example of how to use
modgit
here.
Module configuration
Go to “System > Configuration > Catalog > Catalog Search” :
Now you can configure Elasticsearch parameters as you wish and reindex catalog search.
Elasticsearch documentation is available here.
For the curious, the code that builds and runs the query to Elasticsearch is
here.
48 Responses to “Magento: Enhance your search results with Elasticsearch”
hi
out of curiosity, why did you choose elasticsearch over solr?
Hi,
I chose ES thanks to its scalability, its API and its performances.
BTW, Solr is a good choice too
Hello,
Tout d’abord merci pour le travail que tu fournis et que tu fais partager avec la communauté, vraiment cool !
Je tente d’utiliser ton module, j’ai essayé sur une install propre de magento 1.7.2 avec les samples data de magento.
Je rencontre une erreur “elasticsearch” à l’indexation, la voici :
“failed to execute bulk item (index) index {[magento][product][16|1] (…)”
L’exception JAVA est :
“java.lang.IllegalArgumentException: Min shingle size must be <= max shingle size"
—
Sais tu si ça provient de ton module ou bien de mon installation de ElasticSearch (je suis sous ubuntu), y'a t-il une configuration spécifique d'ElasticSearch ?
Merci par avance !
Hello,
As-tu toujours le problème ?
Moi j’ai essayé avec le sample data justement sur une 1.7 de Magento et je n’ai pas eu ce bug. Je pense quand même que cela peut venir de mon module et non pas de ta configuration d’ES.
Salut Johann,
Tu devrais ajouter ta repo par un pull request ici :
http://www.elasticsearch.org/guide/appendix/clients.html
@++
David
Hi, super, thanks for this Extension! Support your extension the Ajax Autosuggest function?
Yes it’s working fine with it.
Hallo Johann,
Ich habe die Erweiterung manuell installiert, da war nichts unter System / Configuration / Catalog Search in Bezug auf Elasticsearch.
Bei Module Output wurde einzig das Modul gelistet.
Habe danach manuell:
INSERT INTO core_config_data (scope, scope_id, path, value) VALUES(‘default’, 0, ‘catalog/search/engine’, ‘jr_search/engine_elasticsearch’);
ausgeführt, noch immer nichts mit Elasticsearch und ich kann nun keinen Reindex von “Catalog Search Index” mehr machen:
MapperParsingException[Analyzer [analyzer_] not found for field [description]]
Cannot initialize the indexer process.
Ich nutze Magento CE 1.7.0.2 und Elasticsearch 1.19.11.
Hast Du vielleicht eine Idee was da falsch läuft?
In english please?
Salut,
J’ai installé le module avec modgit sans soucis. En revanche, après le vidage du cache j’ai une erreur 503 sur la page de config/catalogue dans l’admin. J’ai cette erreur dans les logs:
‘Mage_Core_Exception’ with message ‘Type de bloc non valide : JR_Search_Block_Catalog_Layer_View’
Vous avez une idée?
Merci.
Laurent
Problème résolu! J’avais oublié de tout recompiler!
Merci
Bonjour,
Lors du lancement du processus de réindexation, j’obtiens l’erreur suivante:
RemoteTransportException[[Zartra][inet[/192.168.0.41:9300]][indices/mapping/put]]; nested: MapperParsingException[Analyzer [analyzer_] not found for field [description]];
Impossible d’initialiser le process d’indexation.
C’est le m^me problème rencontré par Nedad, su Magento 1.7.0.2.
Bien cordialement
Hello from Germany,
I have an Question, because the SearchEngine is not working in Frontend…
What should I write in the Field (Index Name)? It is now Magento and my Store is in the Main Folder on the Server.
Hi!
I’m not sure to understand what you ask me exactly. Index name is the name you want to give to your elasticsearch index, it’s similar to the name you give for your mysql database.
Bonjour,
as-tu des exemples de sites qui utilisent le module ?
Merci par avance pour ta réponse.
Pour le moment non le site n’est pas en production mais dès qu’il le sera je te dirai, s’ils m’autorisent à le faire
Bonjour Johann,
J’ai essayé ton extension, mais le ‘layered navigation’ sur le frontend a disparu. Qu’est-ce que je fais mal?
Cordialement,
Gergely
Salut,
Je rencontre le même problème que Gergely, les filtres du layer ne s’affichent pas.
Après avoir fait une rapide enquête on s’aperçoit que la construction des filtres se fait avant la requête. C’est à dire que lors de l’appel à la méthode “_getItemsData” de chaque filtres la collection n’est pas chargée et par extension le tableau “$this->_facetedData” ne contient pas les facets. Ce tableau est remplie dans le “_beforeLoad” de la collection (ligne 280 de la classe JR_Search_Model_Resource_Catalog_Product_Collection).
Je n’ai pas encore trouvé de solution fonctionnelle (j’ai tenté un load de la collection dans le “_beforeHmtml” du block JR_Search_Block_Catalogsearch_Layer, j’ai bien les filtres mais je perds la pagination…).
Quelqu’un a une solution à ce problème ?
Merci,
Brice
PI: j’ai récupérer la dernière version du module Magento. Elastic en version 0.20.6.
Re,
une autre piste qui confirme un problème d’ordonnancement. Si je déplace le layer dans la colonne de droite (gauche par défaut), celui-ci apparaît bien car la méthode “_getItemsData” est appelé après le “_beforeLoad” de la collection.
Vraiment étrange… mais toujours pas une solution
Brice,
Salut,
J’ai rencontré ce problème sur un autre projet.
Tout fonctionne bien avec le thème par défaut de Magento mais pas avec leur thème personnalisé.
Pour le moment, le seul moyen a été d’ajouter en haut du fichier :
app/design/frontend/<package>/<theme>/template/catalog/layer/view.phtml
la ligne suivante :
$this->getLayer()->getProductCollection()->load();
Je vais essayer d’investiguer plus longuement pour trouver d’où vient le problème.
Salut,
Le problème de cette technique c’est que la page de résultats n’est plus correct. Ex : recherche retournant 2288 résultats à raison de 10 résultats par page, et bien j’ai 100 résultats par page (sans doute une limitation côté Elasticsearch ?).
Tu n’a pas ce problème avec cette technique ?
Brice,
Si en effet et on avait dû modifier le comportement de la méthode
_getParams()
sur la collection.J’ai créé un Gist pour expliquer les modifications : https://gist.github.com/jreinke/5364062
Ce n’est bien évidemment pas normal d’en arriver là mais le problème était complexe, il faut que je creuse ça longuement :-/
Merci, ça marche nickel.
Je suis plutôt passer par une surcharge du layer et l’ajout d’un _beforeToHtml dans lequel je vais le load de la collection.
Brice,
Merci Johann pour la solution.
Brice, est-ce que tu peux m’expliquer ce que tu comprends par surcharge du layer et l’ajout d’un _beforeToHtml? Tu peux me donner un example? Ca m’aiderait beaucoup, je ne suis pas encore expert dans Magento, ca fait que quelques mois que j’ai commencé a creuser dans le code, mais j’essaye d’avancer vite.
Merci d’avance,
Gergely
Gergely,
J’ai tout d’abord créé une classe avec le contenu suivant :
class MonModule_Elasticsearch_Block_Catalogsearch_Layer extends JR_Search_Block_Catalogsearch_Layer {
protected function _beforeToHtml() {
parent::_beforeToHtml();
if (Mage::helper('jr_search')->isActiveEngine()) {
$this->getLayer()->getProductCollection()->load();
}
return $this;
}
}
On indique ici que si le moteur de recherche est elasticsearch alors on force le chargement de la collection. Cette action est effectué juste avant de rendre le HTML. Je trouve que passer par ce mécanisme correspond plus au standard Magento, plutôt que de le faire directement dans le template. D’ailleurs Magento utilise la même technique dans le _beforeToHtml de la liste de produit.
Dans le config.xml on déclare, dans la section blocks, la surcharge suivante :
MonModule_Elasticsearch_Block_Catalogsearch_Layer
Pour être sûr que notre surcharge passe avant celle du module de Johann, il faut ajouter une dépendance dans la déclaration du tiens :
true
local
En espérant que ça aide.
Brice,
Bon le code est pas bien passé
https://gist.github.com/aya-brice/5403608
This post has helped me think things thorguh
Salut,
Je reviens faire mon casse pied mais il y a un soucis avec le patch proposé (rien de très grave). Le tri ne fonctionne plus… Pour corriger le problème il faut modifier légèrement la méthode _getParams de la collection produit pour récupérer le tri en dans l’URL ou via la toolbar.
J’ai mis à jour mon Gist avec la classe Collection.php : https://gist.github.com/aya-brice/5403608
En espérant que ça aide.
Brice,
Bonjour,
merci pour votre Module.
après plusieurs modifs pour adapter votre module a mes besoins, et vu que j’ai plus de 2M de produits sur ma base de données l’indexation est devenu un vrais cauchemar ( plus de 2 min ).
après l’appel à la méthode save() il y a plusieurs type d’indexation qui se déclenchent ( ‘catalog_product_price’, ‘cataloginventory_stock’,’tag_summary’, ‘catalog_product_attribute’, ‘catalog_url’, ‘catalog_product_flat’, ‘catalog_category_flat’, ‘catalog_category_product’, ‘catalogsearch_fulltext’ )
ma question est la suivante : comment je peut déclenché juste l’indexation Elasticsearch sans passer par les autres.
merci d’avance.
Hi Johann,
Great extension. It is working perfectly with the Sample database but not with our customer databases. The data query’s send to Elasticsearch are incorrect becouse of some data. But we are unable to determine the exact cause.
Can you help us with this?
Best regards,
Otto Smittenaar
hi this is great article. I have used ES in my project but can you help me i want to add category name also in json array result. What i’ll do?
Small question, why elasicsearch over sphinx?
How to narrow results based on attribute match ?
Hello,
i have applied elastic search on my magento website — http://www.myessentials.ca/dev. but its not working. can u help me out on this
Thanks
Manik
Good day,
story:
1. I have installed Magento ver. 1.7 with products data already existing
2. I’ve installed ES on the same CentOS server, ES works well
3. I’ve installed this magento extension, it appeared in admin part and seems all right
4. But there is blocker issue – when I try reindex “Catalog Search Index” I’m getting next error
question:
1. please let me know what may be the reason of what so I can pinpoint the issue?
thank you very much
>>> updated
story:
1. installed clean magento store ver. 1.7 on local pc Fedora19
2. installed ES + this extension
result:
1. exactly the same error happens when edit => save product
question:
1. am I doing something wrong? please advise
thanks again
>>> updated
log info regarding my posts above added
any clue?
thank you
Having the same problem… Any solution will be great
Hello,
This free extension is only compatible with Elasticsearch 0.20.x. Are you currently using this version?
I am trying to integrate qbox.io with ES and I keep getting this error: ‘Elasticsearch engine is not available.’ Needless to say features like suggestions are not working. Please help. Thanks
Hello,
Same as above, which Elasticsearch version is used with qbox.io please?
Hello,
I got an error with your extension. It is not possible to reindex,
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) |
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) |
at java.lang.Thread.run(Thread.java:744) |
Caused by: java.lang.NumberFormatException: For input string: “Array” |
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) |
at java.lang.Integer.parseInt(Integer.java:492) |
at java.lang.Integer.parseInt(Integer.java:527) |
at org.elasticsearch.common.xcontent.support.AbstractXContentParser.intValue(AbstractXContentParser.java:126) |
at org.elasticsearch.index.mapper.core.IntegerFieldMapper.innerParseCreateField(IntegerFieldMapper.java:307) |
at org.elasticsearch.index.mapper.core.NumberFieldMapper.parseCreateField(NumberFieldMapper.java:215) |
at org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(AbstractFieldMapper.java:408) |
As you can see you have the product entry “ye_material”:["Array","210"] which throws this error (Caused by: java.lang.NumberFormatException: For input string: “Array” )
Where can I find the error?
Sebastian
Hi,
unfortunately the patch aya brice provided under https://gist.github.com/aya-brice/5403608 is not available anymore. Can someone provide the code again? Help is much appreciated!
You mention this as supporting 1.7+
Will it work fine on magento 1.9?
i tried this but didnt work..i mean der is no search engine option in my magento admin area’s system-config-catalog-catalogsearch
what do u think went wrong?
Does the index name we specify in magento configuration also gets created in elastic search server. Once the configuration is complete can we see the index in elastic search server too
Hi, the extension works wonderfully, I have only a question. When I write something on the searchbar and then I hit the enter button, I correctly go to the search result page. In this page, items are ordered by relevance. I already created a custom attribute to order products on list templates. I’d like to use this custom attribute to oder search result as well. So, is there a way to have the search result page ordered by my custom attribute instead of by relevance? thanks
Hi
I found this plugin to be very attractive and elegant. The carousel implementation looks awesome as well. Can you please tell me how to use this plugin (maybe from the admin part, or somewhere else?) to index the ElasticSearch with some catalog/product/categories data, and then, how can I be able to search this new data with the Search bar (Search textbox) in Magento? Thanks in advance and keep up the great work!
Vlad