-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi level nested objects inner_hits
not working (only root level working)
#13064
Comments
@ranadeeppolavarapu the This issue is related to this ticket: #11118 |
Closing as duplicate of #11118 |
@ranadeeppolavarapu the following query should work:
Downside that It is more verbose, because the query needs to be repeated on each nested level. When the embedded query dsl |
+1 |
This bug is closed as well as #11118, but the original example from @ranadeeppolavarapu still doesn't work on 2.4. Should it be reopen again? |
@black-square The bug was only fixed in 5.0.x. Fixing it required a refactoring that didn't make its way back in 2.4 |
Hi Guys, POST /test_word14/doc/1 (mapping file) please tell me what is the query i am applying here.i am applying the query like this: |
when i am running your example then it is not working it's showing like that:Unknown key for a START_OBJECT in [inner_hits] |
Multi-level nested queries with Create the test indexcurl -XPUT "http://localhost:9200/test_index_github" -H 'Content-Type: application/json' -d'
{
"settings" : {
"index" : {
"number_of_shards" : 10,
"number_of_replicas" : 1
}
}
}
'
curl -XPUT "http://localhost:9200/test_index_github/_mapping" -H 'Content-Type: application/json' -d'
{
"properties": {
"cars": {
"type": "nested",
"properties": {
"manufacturers": {
"type": "nested",
"properties": {
"country": {
"type": "text"
},
"name": {
"type": "text"
}
}
},
"model": {
"type": "text"
},
"make": {
"type": "text"
}
}
},
"last_name": {
"type": "text"
},
"first_name": {
"type": "text"
}
}
}
'
curl -XPUT "http://localhost:9200/test_index_github/_doc/0" -H 'Content-Type: application/json' -d'
{
"first_name": "Zach",
"last_name": "Foobar",
"cars": [
{
"make": "Saturn",
"model": "SL",
"manufacturers": [
{
"name": "Saturn",
"country": "USA"
},
{
"name": "Honda",
"country": "Canada"
}
]
},
{
"make": "Subaru",
"model": "Imprezza",
"manufacturers": [
{
"name": "Subaru",
"country": "Japan"
},
{
"name": "Daimler",
"country": "Germany"
}
]
}
]
}
' Query the test index:curl -XPOST "http://localhost:9200/test_index_github/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"nested": {
"path": "cars",
"query": {
"nested": {
"path": "cars.manufacturers",
"query": {
"match": {
"cars.manufacturers.country": "Japan"
}
},
"inner_hits": {}
}
},
"inner_hits": {}
}
}
}
' Result:
|
Oh I see—the syntax has changed to accommodate this capability: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/inner-hits.html Key sentence: "This indirect referencing is only supported for nested inner hits." This query works: curl -XPOST "http://localhost:9200/test_index_github/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"nested": {
"path": "cars.manufacturers",
"query": {
"match": {
"cars.manufacturers.country": "Japan"
}
},
"inner_hits": {}
}
}
}
' |
.
The text was updated successfully, but these errors were encountered: