Bird
0
0

You want to store a list of addresses for a user, each with street, city, and zip code, and query each address independently. How should you define the mapping?

hard🚀 Application Q8 of 15
Elasticsearch - Mappings and Data Types
You want to store a list of addresses for a user, each with street, city, and zip code, and query each address independently. How should you define the mapping?
A"addresses": { "type": "text" }
B"addresses": { "type": "nested", "properties": {"street": {"type": "text"}, "city": {"type": "keyword"}, "zip": {"type": "keyword"}}}
C"addresses": { "type": "object", "properties": {"street": {"type": "text"}, "city": {"type": "keyword"}, "zip": {"type": "keyword"}}}
D"addresses": { "type": "keyword" }
Step-by-Step Solution
Solution:
  1. Step 1: Identify need for independent querying

    Since each address must be queried independently, nested type is required.
  2. Step 2: Check mapping details

    "addresses": { "type": "nested", "properties": {"street": {"type": "text"}, "city": {"type": "keyword"}, "zip": {"type": "keyword"}}} correctly defines addresses as nested with proper properties. "addresses": { "type": "object", "properties": {"street": {"type": "text"}, "city": {"type": "keyword"}, "zip": {"type": "keyword"}}} uses object type which does not isolate objects. Options A and D are incorrect types.
  3. Final Answer:

    Use nested type with properties for addresses -> Option B
  4. Quick Check:

    Nested type needed for independent queries on object arrays [OK]
Quick Trick: Use nested type for arrays of objects needing separate queries [OK]
Common Mistakes:
MISTAKES
  • Using object type for independent queries
  • Defining addresses as text or keyword
  • Missing properties inside nested mapping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes