# Filter on outer object as well as Nested object

**URL:** <https://discuss.elastic.co/t/filter-on-outer-object-as-well-as-nested-object/14947>\
**Category:** Elasticsearch\
**Created:** [December 19, 2013, 9:40am UTC](https://discuss.elastic.co/t/filter-on-outer-object-as-well-as-nested-object/14947 "2013-12-19T09:40:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul1/32/46819_2.png) [@paul1](https://discuss.elastic.co/u/paul1)\
**Post date:** [December 19, 2013, 9:40am UTC](https://discuss.elastic.co/t/filter-on-outer-object-as-well-as-nested-object/14947/1 "2013-12-19T09:40:25Z")

</div>

My data looks like below .  
Need to filter on "progName" and "name"

{  
"name":"avinash",  
"assistance":"yes",  
"amount":10000,  
"programs":[  
{  
"progName":"Agriculture",  
"BachelorsProgs":53,  
"subs":[  
{  
"progName":"Agricultural Business",  
"BachelorsProgs":53  
}  
]  
},  
{  
"progName":"XYZ",  
"BachelorsProgs":12,  
"subs":[  
{  
"progName":"Agricultural Business",  
"BachelorsProgs":53  
}  
]  
}  
]  
}

My Mapping

{  
"mappings":{  
"university":{  
"properties":{  
"programs":{  
"type":"nested",  
"properties":{  
"progName":{  
"type":"multi\_field",  
"fields":{  
"facet":{  
"type":"string",  
"index":"not\_analyzed"  
},  
"progName":{  
"type":"string"  
}  
}  
}  
}  
}  
}  
}  
}  
}

when i query using below query i get exception

{  
"query":{  
"filtered":{  
"query":{  
"match\_all":{

```
        }
     },
     "filter":{
         "bool": {
         "must": [
            {"term": {
               "name": "avinash"
            }}
         ]
         },
        "nested":{
           "path":"programs",
           "filter":{
              "bool":{
                 "must":[
                    {
                       "term":{
                          "programs.progName":"bible"
                       }
                    },
                    {
                       "range":{
                          "programs.BachelorsProgs":{
                             "gt":0
                          }
                       }
                    }
                 ]
              }
           }
        }
     }
  }

```

}  
}

How do we filter on nested object as well as outer object in a single query

--  
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/6229cf27-bc30-4a32-9a87-6988bdd8a5bd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6229cf27-bc30-4a32-9a87-6988bdd8a5bd%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:** ![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, 2:00am UTC](https://discuss.elastic.co/t/filter-on-outer-object-as-well-as-nested-object/14947/2 "2017-07-06T02:00:18Z")

</div>

Closed on July 6, 2017, 2:00am UTC


