0
0
Elasticsearchquery~20 mins

Field and document level security in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Elasticsearch Security 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 Elasticsearch query with field level security?
Given the following role definition that restricts access to only the title and author fields, what fields will be returned in the search results?
Elasticsearch
{
  "indices": [
    {
      "names": ["books"],
      "privileges": ["read"],
      "field_security": {
        "grant": ["title", "author"]
      }
    }
  ]
}

Search query:
GET /books/_search
{
  "query": { "match_all": {} }
}
ANo fields will be returned because the query does not specify fields.
BAll fields will be returned because the query matches all documents.
COnly the <code>title</code> field will be returned because <code>author</code> is ignored.
DOnly the fields <code>title</code> and <code>author</code> will be returned in each document.
Attempts:
2 left
💡 Hint
Field level security controls which fields are visible in the search results.
Predict Output
intermediate
2:00remaining
What documents are returned with this document level security query?
Given a role with document level security defined as { "term": { "status": "published" } }, what documents will the user see when running GET /articles/_search?
Elasticsearch
{
  "indices": [
    {
      "names": ["articles"],
      "privileges": ["read"],
      "query": {
        "term": { "status": "published" }
      }
    }
  ]
}

Search query:
GET /articles/_search
{
  "query": { "match_all": {} }
}
ANo documents will be returned because the query is overridden.
BAll documents will be returned because the query matches all.
COnly documents where <code>status</code> is <code>published</code> will be returned.
DDocuments with any <code>status</code> except <code>published</code> will be returned.
Attempts:
2 left
💡 Hint
Document level security filters documents based on the query in the role.
🔧 Debug
advanced
2:00remaining
Why does this role not restrict access to the salary field as expected?
A role is defined to deny access to the salary field using except in field level security, but users still see the salary field in search results. What is the likely cause?
Elasticsearch
{
  "indices": [
    {
      "names": ["employees"],
      "privileges": ["read"],
      "field_security": {
        "except": ["salary"]
      }
    }
  ]
}
AThe <code>except</code> parameter is not supported; only <code>grant</code> works for field security.
BThe <code>salary</code> field is misspelled in the <code>except</code> list.
CThe role must also include a document level security query to hide <code>salary</code>.
DThe <code>except</code> parameter requires a wildcard pattern, not a field name.
Attempts:
2 left
💡 Hint
Check the official Elasticsearch documentation for supported field security parameters.
📝 Syntax
advanced
2:00remaining
Which role definition syntax correctly applies document level security to only show documents with department equal to sales?
Choose the correct JSON snippet for the role's indices section to enforce this document level security.
A
{
  "names": ["employees"],
  "privileges": ["read"],
  "document_level_security": {
    "term": { "department": "sales" }
  }
}
B
{
  "names": ["employees"],
  "privileges": ["read"],
  "query": {
    "term": { "department": "sales" }
  }
}
C
{
  "names": ["employees"],
  "privileges": ["read"],
  "filter": {
    "term": { "department": "sales" }
  }
}
D
{
  "names": ["employees"],
  "privileges": ["read"],
  "query": {
    "match": { "department": "sales" }
  }
}
Attempts:
2 left
💡 Hint
Document level security uses the query field inside the indices section.
🚀 Application
expert
3:00remaining
How to combine field and document level security to restrict access to salary field and only active employees?
You want to create a role that: - Allows reading only name and position fields (hide salary) - Shows only documents where status is active Which role definition correctly implements both restrictions?
A
{
  "indices": [
    {
      "names": ["employees"],
      "privileges": ["read"],
      "field_security": { "grant": ["name", "position"] },
      "query": { "term": { "status": "active" } }
    }
  ]
}
B
{
  "indices": [
    {
      "names": ["employees"],
      "privileges": ["read"],
      "field_security": { "grant": ["name", "position", "salary"] },
      "query": { "term": { "status": "active" } }
    }
  ]
}
C
{
  "indices": [
    {
      "names": ["employees"],
      "privileges": ["read"],
      "field_security": { "except": ["salary"] },
      "query": { "match": { "status": "active" } }
    }
  ]
}
D
{
  "indices": [
    {
      "names": ["employees"],
      "privileges": ["read"],
      "field_security": { "grant": ["name", "position"] },
      "query": { "term": { "status": "inactive" } }
    }
  ]
}
Attempts:
2 left
💡 Hint
Use grant for allowed fields and query for document filtering.