Blogs
Q-Have you ever wondered if you can customize your Elastic Search, so that on your searches in Liferay, not only the words you're searching for come up in the results but also synonyms of these words?
A-Yes, you can!
Below, I'll show you an example of how I did it (by customizing my indexes and mappings settings).
Let's say that I have a web content article containing the word "small" and I search for the word "tiny".
- Navigate to Control Panel → Configuration → System Settings → Foundation
- Search for the com.liferay.portal.search.elasticsearch.configuration.ElasticsearchConfiguration system setting.
- Go to "Aditional index configurations" and add your own.
You can start by copying the contents of your index-settings.json file there. Your index-settings.json file is packed in the Elastic Search module of your Liferay bundle.
Now, modify it as this document describes: https://www.elastic.co/guide/en/elasticsearch/guide/current/using-synonyms.html .
It should look like the image below (note the "synonyms" part of the json, where we wrote our list of synonyms):

- Now go to "Override type mappings" and copy into the text area input the contents of the file "liferay-type-mappings.json", also packed in the Elastic Search module (a jar that you will find in your Liferay bundle) into it.
Modify it, also following the steps this document describes: https://www.elastic.co/guide/en/elasticsearch/guide/current/using-synonyms.html (as in the previous step).
For example, you could add something like this:
"content": {"index": "analyzed","store": "yes","search_analyzer" : "my_synonym_analyzer","analyzer" : "my_synonym_analyzer","term_vector": "with_positions_offsets","type": "string"},
and something like this:
"title": {"index": "analyzed","store": "yes","search_analyzer" : "my_synonym_analyzer","analyzer" : "my_synonym_analyzer","term_vector": "with_positions_offsets","type": "string"},
to it:
- Save your changes
- Navigate to Control Panel → Configuration → Server Administration and execute "Reindex all search indexes" under the section "Index Actions"

- Perform a search and... Voila!, the magic happens:

Easy, right?
If Elastic Search can do it, Liferay will do it too (since it leverages on Elastic Search for indexing its documents). You just need to know it can be done, and where in the control panel you can configure it.

