How can i fetch nested object in elastic search ?
{
"_index": "userinfo",
"_type": "userdetails",
"_id": "2",
"_score": 1,
"_source": {
"id": "2",
"name": "Robert Mark",
"age": 42,
"email": "robert.mark@ceb.com",
"userType": {
"id": "3",
"type": "End User"
},
"hobbies": [
{
"id": "3",
"description": "Writing Books"
},
{
"id": "4",
"description": "Gardening"
}
]
}
}
This is my json structure i want to fetch all the records where description under hobbies are "Gardening" .
I am new to elastic search please help me for this if any one knows .
"description": "Gardening"
This is your query:
{
"query": {
"nested": {
"path": "hobbies",
"query": {
"match": {
"hobbies.description": "Gardening"
}
}
}
}
}
israelst is correct if you precreated a nested
mapping type for your hobbies object. By default though, it uses object
instead of `nested.
{
"query" : {
"match" : {
"hobbies.description" : "Gardening"
}
}
}
Note that the queries are practically the same and, in fact, my example is a subset of the nested version.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.