# ElasticSearch - Related posts

**URL:** <https://discuss.elastic.co/t/elasticsearch-related-posts/146997>\
**Category:** Elasticsearch\
**Created:** [September 2, 2018, 9:50pm UTC](https://discuss.elastic.co/t/elasticsearch-related-posts/146997 "2018-09-02T21:50:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krenari](https://avatars.discourse-cdn.com/v4/letter/k/59ef9b/32.png) [@Krenari](https://discuss.elastic.co/u/Krenari)\
**Post date:** [September 2, 2018, 9:50pm UTC](https://discuss.elastic.co/t/elasticsearch-related-posts/146997/1 "2018-09-02T21:50:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 30, 2018, 9:50pm UTC](https://discuss.elastic.co/t/elasticsearch-related-posts/146997/2 "2018-09-30T21:50:31Z")

</div>

Closed on September 30, 2018, 9:50pm UTC

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