Bird
Raised Fist0
Elasticsearchquery~20 mins

Boolean and binary types in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Boolean and Binary Mastery
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 a boolean filter?

Consider the following Elasticsearch query that filters documents based on a boolean field is_active. What documents will be returned?

Elasticsearch
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "is_active": true } }
      ]
    }
  }
}
AAll documents regardless of <code>is_active</code> value
BOnly documents where the field <code>is_active</code> is true
COnly documents where the field <code>is_active</code> is false
DDocuments where <code>is_active</code> field is missing
Attempts:
2 left
💡 Hint

Think about what the term filter does with boolean fields.

❓ Predict Output
intermediate
2:00remaining
What is the result of indexing a binary field with base64 data?

You index a document with a binary field file_data containing base64 encoded string. What happens when you retrieve this field?

Elasticsearch
{
  "mappings": {
    "properties": {
      "file_data": { "type": "binary" }
    }
  }
}
AThe field returns the original base64 encoded string exactly as indexed
BThe field returns the decoded binary data as a string
CThe field returns a JSON error because binary data is not supported
DThe field is not stored and returns null
Attempts:
2 left
💡 Hint

Remember how Elasticsearch stores binary fields internally.

🔧 Debug
advanced
2:00remaining
Why does this boolean query return no results?

Given this query, why might it return zero documents even though some documents have is_verified set to false?

Elasticsearch
{
  "query": {
    "bool": {
      "must": [
        { "term": { "is_verified": false } }
      ]
    }
  }
}
AThe <code>term</code> query does not match <code>false</code> because the field is mapped as a string, not boolean
BThe <code>must</code> clause requires documents to have <code>is_verified</code> true, so false matches nothing
CThe query syntax is invalid and causes an error
DThe <code>term</code> query matches only <code>true</code> values by default
Attempts:
2 left
💡 Hint

Check the field mapping type and how term queries work with booleans.

📝 Syntax
advanced
2:00remaining
Which option correctly defines a binary field in Elasticsearch mapping?

Choose the correct JSON snippet to define a binary field named image_data in an Elasticsearch index mapping.

A"image_data": { "type": "base64" }
B"image_data": { "type": "byte" }
C"image_data": { "type": "boolean" }
D"image_data": { "type": "binary" }
Attempts:
2 left
💡 Hint

Recall the exact type name Elasticsearch uses for binary data.

🚀 Application
expert
2:00remaining
How many documents will match this boolean query with must_not clause?

Assume an index with 100 documents: 60 have is_active true, 40 have is_active false. What is the count of documents returned by this query?

{
  "query": {
    "bool": {
      "must_not": [
        { "term": { "is_active": true } }
      ]
    }
  }
}
A100
B60
C40
D0
Attempts:
2 left
💡 Hint

The must_not clause excludes documents matching the condition.

Practice

(1/5)
1. What type of data does the boolean type in Elasticsearch store?
easy
A. True or false values
B. Text strings
C. Numbers with decimals
D. Base64 encoded files

Solution

  1. Step 1: Understand the boolean type purpose

    The boolean type is designed to store values that represent true or false states.
  2. Step 2: Compare with other data types

    Text strings, numbers, and base64 encoded files are stored in different types like text, float, or binary, not boolean.
  3. Final Answer:

    True or false values -> Option A
  4. Quick Check:

    Boolean = true/false [OK]
Hint: Boolean means true or false only [OK]
Common Mistakes:
  • Confusing boolean with text or number types
  • Thinking boolean stores encoded files
  • Assuming boolean can hold multiple values
2. Which of the following is the correct way to define a binary field in an Elasticsearch mapping?
easy
A. { "my_field": {"type": "text"} }
B. { "my_field": {"type": "boolean"} }
C. { "my_field": {"type": "binary"} }
D. { "my_field": {"type": "integer"} }

Solution

  1. Step 1: Identify the binary type syntax

    In Elasticsearch, a binary field is defined with "type": "binary" inside the mapping.
  2. Step 2: Check other options

    Options A, B, and D define other types (text, boolean, integer) which are not binary.
  3. Final Answer:

    { "my_field": {"type": "binary"} } -> Option C
  4. Quick Check:

    Binary type uses "type": "binary" [OK]
Hint: Binary type always uses "type": "binary" in mapping [OK]
Common Mistakes:
  • Using boolean or text instead of binary
  • Missing quotes around type name
  • Incorrect JSON structure
3. Given this Elasticsearch document mapping and data:
{
  "mappings": {
    "properties": {
      "is_active": {"type": "boolean"},
      "file_data": {"type": "binary"}
    }
  }
}

