Complete the code to start a nested query on the field 'comments'.
{
"query": {
"nested": {
"path": "[1]"
}
}
}The nested query requires the path to specify the nested field. Here, 'comments' is the nested field.
Complete the code to add a match query inside the nested query for 'comments.author'.
{
"query": {
"nested": {
"path": "comments",
"query": {
"match": {
"comments.[1]": "Alice"
}
}
}
}
}Inside the nested query, you match on a field inside the nested objects. Here, 'author' is the correct field to match 'Alice'.
Fix the error in the nested query by completing the missing key for the inner query.
{
"query": {
"nested": {
"path": "comments",
"query": {
"[1]": {
"must": {
"match": {
"comments.text": "great"
}
}
}
}
}
}
}The inner query inside a nested query often uses a bool query to combine conditions. Here, the missing key is 'bool'.
Fill both blanks to create a nested query that filters comments with 'likes' greater than 10.
{
"query": {
"nested": {
"path": "comments",
"query": {
"range": {
"comments.[1]": {
"[2]": 10
}
}
}
}
}
}The range query filters on the 'likes' field with the operator 'gt' (greater than) 10.
Fill all three blanks to create a nested query that matches comments by 'author' 'Bob' and filters by 'date' after '2023-01-01'.
{
"query": {
"nested": {
"path": "comments",
"query": {
"bool": {
"must": [
{ "match": { "comments.[1]": "Bob" } },
{ "range": { "comments.[2]": { "[3]": "2023-01-01" } } }
]
}
}
}
}
}The bool query combines a match on 'author' and a range filter on 'date' with 'gte' (greater than or equal) to '2023-01-01'.