Bird
Raised Fist0

A user tries to monitor disk usage but gets an error:

medium📝 Troubleshoot Q7 of Q15
Elasticsearch - ELK Stack Integration
A user tries to monitor disk usage but gets an error:
GET /metrics/_search
{
  "query": {
    "match": { "disk_usage": "high" }
  },
  "aggs": {
    "avg_disk": {
      "avg": {
        "field": "disk_usage"
      }
    }
  }
}

The error says 'fielddata is disabled on text fields'. What is the best fix?
AEnable fielddata on 'disk_usage' field in mapping
BUse a range query instead of match
CRemove the 'disk_usage' field from the query
DChange the mapping of 'disk_usage' to keyword type
Step-by-Step Solution
Solution:
  1. Step 1: Understand the error about fielddata on text fields

    Text fields do not support aggregations or sorting unless mapped as keyword or fielddata enabled.
  2. Step 2: Choose the best practice

    Changing mapping to keyword type is recommended for exact matches and aggregations.
  3. Final Answer:

    Change the mapping of 'disk_usage' to keyword type -> Option D
  4. Quick Check:

    Fielddata error fix = Use keyword mapping [OK]
Quick Trick: Use keyword type for exact match fields [OK]
Common Mistakes:
MISTAKES
  • Trying to enable fielddata which is costly
  • Using range query on text field incorrectly
  • Removing field instead of fixing mapping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes