# MoreLikeThis ignores queries?

**URL:** <https://discuss.elastic.co/t/morelikethis-ignores-queries/16437>\
**Category:** Elasticsearch\
**Created:** [March 18, 2014, 7:05pm UTC](https://discuss.elastic.co/t/morelikethis-ignores-queries/16437 "2014-03-18T19:05:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexey\_Bagryancev](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Alexey\_Bagryancev](https://discuss.elastic.co/u/Alexey_Bagryancev)\
**Post date:** [March 18, 2014, 7:05pm UTC](https://discuss.elastic.co/t/morelikethis-ignores-queries/16437/1 "2014-03-18T19:05:49Z")

</div>

Hi,

I am trying to filter moreLikeThis results by adding additional query - but  
it seems to ignore it at all.

I tried to run my ignoreQuery separately and it works fine, but how to make  
it work with moreLikeThis? Please help me.

$ignoreQuery = $this-\>IgnoreCategoryQuery('movies')

$this-\>resultsSet = $this-\>index-\>moreLikeThis(  
new \Elastica\Document($id),  
array\_merge($this-\>mlt\_fields, array('search\_size' =\> $this-\>size  
, 'search\_from' =\> $this-\>from)),  
$ignoreQuery);

My IgnoreCategory function:

public function IgnoreCategoryQuery($category = 'main')  
{  
$categoriesTermQuery = new \Elastica\Query\Term();  
$categoriesTermQuery-\>setTerm('categories', $category);

$categoriesBoolQuery = new \Elastica\Query\Bool();  
$categoriesBoolQuery-\>addMustNot($categoriesTermQuery);

return $categoriesBoolQuery;  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1480e498-f21c-4bc2-b43c-3d068c73ba55%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1480e498-f21c-4bc2-b43c-3d068c73ba55%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Alexey\_Bagryancev](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Alexey\_Bagryancev](https://discuss.elastic.co/u/Alexey_Bagryancev)\
**Post date:** [March 19, 2014, 4:01am UTC](https://discuss.elastic.co/t/morelikethis-ignores-queries/16437/2 "2014-03-19T04:01:06Z")

</div>

Anyone can help me? It really does not work...

среда, 19 марта 2014 г., 2:05:49 UTC+7 пользователь Alexey Bagryancev  
написал:

> Hi,
> 
> I am trying to filter moreLikeThis results by adding additional query -  
> but it seems to ignore it at all.
> 
> I tried to run my ignoreQuery separately and it works fine, but how to  
> make it work with moreLikeThis? Please help me.
> 
> $ignoreQuery = $this-\>IgnoreCategoryQuery('movies')
> 
> $this-\>resultsSet = $this-\>index-\>moreLikeThis(  
> new \Elastica\Document($id),  
> array\_merge($this-\>mlt\_fields, array('search\_size' =\> $this-\>  
> size, 'search\_from' =\> $this-\>from)),  
> $ignoreQuery);
> 
> My IgnoreCategory function:
> 
> public function IgnoreCategoryQuery($category = 'main')  
> {  
> $categoriesTermQuery = new \Elastica\Query\Term();  
> $categoriesTermQuery-\>setTerm('categories', $category);
> 
> $categoriesBoolQuery = new \Elastica\Query\Bool();  
> $categoriesBoolQuery-\>addMustNot($categoriesTermQuery);
> 
> return $categoriesBoolQuery;  
> }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/212ca5d9-4c48-476d-9ea1-983b9578e8f9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/212ca5d9-4c48-476d-9ea1-983b9578e8f9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Alex\_Ksikes1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_ksikes1/32/1534_2.png) [@Alex\_Ksikes1](https://discuss.elastic.co/u/Alex_Ksikes1)\
**Post date:** [May 6, 2014, 10:16am UTC](https://discuss.elastic.co/t/morelikethis-ignores-queries/16437/3 "2014-05-06T10:16:29Z")

</div>

Hello Alexey,

You should use the query DSL and not the more like this API. You can create  
a boolean query where one clause is your more like this query and the other  
one is your ignore category query (better use a filter here if you can).

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

However, more like this of the DSL only takes a like\_text parameter, you  
cannot pass the id of the document. This will change in a subsequent  
version of ES. For now, to simulate this functionality, you can use  
multiple mlt queries with a like\_text set to the value of each field of the  
queried document, inside a boolean query. Let me know if this helps.

Alex

On Wednesday, March 19, 2014 5:01:06 AM UTC+1, Alexey Bagryancev wrote:

> Anyone can help me? It really does not work...
> 
> среда, 19 марта 2014 г., 2:05:49 UTC+7 пользователь Alexey Bagryancev  
> написал:
> 
> > Hi,
> > 
> > I am trying to filter moreLikeThis results by adding additional query -  
> > but it seems to ignore it at all.
> > 
> > I tried to run my ignoreQuery separately and it works fine, but how to  
> > make it work with moreLikeThis? Please help me.
> > 
> > $ignoreQuery = $this-\>IgnoreCategoryQuery('movies')
> > 
> > $this-\>resultsSet = $this-\>index-\>moreLikeThis(  
> > new \Elastica\Document($id),  
> > array\_merge($this-\>mlt\_fields, array('search\_size' =\> $this-\>  
> > size, 'search\_from' =\> $this-\>from)),  
> > $ignoreQuery);
> > 
> > My IgnoreCategory function:
> > 
> > public function IgnoreCategoryQuery($category = 'main')  
> > {  
> > $categoriesTermQuery = new \Elastica\Query\Term();  
> > $categoriesTermQuery-\>setTerm('categories', $category);
> > 
> > $categoriesBoolQuery = new \Elastica\Query\Bool();  
> > $categoriesBoolQuery-\>addMustNot($categoriesTermQuery);
> > 
> > return $categoriesBoolQuery;  
> > }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e605d6e2-b42b-4661-b819-90735a9581ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e605d6e2-b42b-4661-b819-90735a9581ec%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:31am UTC](https://discuss.elastic.co/t/morelikethis-ignores-queries/16437/4 "2017-07-06T01:31:28Z")

</div>

Closed on July 6, 2017, 1:31am UTC


