0
0
Elasticsearchquery~20 mins

Dynamic vs explicit mapping in Elasticsearch - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Mapping 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 dynamic mapping example?

Given the following Elasticsearch mapping and document indexing, what will be the type of the age field in the index?

{
  "mappings": {
    "dynamic": true
  }
}

Document:
{
  "name": "Alice",
  "age": 30
}
AThe document will fail to index due to missing explicit mapping.
B"age" will be mapped as a <code>text</code> type by default.
C"age" will be mapped as a <code>long</code> type automatically.
D"age" will be mapped as a <code>keyword</code> type automatically.
Attempts:
2 left
💡 Hint

Dynamic mapping tries to guess the field type based on the value.

Predict Output
intermediate
2:00remaining
What happens when explicit mapping conflicts with dynamic mapping?

Given this explicit mapping and a document, what will be the type of the price field?

{
  "mappings": {
    "properties": {
      "price": { "type": "keyword" }
    },
    "dynamic": true
  }
}

Document:
{
  "price": 19.99
}
A"price" will be mapped as <code>text</code> by dynamic mapping.
B"price" will be mapped as <code>keyword</code> as per explicit mapping, ignoring dynamic mapping.
C"price" will be mapped as <code>float</code> because the document value is a number.
DThe document will fail to index due to type conflict.
Attempts:
2 left
💡 Hint

Explicit mappings override dynamic mapping for specified fields.

🔧 Debug
advanced
2:00remaining
Why does this dynamic mapping cause a runtime error?

Consider this mapping and document indexing attempt:

{
  "mappings": {
    "dynamic": "strict"
  }
}

Document:
{
  "title": "Book",
  "pages": 250
}

What error will Elasticsearch raise when indexing this document?

AElasticsearch will raise a <code>strict_dynamic_mapping_exception</code> because <code>pages</code> is not defined in mapping.
BElasticsearch will index the document successfully with dynamic mapping.
CElasticsearch will ignore the <code>pages</code> field silently.
DElasticsearch will raise a <code>mapper_parsing_exception</code> due to invalid field type.
Attempts:
2 left
💡 Hint

Strict dynamic mapping forbids new fields not defined explicitly.

🧠 Conceptual
advanced
2:00remaining
How does explicit mapping improve search performance compared to dynamic mapping?

Which of the following best explains why explicit mapping can improve Elasticsearch search performance?

AExplicit mapping forces Elasticsearch to reindex data on every search.
BExplicit mapping disables indexing, so searches are faster.
CExplicit mapping automatically caches all fields, speeding up searches.
DExplicit mapping defines field types and analyzers upfront, allowing optimized indexing and queries.
Attempts:
2 left
💡 Hint

Think about how knowing field types helps Elasticsearch.

Predict Output
expert
2:00remaining
What is the number of fields indexed with this mixed mapping?

Given this mapping and document, how many fields will be indexed?

{
  "mappings": {
    "dynamic": false,
    "properties": {
      "user": { "type": "keyword" },
      "message": { "type": "text" }
    }
  }
}

Document:
{
  "user": "bob",
  "message": "Hello world",
  "timestamp": "2024-06-01T12:00:00Z"
}
A2 fields will be indexed: <code>user</code> and <code>message</code> only.
B3 fields will be indexed including <code>timestamp</code>.
COnly 1 field will be indexed because <code>dynamic</code> is false.
DNo fields will be indexed due to <code>dynamic</code> false.
Attempts:
2 left
💡 Hint

Dynamic false disables indexing of fields not explicitly mapped.