0
0
Elasticsearchquery~20 mins

Source filtering in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Source Filtering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this source filtering query?

Given the following Elasticsearch query that uses source filtering, what fields will be included in the response's _source?

Elasticsearch
{
  "_source": ["user", "post_date"],
  "query": {
    "match": {"message": "search"}
  }
}
AAll fields will be included because <code>_source</code> is ignored in this query.
BOnly the fields <code>user</code> and <code>post_date</code> will be included in <code>_source</code>.
COnly the <code>message</code> field will be included in <code>_source</code>.
DNo fields will be included in <code>_source</code> because the query filters them out.
Attempts:
2 left
💡 Hint

Think about what the _source array specifies in the query.

Predict Output
intermediate
2:00remaining
What fields are excluded by this source filtering?

Consider this Elasticsearch query snippet:

{
  "_source": { "excludes": ["comments", "metadata"] },
  "query": { "match_all": {} }
}

Which fields will not appear in the _source of the response?

AThe fields <code>comments</code> and <code>metadata</code> will be excluded from the response <code>_source</code>.
BAll fields will be included because excludes is ignored.
COnly the fields <code>comments</code> and <code>metadata</code> will be included.
DNo fields will be excluded; the query will return an empty <code>_source</code>.
Attempts:
2 left
💡 Hint

Look at what the excludes array does in _source.

🔧 Debug
advanced
2:00remaining
Why does this source filtering query cause an error?

Examine this Elasticsearch query:

{
  "_source": ["user", {"post_date"}],
  "query": { "match": {"message": "error"} }
}

What is the cause of the error?

AThe query is missing the <code>size</code> parameter.
BThe <code>match</code> query is missing a closing brace.
CThe <code>_source</code> field must be a string, not an array.
DThe <code>_source</code> array contains an invalid object instead of a string for field names.
Attempts:
2 left
💡 Hint

Check the format of the _source array elements.

🧠 Conceptual
advanced
2:00remaining
What is the effect of using _source: false in a query?

In Elasticsearch, what happens if you set "_source": false in your search query?

AThe query will return all fields in <code>_source</code> as usual.
BThe query will fail with a syntax error because <code>_source</code> cannot be false.
CThe response will not include the <code>_source</code> field at all, returning only metadata like <code>_id</code> and <code>_score</code>.
DThe query will include only the <code>_source</code> fields that are indexed.
Attempts:
2 left
💡 Hint

Think about what disabling _source means for the response.

Predict Output
expert
2:00remaining
How many fields are returned with this nested source filtering?

Given this Elasticsearch query:

{
  "_source": {
    "includes": ["user", "comments.text"],
    "excludes": ["user.email"]
  },
  "query": { "match_all": {} }
}

Assuming documents have fields user.name, user.email, comments.text, and comments.date, how many fields will appear in the _source of each hit?

A2 fields: <code>user.name</code> and <code>comments.text</code> (excluding <code>user.email</code>).
B3 fields: <code>user.name</code>, <code>user.email</code>, and <code>comments.text</code>.
COnly 1 field: <code>comments.text</code> because <code>user.email</code> is excluded and <code>user</code> is partially included.
DAll fields are returned because excludes are ignored when includes are used.
Attempts:
2 left
💡 Hint

Remember that excludes remove fields even if includes select their parent.