ElasticPress is a plugin that works with Elasticsearch to add more robust search, indexing, and filter options than are available in the standard WordPress search. In order to make it work on your multilingual site, you need WPML’s free ElasticPress glue plugin.
The WPML ElasticPress glue plugin:
- Adds a language parameter to be able to filter search by language
- Adds extra parameters to CLI commands to allow indexing of only specific languages
This makes it easier for your users to find what they’re looking for in the language they need. It also prevents the search results from displaying results in a mix of languages.
To download WPML’s ElasticPress glue plugin, please visit our GitHub repository. Download the wpml-elasticpress.zip file and upload it to your site.
Once the plugin is installed, re-index your posts. You can do this either through the WordPress admin, or using the following command:
wp wpml_elasticpress index --setup --post-type=post
When the re-indexing is complete, you’ll see relevant search results in each of your site languages.
The ElasticPress glue plugin also allows you to only index posts in specific languages. To do this:
- Remove any posts that have already been indexed by using the command
wp elasticpress delete-index
- Index posts for a given language (in this example, it’s English):
wp wpml_elasticpress index --setup --post-type=post --post-lang=en
- If you check your site’s frontend now, you’ll see only English posts in the search results on the English site. If you switch languages, the search results should be empty.
If you would like to index additional language, repeat step 2. Be sure to skip the –setup argument, otherwise you will remove the posts that have already been indexed):
wp wpml_elasticpress index --post-type=post --post-lang=fr