# More Like This in a boolean query

**URL:** <https://discuss.elastic.co/t/more-like-this-in-a-boolean-query/9760>\
**Category:** Elasticsearch\
**Created:** [November 19, 2012, 3:23pm UTC](https://discuss.elastic.co/t/more-like-this-in-a-boolean-query/9760 "2012-11-19T15:23:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Dunn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_dunn/32/2315_2.png) [@Nick\_Dunn](https://discuss.elastic.co/u/Nick_Dunn)\
**Post date:** [November 19, 2012, 3:23pm UTC](https://discuss.elastic.co/t/more-like-this-in-a-boolean-query/9760/1 "2012-11-19T15:23:20Z")

</div>

I'm wanting to use ES to build a list of related documents for a given  
document. However I don't want to rely on the default more like this result  
— I'd like a little more control. Each of my documents has three sets of  
tags (arrays of strings) and one "primary tag" (single string). I work out  
a related article where other articles "must" match a primary tag, and  
"should" match any of the other three sets of tags. This works quite well,  
but I was wondering whether I'd be able to add in article contents to the  
algorithm.

Can I add a more like this query into a boolean "should"? And if so, can I  
pass a document ID (like the \_mlt API) as opposed to a string for  
"like\_text"?

--

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [November 19, 2012, 5:13pm UTC](https://discuss.elastic.co/t/more-like-this-in-a-boolean-query/9760/2 "2012-11-19T17:13:03Z")

</div>

Hi Nick,

it is possible to wrap MoreLikeThis queries into a boolean query. Put your  
primary tag field mlt query into a "must" clause and your other tag fields  
mlt query into a "should" clause. If you want to start from a specific  
document, fetch it with a GetRequest by ID, and read the content of the  
primary tag field and other tags fields for filling the "like\_text" fields  
in the clauses.

Jörg

On Monday, November 19, 2012 4:23:21 PM UTC+1, Nick Dunn wrote:

> I'm wanting to use ES to build a list of related documents for a given  
> document. However I don't want to rely on the default more like this result  
> — I'd like a little more control. Each of my documents has three sets of  
> tags (arrays of strings) and one "primary tag" (single string). I work out  
> a related article where other articles "must" match a primary tag, and  
> "should" match any of the other three sets of tags. This works quite well,  
> but I was wondering whether I'd be able to add in article contents to the  
> algorithm.
> 
> Can I add a more like this query into a boolean "should"? And if so, can I  
> pass a document ID (like the \_mlt API) as opposed to a string for  
> "like\_text"?

--

---

<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:** [July 6, 2017, 3:03am UTC](https://discuss.elastic.co/t/more-like-this-in-a-boolean-query/9760/3 "2017-07-06T03:03:40Z")

</div>


