# Query into query

**URL:** <https://discuss.elastic.co/t/query-into-query/9061>\
**Category:** Elasticsearch\
**Created:** [September 19, 2012, 11:32am UTC](https://discuss.elastic.co/t/query-into-query/9061 "2012-09-19T11:32:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pere\_roca\_ristol](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@pere\_roca\_ristol](https://discuss.elastic.co/u/pere_roca_ristol)\
**Post date:** [September 19, 2012, 11:32am UTC](https://discuss.elastic.co/t/query-into-query/9061/1 "2012-09-19T11:32:42Z")

</div>

i have this query that works

"query": {"query\_string" :{ "fields" : ["family"], "query": "Apocynaceae  
Gentianaceae", "default\_operator" : "OR" } }

i want to use it inside another query (see other query below), so that I  
get the request that fit both filters.

I tried many different options ('filtered' and 'filter', put one query  
inside other query...) without success. Any help for a elasticsearch  
beginner?

thanks in advance,

curl -XGET  
http://my\_server:9200/idx\_occurrence/Occurrence/\_search?pretty=true -d '

{

"from" : 0, "size" : 10,

"query":

{

```
"bool" : {

  "must" : {

    "bool" : {

      "should" : {

        "bool" : {

          "must" : {

            "bool" : {

              "must" : [ {

                "range" : {

                  "decimalLatitude_interpreted" : {

                    "from" : 47,

                    "to" : 49,

                    "include_lower" : true,

                    "include_upper" : true

                  }

                }

              }, {

                "range" : {

                  "decimalLongitude_interpreted" : {

                    "from" : 6.9425781,

                    "to" : 7.790039,

                    "include_lower" : true,

                    "include_upper" : true

                  }

                }

              } ]

            }

          }

        }

      }

    }

  }

}

```

}

}'

--

---

<div class="post-metadata">

**Author:** ![pere\_roca\_ristol](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@pere\_roca\_ristol](https://discuss.elastic.co/u/pere_roca_ristol)\
**Post date:** [September 19, 2012, 12:58pm UTC](https://discuss.elastic.co/t/query-into-query/9061/2 "2012-09-19T12:58:56Z")

</div>

ok, i finally managed to get it work. Something like...

"query" : {  
"filtered":  
{  
"query":  
{  
"query\_string":  
{  
"fields" : ["family"], "query": "Apocynaceae Gentianaceae"",  
"default\_operator" : "AND"  
}  
}  
,  
"filter":  
{  
"query" : {  
"bool" : {  
..........

On Wednesday, 19 September 2012 13:32:42 UTC+2, pere roca ristol wrote:

> i have this query that works
> 
> "query": {"query\_string" :{ "fields" : ["family"], "query": "Apocynaceae  
> Gentianaceae", "default\_operator" : "OR" } }
> 
> i want to use it inside another query (see other query below), so that I  
> get the request that fit both filters.
> 
> I tried many different options ('filtered' and 'filter', put one query  
> inside other query...) without success. Any help for a elasticsearch  
> beginner?
> 
> thanks in advance,
> 
> curl -XGET  
> http://my\_server:9200/idx\_occurrence/Occurrence/\_search?pretty=true -d '
> 
> {
> 
> "from" : 0, "size" : 10,
> 
> "query":
> 
> {
> 
> ```
> "bool" : {
> 
> "must" : {
> 
> "bool" : {
> 
> "should" : {
> 
> "bool" : {
> 
> "must" : {
> 
> "bool" : {
> 
> "must" : [ {
> 
> "range" : {
> 
> "decimalLatitude_interpreted" : {
> 
> "from" : 47,
> 
> "to" : 49,
> 
> "include_lower" : true,
> 
> "include_upper" : true
> 
> }
> 
> }
> 
> }, {
> 
> "range" : {
> 
> "decimalLongitude_interpreted" : {
> 
> "from" : 6.9425781,
> 
> "to" : 7.790039,
> 
> "include_lower" : true,
> 
> "include_upper" : true
> 
> }
> 
> }
> 
> } ]
> 
> }
> 
> }
> 
> }
> 
> }
> 
> }
> 
> }
> 
> }
> 
> ```
> 
> }
> 
> }'

--

---

<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:12am UTC](https://discuss.elastic.co/t/query-into-query/9061/3 "2017-07-06T03:12:20Z")

</div>


