# Question on query combination

**URL:** <https://discuss.elastic.co/t/question-on-query-combination/7726>\
**Category:** Elasticsearch\
**Created:** [May 16, 2012, 7:03pm UTC](https://discuss.elastic.co/t/question-on-query-combination/7726 "2012-05-16T19:03:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_Decker](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Scott\_Decker](https://discuss.elastic.co/u/Scott_Decker)\
**Post date:** [May 16, 2012, 7:03pm UTC](https://discuss.elastic.co/t/question-on-query-combination/7726/1 "2012-05-16T19:03:46Z")

</div>

Hey All, a fun query combination for you all.

here is what we are trying to do:

pseudo query:

(  
content:"\<some string that the query parser on es side will parse" -  
must match at least 2 times  
size:[\* TO 300]  
)  
OR  
(  
content:"\<some string that the query parser on es side will parse" -  
must match at least 3 times  
size:[\* TO 600]  
)

something like  
(  
+content:'johnny depp" \<must be in the content at least 2 times\>  
+size:[\* TO 300]  
)  
OR  
(  
+content:'johnny depp" \<must be in the content at least 3 times\>  
+size:[\* TO 600]  
)

In what way could we do the above query? Is there a way to do it with  
dismax? Is there some way to do it with terms, and if so, how do we get the  
right analyzer to run against the text in our client versus what is on  
elasticsearch?  
We are basically trying to say we think it is a match for Johnny Depp if he  
is in the text at least twice and the content size is small.  
The problem with just using scoring, is that we also match on some other  
fields in a constant way. if is present in a field, then you are  
also a match.  
So, how to combine that constant query along with something that is more of  
a scored query?

---

<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:** [May 17, 2012, 10:21pm UTC](https://discuss.elastic.co/t/question-on-query-combination/7726/2 "2012-05-17T22:21:43Z")

</div>

You men how to combine the content query with the size one? It can be a  
filtered query, with the query on the content, and a filter of range on the  
size.

On Wed, May 16, 2012 at 10:03 PM, Scott Decker [scott@publishthis.com](mailto:scott@publishthis.com)wrote:

> Hey All, a fun query combination for you all.
> 
> here is what we are trying to do:
> 
> pseudo query:
> 
> (  
> content:"\<some string that the query parser on es side will parse" -  
> must match at least 2 times  
> size:[\* TO 300]  
> )  
> OR  
> (  
> content:"\<some string that the query parser on es side will parse" -  
> must match at least 3 times  
> size:[\* TO 600]  
> )
> 
> something like  
> (  
> +content:'johnny depp" \<must be in the content at least 2 times\>  
> +size:[\* TO 300]  
> )  
> OR  
> (  
> +content:'johnny depp" \<must be in the content at least 3 times\>  
> +size:[\* TO 600]  
> )
> 
> In what way could we do the above query? Is there a way to do it with  
> dismax? Is there some way to do it with terms, and if so, how do we get the  
> right analyzer to run against the text in our client versus what is on  
> elasticsearch?  
> We are basically trying to say we think it is a match for Johnny Depp if  
> he is in the text at least twice and the content size is small.  
> The problem with just using scoring, is that we also match on some other  
> fields in a constant way. if is present in a field, then you are  
> also a match.  
> So, how to combine that constant query along with something that is more  
> of a scored query?

---

<div class="post-metadata">

**Author:** ![Scott\_Decker](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Scott\_Decker](https://discuss.elastic.co/u/Scott_Decker)\
**Post date:** [May 18, 2012, 4:23pm UTC](https://discuss.elastic.co/t/question-on-query-combination/7726/3 "2012-05-18T16:23:58Z")

</div>

well, yes, sort of.

Basically, the problem is in the minimum must match problem.

the full query is something like  
+(  
tag:topic\_id.89998.0  
)  
+(  
content:"johnny depp" \<this must be in the content 3 times or more if the  
content is greater than say 500 characters\>  
)  
+(  
content:"pirates" \<this must be in the content 2 times or more if the  
content is greater than say 300 characters\>  
)

not really sure how to do this type of query. might be span queries, or  
maybe filter. Not sure if dismax query could do this?

On Thursday, May 17, 2012 3:21:43 PM UTC-7, kimchy wrote:

> You men how to combine the content query with the size one? It can be a  
> filtered query, with the query on the content, and a filter of range on the  
> size.
> 
> Hey All, a fun query combination for you all.
> 
> > here is what we are trying to do:
> > 
> > pseudo query:
> > 
> > (  
> > content:"\<some string that the query parser on es side will parse" -  
> > must match at least 2 times  
> > size:[\* TO 300]  
> > )  
> > OR  
> > (  
> > content:"\<some string that the query parser on es side will parse" -  
> > must match at least 3 times  
> > size:[\* TO 600]  
> > )
> > 
> > something like  
> > (  
> > +content:'johnny depp" \<must be in the content at least 2 times\>  
> > +size:[\* TO 300]  
> > )  
> > OR  
> > (  
> > +content:'johnny depp" \<must be in the content at least 3 times\>  
> > +size:[\* TO 600]  
> > )
> > 
> > In what way could we do the above query? Is there a way to do it with  
> > dismax? Is there some way to do it with terms, and if so, how do we get the  
> > right analyzer to run against the text in our client versus what is on  
> > elasticsearch?  
> > We are basically trying to say we think it is a match for Johnny Depp if  
> > he is in the text at least twice and the content size is small.  
> > The problem with just using scoring, is that we also match on some other  
> > fields in a constant way. if is present in a field, then you are  
> > also a match.  
> > So, how to combine that constant query along with something that is more  
> > of a scored query?

---

<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:28am UTC](https://discuss.elastic.co/t/question-on-query-combination/7726/4 "2017-07-06T03:28:11Z")

</div>

Closed on July 6, 2017, 3:28am UTC


