I think I found a solution for WPML by updating get_index_name in classes/class-ep-config.php. Indexing and search now appears to return correct language based results.
$site_url = get_site_url( $blog_id );
// WPML support
if ( function_exists('icl_object_id') ) {
$site_url = preg_replace('/\/$/','',apply_filters( 'wpml_home_url', $site_url ));
} // if
Hi,
Is there a way to solve this without adjusting the core plugin files? (like with a hook)
This should work:
// Over-ride index name to support WPML
function filter_ep_index_name($index_name, $blog_id) {
// WPML support
if ( function_exists('icl_object_id') ) {
$site_url = get_site_url( $blog_id );
$site_url = preg_replace('/\/$/','',apply_filters( 'wpml_home_url', $site_url ));
if ( ! empty( $site_url ) ) {
$index_name = preg_replace( '#https?://(www\.)?#i', '', $site_url );
$index_name = preg_replace( '#[^\w]#', '', $index_name ) . '-' . $blog_id;
} else {
$index_name = false;
}
} // if
return $index_name;
} // filter_ep_index_name
// Fix Index name
add_filter('ep_index_name', array($this,'filter_ep_index_name'), 10, 2);
Thanks.
I used another workaround though:
//
// Add wpml metadata to index
//
add_filter( 'ep_config_mapping', 'index_elastic_meta' );
function index_elastic_meta ( $mapping ) {
$mapping['mappings']['post']['properties']['wpml_language'] = array(
'type' => 'string'
);
return $mapping;
}
add_filter( 'ep_post_sync_args', 'add_elastic_meta' );
function add_elastic_meta ( $post_args, $post_id=false ) {
if ( $post_args['post_id'] ) {
$lang_info = wpml_get_language_information($post_args['post_id']);
$post_args['post_meta']['wpml_language'] = $lang_info['language_code'];
}
return $post_args;
}
Paul, did you have to make any additional changes to get EP plugin to push all language content to ES when using a single index? In my initial tests, EP would only push content for the currently active language.
Hello Guys,
I am not really sure how to use elasticpress, however, I know that I have WPML installed and when I go throguht the last steps of the installation process of elasticpress and setup by terminal I will run into the same problems as you have. Apparently elasticsearch is not compatible with WPML.
Maybe I am in over my head, however I thought that setting up elasticsearch would be quite easy.
Do I add above code to my functions.php and it will all work smoothly?
Thanks!
Hi,
Yes, you should be able to add the code to functions.php in your custom theme. In the solution that I provided, it is necessary to re-index in Elastic plugin for each WPML language after making the code update since it creates a separate Elasticsearch index for each language.