# Nested: SearchParseException when query to non-existing type

**URL:** <https://discuss.elastic.co/t/nested-searchparseexception-when-query-to-non-existing-type/28415>\
**Category:** Elasticsearch\
**Created:** [September 1, 2015, 9:43am UTC](https://discuss.elastic.co/t/nested-searchparseexception-when-query-to-non-existing-type/28415 "2015-09-01T09:43:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [September 1, 2015, 9:43am UTC](https://discuss.elastic.co/t/nested-searchparseexception-when-query-to-non-existing-type/28415/1 "2015-09-01T09:43:33Z")

</div>

I create an index with multiple types all of which has a nested field defined as follows:

```
"AssocQueries": {
    "type": "nested",
    "properties": {
        "Term": {
            "type": "string",
            "fields": {
                "exact": {
                    "type": "string", "analyzer": "lowercase_keyword"
                }
            }
        },
        "Count": {
            "type": "long"
        }
    }
},

```

And in queries to all type, there is a nested query with function score as follows:  
{  
"nested": {  
"path": "AssocQueries",  
"query": {  
"function\_score": {  
"query": {  
"match": {  
"exact": "blah blah..."  
}  
},  
functions: [{  
}],  
}  
}  
}  
}

The problem is, if I send the query to a non-existing type, example, localhost:9200/myindex/badtype/\_search, I will get exception:  
[nested] failed to find nested object under path [AssocQueries]]

I know I can check if the type is valid before run the query, but is there any other simple ways to avoid such exception even send query to an invalid type?

---

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [September 3, 2015, 6:43am UTC](https://discuss.elastic.co/t/nested-searchparseexception-when-query-to-non-existing-type/28415/2 "2015-09-03T06:43:23Z")

</div>

Any suggestion?  
Somehow, I think it is ES's bug, since it should simply return empty result if the type does not exist. Actually, ES has different behavior for non-existing type query. If I remove the function score part from the query, the request won't throw exception for non-existing type.

---

<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 5, 2017, 11:52pm UTC](https://discuss.elastic.co/t/nested-searchparseexception-when-query-to-non-existing-type/28415/3 "2017-07-05T23:52:24Z")

</div>


