Bird
Raised Fist0
Elasticsearchquery~10 mins

Boolean and binary types in Elasticsearch - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Boolean and binary types
Start
↓
Define Field Type
↓
Boolean Type
↓
Accepts true/false
↓
Stores as true/false
↓
Binary Type
↓
Accepts base64 strings
↓
Stores as binary data
↓
Use in documents
↓
Query & Retrieve
↓
End
This flow shows how Elasticsearch handles Boolean and Binary types: defining fields, accepting values, storing them, and using them in documents.
Execution Sample
Elasticsearch
PUT /my_index
{
  "mappings": {
    "properties": {
      "is_active": {"type": "boolean"},
      "file_data": {"type": "binary"}
    }
  }
}
Defines an index with a boolean field 'is_active' and a binary field 'file_data'.
Execution Table
StepActionFieldInput ValueStored ValueNotes
1Define boolean fieldis_activeN/AN/AField type set to boolean
2Define binary fieldfile_dataN/AN/AField type set to binary
3Index documentis_activetruetrueBoolean true stored as true
4Index documentfile_data"SGVsbG8="<binary data>Base64 string decoded and stored
5Retrieve documentis_activeN/AtrueBoolean value retrieved as true
6Retrieve documentfile_dataN/A"SGVsbG8="Binary data returned as base64 string
7ExitN/AN/AN/AAll fields processed successfully
💡 All fields defined and data indexed and retrieved successfully.
Variable Tracker
VariableStartAfter Step 3After Step 4After Step 5After Step 6Final
is_activeundefinedtruetruetruetruetrue
file_dataundefinedundefined<binary data><binary data>"SGVsbG8=""SGVsbG8="
Key Moments - 2 Insights
Why does the binary field store base64 strings but return base64 strings on retrieval?
Because Elasticsearch expects binary data to be sent as base64 strings, it decodes and stores the raw binary internally, but when retrieving, it encodes the binary back to base64 for safe transport. See execution_table rows 4 and 6.
Can the boolean field accept strings like "true" or only boolean true/false?
Elasticsearch accepts boolean values true or false directly. Strings like "true" are converted internally if possible, but best practice is to send actual boolean values. See execution_table row 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4, what is the input value for the binary field?
A"SGVsbG8="
Btrue
C<binary data>
Dfalse
💡 Hint
Check the 'Input Value' column at step 4 in the execution_table.
At which step is the boolean value retrieved from the index?
AStep 3
BStep 6
CStep 5
DStep 2
💡 Hint
Look for 'Retrieve document' action for 'is_active' field in execution_table.
If you send the string "false" instead of boolean false to the boolean field, what likely happens?
AIt stores as string "false"
BIt stores as boolean false
CIt causes an error
DIt stores as boolean true
💡 Hint
Refer to key_moments about boolean field input handling.
Concept Snapshot
Boolean and binary types in Elasticsearch:
- Boolean fields store true/false values.
- Binary fields store base64-encoded binary data.
- Binary input must be base64 strings; stored as raw binary.
- Retrieval of binary fields returns base64 strings.
- Boolean fields accept true/false values directly.
Full Transcript
This visual execution trace shows how Elasticsearch handles Boolean and Binary types. First, fields are defined with their types. Boolean fields accept true or false values and store them as such. Binary fields accept base64 encoded strings, decode them to store raw binary data, and return base64 strings when retrieved. The execution table traces defining fields, indexing documents with these fields, and retrieving them. Variable tracking shows how values change through steps. Key moments clarify common confusions about input formats and storage. The quiz tests understanding of input values, retrieval steps, and type handling. The snapshot summarizes key points about these types in Elasticsearch.

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