# Search query exception "org.elasticsearch.index.query.QueryShardException: failed to create query"

**URL:** <https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820>\
**Category:** Elasticsearch\
**Created:** [March 31, 2020, 8:55am UTC](https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820 "2020-03-31T08:55:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suchita\_Gangurde](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suchita_gangurde/32/45032_2.png) [@Suchita\_Gangurde](https://discuss.elastic.co/u/Suchita_Gangurde)\
**Post date:** [March 31, 2020, 8:55am UTC](https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820/1 "2020-03-31T08:55:33Z")

</div>

Hello,  
I am using elasticsearch version 7.3.1, on my local setup search query execution works fine.  
But the same query using docker image for es version 7.3.1 on kubernetes recently I am facing following exception:  
"message": "All shards failed for phase: [query]" ,  
stacktrace": ["org.elasticsearch.index.query.QueryShardException: failed to create query: {",  
"bool" : {",  
"must" : [",  
{",  
"term" : {",  
"username" : {",  
"value" : "12345",",  
"boost" : 1.0",  
}",  
}",  
},",  
{",  
"nested" : {",  
"query" : {",  
"exists" : {",  
"field" : "email\_addresses.value",",  
"boost" : 1.0",  
}",  
},",  
"path" : "email\_addresses",",  
"ignore\_unmapped" : false,",  
"score\_mode" : "avg",",  
"boost" : 1.0",  
}",  
}",  
],",  
"should" : [",  
{",  
"nested" : {",  
"query" : {",  
"multi\_match" : {",  
"query" : "abc",",  
"fields" : [",  
"email\_addresses.value^3.0",",  
"family\_name^1.0",",  
"given\_name^2.0"",  
],",  
"type" : "bool\_prefix",",  
"operator" : "OR",",  
"slop" : 0,",  
"prefix\_length" : 0,",  
"max\_expansions" : 50,",  
"zero\_terms\_query" : "NONE",",  
"auto\_generate\_synonyms\_phrase\_query" : true,",  
"fuzzy\_transpositions" : true,",  
"boost" : 1.0",  
}",  
},",  
"path" : "email\_addresses",",  
"ignore\_unmapped" : false,",  
"score\_mode" : "avg",",  
"boost" : 1.0",  
}", },",  
{",  
"multi\_match" : {",  
"query" : "abc",",  
"fields" : [",  
"email\_addresses.value^3.0",",  
"family\_name^1.0",",  
"given\_name^2.0"",  
],",  
"type" : "bool\_prefix",",  
"operator" : "OR",",  
"slop" : 0,",  
"prefix\_length" : 0,",  
"max\_expansions" : 50,",  
"zero\_terms\_query" : "NONE",",  
"auto\_generate\_synonyms\_phrase\_query" : true,",  
"fuzzy\_transpositions" : true,",  
"boost" : 1.0",  
}",  
}",  
],",  
"adjust\_pure\_negative" : true,",  
"minimum\_should\_match" : "1",",  
"boost" : 1.0",  
}",  
}",  
"Caused by: java.lang.IllegalStateException: [nested] nested object under path [email\_addresses] is not of nested type",

Please help

---

<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:** [March 31, 2020, 9:10am UTC](https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820/2 "2020-03-31T09:10:40Z")

</div>

Welcome.

Here `email_addresses` is not of `nested` type in your mapping. So you can't use `nested` queries.

---

<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:** [March 31, 2020, 9:11am UTC](https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820/3 "2020-03-31T09:11:00Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.

---

<div class="post-metadata">

**Author:** ![Suchita\_Gangurde](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suchita_gangurde/32/45032_2.png) [@Suchita\_Gangurde](https://discuss.elastic.co/u/Suchita_Gangurde)\
**Post date:** [April 1, 2020, 4:44pm UTC](https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820/4 "2020-04-01T16:44:16Z")

</div>

`Thanks for your reply, could you please elaborate of what do you mean by email_addresses is not of nested type?`

---

<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:** [April 1, 2020, 5:12pm UTC](https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820/5 "2020-04-01T17:12:09Z")

</div>

That's a guess. Check the mapping.

---

<div class="post-metadata">

**Author:** ![Suchita\_Gangurde](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suchita_gangurde/32/45032_2.png) [@Suchita\_Gangurde](https://discuss.elastic.co/u/Suchita_Gangurde)\
**Post date:** [April 1, 2020, 5:57pm UTC](https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820/6 "2020-04-01T17:57:13Z")

</div>

But same query with same elasticsearch version works on local machine setup. Is there anything I am missing

---

<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:** [April 1, 2020, 7:12pm UTC](https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820/7 "2020-04-01T19:12:58Z")

</div>

What is the mapping in both cases?

---

<div class="post-metadata">

**Author:** ![Suchita\_Gangurde](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suchita_gangurde/32/45032_2.png) [@Suchita\_Gangurde](https://discuss.elastic.co/u/Suchita_Gangurde)\
**Post date:** [April 2, 2020, 4:55am UTC](https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820/8 "2020-04-02T04:55:32Z")

</div>

Thank you so much for your pointer there was different mappings due to which search was failing it is working for me now.

---

<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:** [April 30, 2020, 4:55am UTC](https://discuss.elastic.co/t/search-query-exception-org-elasticsearch-index-query-queryshardexception-failed-to-create-query/225820/9 "2020-04-30T04:55:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
