I'm storing objects in elasticsearch like this
{
"user":{
"name":"Johnson",
"age":24
}
}
Please note that I do not have a default mapping set in elasticsearch. I'm simply inserting the data directly.
Now, While using "nested query" to try to query the data.
GET user_index/user_document/_search
{
"query":{
"nested" : {
"path" : "user",
"score_mode" : "avg",
"query" : {
"bool" : {
"must" : [
{
"match" : {"user.name" : "Johnson"}
}
]
}
}
}
}
}
This fails and i get an error
nested object under path [user] is not of nested type
My Questions are
- Should i create a default mapping for querying nested objects?
Why can't a query like this below (which works) be used instead?
GET user_index/_search { "query":{ "match":{ "user.name":"Johnson" } } }