# Is there a way to combine query\_string with mlt\_field?

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-combine-query-string-with-mlt-field/14993>\
**Category:** Elasticsearch\
**Created:** [December 23, 2013, 1:11am UTC](https://discuss.elastic.co/t/is-there-a-way-to-combine-query-string-with-mlt-field/14993 "2013-12-23T01:11:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![project2501](https://avatars.discourse-cdn.com/v4/letter/p/41988e/32.png) [@project2501](https://discuss.elastic.co/u/project2501)\
**Post date:** [December 23, 2013, 1:11am UTC](https://discuss.elastic.co/t/is-there-a-way-to-combine-query-string-with-mlt-field/14993/1 "2013-12-23T01:11:20Z")

</div>

Hi,  
I can get facet counts from a MLT field query. Like below.

{"query":{"_mlt\_field_":{"text":{"like\_text":"ministers of  
defense","min\_term\_freq":1,"max\_query\_terms":12}}},"fields":["id"],"facets":{"entities.people":{"terms":{"field":"entities.people"}}}}

But I'm having trouble constructing a query for those documents. I still  
need to use the mlt\_field query as its the basis for my facets.  
But if I try and add query\_string like this:

{"query":{"_mlt\_field_":{"text":{"like\_text":"ministers of  
defense","min\_term\_freq":1,"max\_query\_terms":12}},"_query\_string_":{"fields":["text"],"query":"(entities.people:"government"  
OR entities.people:"government") AND  
text:"government""}},"fields":["id","locations","ratings"]}

I get a parse error.

What's the trick to add a query or filter to mlt\_field? The documentation  
doesn't clarify this.

thank you!!!

--  
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/a71c9db6-69cc-42f3-ae3f-a727c41e6803%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a71c9db6-69cc-42f3-ae3f-a727c41e6803%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 23, 2013, 1:25am UTC](https://discuss.elastic.co/t/is-there-a-way-to-combine-query-string-with-mlt-field/14993/2 "2013-12-23T01:25:12Z")

</div>

I guess you could use a BoolQuery or a FilteredQuery.  
Does it help?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 23 déc. 2013 à 02:11, project2501 [darreng5150@gmail.com](mailto:darreng5150@gmail.com) a écrit :

Hi,  
I can get facet counts from a MLT field query. Like below.

{"query":{"mlt\_field":{"text":{"like\_text":"ministers of defense","min\_term\_freq":1,"max\_query\_terms":12}}},"fields":["id"],"facets":{"entities.people":{"terms":{"field":"entities.people"}}}}

But I'm having trouble constructing a query for those documents. I still need to use the mlt\_field query as its the basis for my facets.  
But if I try and add query\_string like this:

{"query":{"mlt\_field":{"text":{"like\_text":"ministers of defense","min\_term\_freq":1,"max\_query\_terms":12}},"query\_string":{"fields":["text"],"query":"(entities.people:"government" OR entities.people:"government") AND text:"government""}},"fields":["id","locations","ratings"]}

I get a parse error.

What's the trick to add a query or filter to mlt\_field? The documentation doesn't clarify this.

## thank you!!!

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/a71c9db6-69cc-42f3-ae3f-a727c41e6803%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a71c9db6-69cc-42f3-ae3f-a727c41e6803%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/57D69F70-7C6B-48CE-A0A9-EDE1F0606FF5%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/57D69F70-7C6B-48CE-A0A9-EDE1F0606FF5%40pilato.fr).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:59am UTC](https://discuss.elastic.co/t/is-there-a-way-to-combine-query-string-with-mlt-field/14993/3 "2017-07-06T01:59:40Z")

</div>


