ElasticSearch - Related posts

Dear all,

It is my first time that I am trying to use Elasticsearch and I would apologize for any inconvenient question.

I am trying to use elasticsearch in wordpress for two main reasons, first performance and second higher quality "related posts" feature.

I installed elasticsearch server, I installed elasticpress wordpress plugin, I synchronized(indexed) database with the help of plugin. search is working very well but not related posts.

Related posts is give me only last posted articles not related posts:

I call this plugin function ep_find_related(post_id, return) which is suppose to return me related posts but instead of that it returns latest posts which are not related to post_id. Below is the plugin function with formated_args function:

function ep_related_posts_formatted_args( $formatted_args, $args ) {
if ( ! empty( $args[ 'more_like' ] ) ) {
$formatted_args[ 'query' ] = array(
'more_like_this' => array(
'ids' => is_array( $args[ 'more_like' ] ) ? $args[ 'more_like' ] : array( $args[ 'more_like' ] ),
'fields' => apply_filters( 'ep_related_posts_fields', array( 'post_title', 'post_content', 'terms.post_tag.name' ) ),
'min_term_freq' => 1,
'max_query_terms' => 12,
'min_doc_freq' => 1,

return $formatted_args;



  • Search Elasticsearch for related content
  • @param int $post_id
  • @param int $return
  • @since 2.1
  • @return array|bool
    function ep_find_related( $post_id, $return = 5 ) {
    $args = array(
    'more_like' => $post_id,
    'posts_per_page' => $return,
    'ep_integrate' => true,

Please let me know what I am doing wrong

Thank you for taking your time to help me.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.