Document:
{
  "is_active": true,
  "file_data": "SGVsbG8gd29ybGQ="
}

What will be the value of is_active when retrieved?
medium
A. null
B. true
C. false
D. "SGVsbG8gd29ybGQ="

Solution

  1. Step 1: Understand the boolean field value

    The field "is_active" is boolean and set to true in the document.
  2. Step 2: Confirm retrieval value

    When retrieved, the boolean field returns the stored true value, not the binary data or null.
  3. Final Answer:

    true -> Option B
  4. Quick Check:

    Boolean field returns true/false as stored [OK]
Hint: Boolean fields return true or false as stored [OK]
Common Mistakes:
  • Confusing binary field value with boolean
  • Expecting base64 string for boolean field
  • Assuming null if not explicitly queried
4. You have this Elasticsearch mapping snippet:
{
  "properties": {
    "flag": {"type": "boolean"},
    "data": {"type": "binary"}
  }
}

Which of the following is a mistake that will cause an error when indexing a document?
medium
A. {"flag": "yes", "data": "dGVzdA=="}
B. {"flag": true, "data": "dGVzdA=="}
C. {"flag": false, "data": ""}
D. {"flag": false, "data": "dGVzdA=="}

Solution

  1. Step 1: Check boolean field value types

    The boolean field "flag" must be true or false, not strings like "yes".
  2. Step 2: Validate binary field values

    The binary field "data" expects base64 encoded strings, which "dGVzdA==" is valid for.
  3. Final Answer:

    {"flag": "yes", "data": "dGVzdA=="} -> Option A
  4. Quick Check:

    Boolean must be true/false, not string [OK]
Hint: Boolean fields accept only true or false, not strings [OK]
Common Mistakes:
  • Using string 'yes' or 'no' for boolean
  • Passing non-base64 strings to binary fields
  • Leaving binary field empty without quotes
5. You want to store user profile pictures in Elasticsearch using the binary type and also keep a flag if the user is verified using boolean. Which of the following mapping and document pairs is correct and efficient?
hard
A. { "mappings": { "properties": { "profile_pic": {"type": "text"}, "verified": {"type": "boolean"} } } } Document: { "profile_pic": "iVBORw0KGgoAAAANSUhEUgAAAAUA", "verified": "yes" }
B. { "mappings": { "properties": { "profile_pic": {"type": "binary"}, "verified": {"type": "boolean"} } } } Document: { "profile_pic": "not_base64_data", "verified": true }
C. { "mappings": { "properties": { "profile_pic": {"type": "binary"}, "verified": {"type": "text"} } } } Document: { "profile_pic": "iVBORw0KGgoAAAANSUhEUgAAAAUA", "verified": false }
D. { "mappings": { "properties": { "profile_pic": {"type": "binary"}, "verified": {"type": "boolean"} } } } Document: { "profile_pic": "iVBORw0KGgoAAAANSUhEUgAAAAUA", "verified": true }

Solution

  1. Step 1: Check mapping types for fields

    The profile picture should be stored as binary type with base64 data, and verified as boolean true/false.
  2. Step 2: Validate document values

    { "mappings": { "properties": { "profile_pic": {"type": "binary"}, "verified": {"type": "boolean"} } } } Document: { "profile_pic": "iVBORw0KGgoAAAANSUhEUgAAAAUA", "verified": true } uses binary type with base64 string and boolean true, which is correct and efficient.
  3. Step 3: Identify errors in other options

    { "mappings": { "properties": { "profile_pic": {"type": "text"}, "verified": {"type": "boolean"} } } } Document: { "profile_pic": "iVBORw0KGgoAAAANSUhEUgAAAAUA", "verified": "yes" } uses text for binary and string "yes" for boolean, which is incorrect.
    { "mappings": { "properties": { "profile_pic": {"type": "binary"}, "verified": {"type": "text"} } } } Document: { "profile_pic": "iVBORw0KGgoAAAANSUhEUgAAAAUA", "verified": false } uses text for boolean field.
    { "mappings": { "properties": { "profile_pic": {"type": "binary"}, "verified": {"type": "boolean"} } } } Document: { "profile_pic": "not_base64_data", "verified": true } has invalid base64 data for binary field.
  4. Final Answer:

    Mapping and document with binary and boolean types correctly used -> Option D
  5. Quick Check:

    Binary = base64, Boolean = true/false [OK]
Hint: Binary needs base64 data; boolean must be true or false [OK]
Common Mistakes:
  • Using text type for binary data
  • Passing non-base64 strings to binary fields
  • Using strings like 'yes' for boolean fields
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard