# How apply a filter on MLT request with Java API?

**URL:** <https://discuss.elastic.co/t/how-apply-a-filter-on-mlt-request-with-java-api/9737>\
**Category:** Elasticsearch\
**Created:** [November 16, 2012, 8:52am UTC](https://discuss.elastic.co/t/how-apply-a-filter-on-mlt-request-with-java-api/9737 "2012-11-16T08:52:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atharva\_Patel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atharva_patel/32/2414_2.png) [@Atharva\_Patel](https://discuss.elastic.co/u/Atharva_Patel)\
**Post date:** [November 16, 2012, 8:52am UTC](https://discuss.elastic.co/t/how-apply-a-filter-on-mlt-request-with-java-api/9737/1 "2012-11-16T08:52:51Z")

</div>

As I want to perform MLT query with doc id in my hand, I have two questions.

1. Is it possible to perform MLT query by passing just a docID in case  
where the \_source is disabled? Reason is my document size will be large, so  
I don't feel it feasible either to send a like\_text or enabling \_source as  
both can explode the memory requirements.

2. How can I apply a filter on the MLT request from Java API?

--

---

<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, 12:25am UTC](https://discuss.elastic.co/t/how-apply-a-filter-on-mlt-request-with-java-api/9737/2 "2012-11-19T00:25:32Z")

</div>

1. yes, you can use the fields parameter to use mlt without an enabled  
\_source. Only if you do not provide fields, mlt is falling back to use  
\_source

2. mlt filter is not implemented at the moment, but it seems possible by  
introducing a filter parameter to the mlt action

Cheers,

Jörg

On Friday, November 16, 2012 9:52:51 AM UTC+1, Atharva Patel wrote:

> As I want to perform MLT query with doc id in my hand, I have two  
> questions.
> 
> 1. Is it possible to perform MLT query by passing just a docID in case  
> where the \_source is disabled? Reason is my document size will be large, so  
> I don't feel it feasible either to send a like\_text or enabling \_source as  
> both can explode the memory requirements.
> 
> 2. How can I apply a filter on the MLT request from Java API?

--

---

<div class="post-metadata">

**Author:** ![Atharva\_Patel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atharva_patel/32/2414_2.png) [@Atharva\_Patel](https://discuss.elastic.co/u/Atharva_Patel)\
**Post date:** [November 22, 2012, 4:11am UTC](https://discuss.elastic.co/t/how-apply-a-filter-on-mlt-request-with-java-api/9737/3 "2012-11-22T04:11:23Z")

</div>

Thanks for the reply Jorg!

When I try out performing MTL query using MLT API [http://goo.gl/oEwFH](http://goo.gl/oEwFH), it  
gives me error:  
{"error":"ElasticSearchException[No fields found to fetch the 'likeText'  
from]","status":500}

Am I missing something? I would like to highlight that I am neither storing  
the fields or enabling \_source. Is it still possible to perform MLT query  
with that docID? How? I have mentioned the fields 'analyzed'. Do I need to  
do anything else also?

On Monday, 19 November 2012 05:55:33 UTC+5:30, Jörg Prante wrote:

> 1. yes, you can use the fields parameter to use mlt without an enabled  
> \_source. Only if you do not provide fields, mlt is falling back to use  
> \_source
> 
> 2. mlt filter is not implemented at the moment, but it seems possible by  
> introducing a filter parameter to the mlt action
> 
> Cheers,
> 
> Jörg
> 
> On Friday, November 16, 2012 9:52:51 AM UTC+1, Atharva Patel wrote:
> 
> > As I want to perform MLT query with doc id in my hand, I have two  
> > questions.
> > 
> > 1. Is it possible to perform MLT query by passing just a docID in case  
> > where the \_source is disabled? Reason is my document size will be large, so  
> > I don't feel it feasible either to send a like\_text or enabling \_source as  
> > both can explode the memory requirements.
> > 
> > 2. How can I apply a filter on the MLT request from Java API?

--

---

<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 23, 2012, 6:24pm UTC](https://discuss.elastic.co/t/how-apply-a-filter-on-mlt-request-with-java-api/9737/4 "2012-11-23T18:24:31Z")

</div>

Hi Atharva,

if you don't have fields stored, and no \_source is enabled, you are out of  
luck. MoreLikeThis works by executing two actions: first, a get request on  
the given document, fetching a stored field content for the likeText search  
query (falling ack to \_source if no fields are specified), then populating  
the parameters before executing a generated search as the second action.

Best regards,

Jörg

--

---

<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/how-apply-a-filter-on-mlt-request-with-java-api/9737/5 "2017-07-06T03:03:06Z")

</div>


