Ravindra BagaleCourses & study guides मराठी

Chapter 95: Logging with Loki, Elastic Stack and CloudWatch

DevOps

95.9 Elasticsearch — index, mapping, text and keyword

Story (fictional teaching scenario). At a fictional Surat firm, Grace from Leeds finds that one producer sends status as a number and another sends a word. The team fixes the schema instead of blaming the search bar.

Elasticsearch — index, mapping, text and keyword
Elasticsearch — index, mapping, text and keyword

Why

Field types decide which comparisons and searches make sense.

What

  • An index is a logical collection of documents and associated search structures.
  • A mapping defines field types and indexing behaviour.
  • keyword supports exact-value matching; text is analyzed for full-text search.
  • A date field represents time; an integer/long supports numeric ranges.
  • Dynamic mapping infers new fields. Uncontrolled field names can cause mapping explosion, meaning too many mapped fields.

How

  1. Define known fields explicitly for predictable queries.

  2. Keep exact categories in keyword fields.

  3. Keep numeric fields numeric.

  4. Review unrecognized fields; many existing type changes require reindexing rather than an in-place switch.

Example 1: Mapping body only — not an executed create request

  1. Read the command or request.
{"mappings":{"properties":{"ts":{"type":"date"},"service":{"type":"keyword"},"level":{"type":"keyword"},"request_id":{"type":"keyword"},"status":{"type":"integer"},"latency_ms":{"type":"long"}}}}
  1. Read the result.

Output (illustrative; NOT executed against Loki, Elastic or CloudWatch)

Exact category filters and numeric comparisons have planned field types.
  1. Line by line: mappings.properties lists field definitions. ts is date. The three categories/IDs are keyword. status and latency_ms are numbers. This body does not ingest data by itself and was not sent anywhere. Explicit known fields do not automatically block all new fields; configure dynamic-field behaviour separately when needed.

Ravindra Bagale's Tip

A quoted number in JSON is not the same type as a number.

Did you understand? Let us try it once more.