# Filter on "more like this" query?

**URL:** <https://discuss.elastic.co/t/filter-on-more-like-this-query/3370>\
**Category:** Elasticsearch\
**Created:** [September 27, 2010, 4:16am UTC](https://discuss.elastic.co/t/filter-on-more-like-this-query/3370 "2010-09-27T04:16:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ask\_Bjorn\_Hansen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ask_bjorn_hansen/32/2995_2.png) [@Ask\_Bjorn\_Hansen](https://discuss.elastic.co/u/Ask_Bjorn_Hansen)\
**Post date:** [September 27, 2010, 4:16am UTC](https://discuss.elastic.co/t/filter-on-more-like-this-query/3370/1 "2010-09-27T04:16:06Z")

</div>

Hi everyone,

I'm replacing the search on [http://jobs.perl.org/](http://jobs.perl.org/) with Elastic  
Search. So far everything is working very nicely - it's been a  
pleasure to work with (well, except the obscure errors while I was  
learning the query syntax).

I loaded all the old/expired jobs into the index, too -- the intention  
was to be able to do a "more like this" query to help the user find an  
active similar job when requesting details for a job that's expired or  
been removed from the site by the poster.

To do this I added an 'active: [0 | 1]' flag to each document and in  
regular search I just filter on this; it works great.

However -- I can't figure out how to do the filter on the mlt query.  
Is it not possible?

- ask

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [September 27, 2010, 7:46am UTC](https://discuss.elastic.co/t/filter-on-more-like-this-query/3370/2 "2010-09-27T07:46:12Z")

</div>

Hi Ask

> However -- I can't figure out how to do the filter on the mlt query.  
> Is it not possible?

You are using the /\_mlt query?

This just gets converted to a standard search with a more\_like\_this  
query:  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/more\_like\_this/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/more_like_this/)

which you can then wrap in query filter:  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/query\_dsl/query\_filter/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/query_filter/)

clint

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [September 27, 2010, 8:18am UTC](https://discuss.elastic.co/t/filter-on-more-like-this-query/3370/3 "2010-09-27T08:18:05Z")

</div>

I think that it should be wrapped with a filtered query:  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/query\_dsl/filtered\_query/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/filtered_query/),  
the mlt\_query will be the query, and the filter will include the active  
ones.

On Mon, Sep 27, 2010 at 9:46 AM, Clinton Gormley [clinton@iannounce.co.uk](mailto:clinton@iannounce.co.uk)wrote:

> Hi Ask
> 
> > However -- I can't figure out how to do the filter on the mlt query.  
> > Is it not possible?
> 
> You are using the /\_mlt query?
> 
> This just gets converted to a standard search with a more\_like\_this  
> query:  
> [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/more\_like\_this/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/more_like_this/)
> 
> which you can then wrap in query filter:
> 
> [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/query\_dsl/query\_filter/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/query_filter/)
> 
> clint

---

<div class="post-metadata">

**Author:** ![Ask\_Bjorn\_Hansen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ask_bjorn_hansen/32/2995_2.png) [@Ask\_Bjorn\_Hansen](https://discuss.elastic.co/u/Ask_Bjorn_Hansen)\
**Post date:** [September 27, 2010, 9:22am UTC](https://discuss.elastic.co/t/filter-on-more-like-this-query/3370/4 "2010-09-27T09:22:44Z")

</div>

Thanks Shay & Clint:

Yes - I was trying to use the 'mlt' query (with the id of the old  
posting). Clint pointed out to me on IRC that I need to do it with a  
regular search to combine it with other filters. I changed the code  
to just build the "like\_text" and pass it in as a regular filter and  
all is well now. Thanks!

> <https://gist.github.com/abh/598752>

- ask

--  
[http://askask.com/](http://askask.com/)

---

<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, 4:18am UTC](https://discuss.elastic.co/t/filter-on-more-like-this-query/3370/5 "2017-07-06T04:18:55Z")

</div>


