I'm using ElasticSearch 5.5.1. I want to query a document that has nested objects. I will quote a popular example documented well in the ElasticSearch community.
The nested documents are:
[
{
"name":"Bob",
"car":[ <!-- Nested -->
{
"make":"Saturn",
"model":"Imprezza"
}
]
},
{
"name":"Zach",
"car":[ <!-- Nested -->
{
"make":"Saturn",
"model":"SL"
},
{
"make":"Subaru",
"model":"Imprezza"
}
]
}
]
The query:
{
"query": {
"bool": {
"must": [
{
"term": {
"name": {
"value": "bob"
}
}
}
]
}
}
}
Works as expected and the nested query:
{
"query": {
"nested": {
"path": "car",
"query": {
"bool": {
"must": [
{
"match": {
"car.make": "Saturn"
}
},
{
"match": {
"car.model": "SL"
}
}
]
}
}
}
}
}
Works well too. However, the combination of the above two queries fails to work.
{
"query": {
"bool": {
"must": [
{
"term": {
"name": {
"value": "bob"
}
}
}
]
},
"nested": {
"path": "car",
"query": {
"bool": {
"must": [
{
"match": {
"car.make": "Saturn"
}
},
{
"match": {
"car.model": "SL"
}
}
]
}
}
}
}
}
It results in the following error message.
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 14,
"col": 7
}
],
"type": "parsing_exception",
"reason": "[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 14,
"col": 7
},
"status": 400
}
Any idea what could be the problem here? Your help will be greatly appreciated.