Big Data 20 min read

Elasticsearch Mapping, Data Types, and Document Operations Guide

This article explains how to define Elasticsearch mappings, use automatic and manual mapping, work with basic data types, multi‑fields and predefined fields, and perform document updates, version‑based concurrency control, and deletions, providing practical curl examples for each operation.

Big Data Technology & Architecture
Big Data Technology & Architecture
Big Data Technology & Architecture
Elasticsearch Mapping, Data Types, and Document Operations Guide

Elasticsearch mappings describe how each field in a document should be indexed; they can be generated automatically or defined manually using the _mapping API. Example to retrieve the current mapping:

curl '172.16.1.127:9200/get-together/_doc/_mapping?pretty'

Automatic mapping creates fields on the fly, while manual mapping lets you specify types such as text, keyword, date, long, boolean, etc. Example of creating an index with a document:

curl -XPUT '172.16.1.127:9200/my_index/_doc/1?pretty' -H 'Content-Type: application/json' -d '{"name":"Late Night with Elasticsearch","date":"2013-10-25T19:00"}'

Basic data types covered include:

String – use text for analyzed fields and keyword for exact matches.

Number – choose byte, short, int, long, float, or double depending on range and precision.

Date – stored as date type, default ISO‑8601 format or custom formats via the format option.

Boolean – stored as boolean values true/false.

Array – any basic type can be an array without extra mapping.

Multi‑fields allow the same field to be indexed in different ways, for example adding a non‑indexed sub‑field:

curl -XPUT '172.16.1.127:9200/blog/_mapping/posts?pretty' -H 'Content-Type: application/json' -d '{"posts":{"properties":{"tags":{"type":"text","index":true,"fields":{"verbatim":{"type":"text","index":false}}}}}}'

Predefined fields such as _source, _all, _id, _type, and _index have special roles: _source stores the original JSON, _all (now deprecated) concatenated searchable text, and the others identify documents within an index.

Document updates can be performed by re‑indexing a new document, using the update API with a partial doc, an upsert clause, or a painless script. Example of a scripted price increase:

curl -XPOST '172.16.1.127:9200/online-shop/_doc/1/_update?pretty' -H 'Content-Type: application/json' -d '{"script":{"source":"ctx._source.price += params.price_diff","params":{"price_diff":10}}}'

Version numbers enable optimistic concurrency control. Supplying ?version=2 ensures the operation only succeeds if the document is at that version, otherwise a version_conflict_engine_exception is returned. The retry_on_conflict parameter can automatically retry updates.

Deletion can be done per‑document, by query, or at the index level. Deleting a document marks it as removed; the actual space is reclaimed later. Example:

curl -XDELETE '172.16.1.127:9200/online-shop/_doc/1?pretty'

Indexes can be deleted, closed, or opened. Closing an index frees resources while keeping the data on disk for later use.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ElasticsearchMappingData TypesVersion ControlDocument Update
Big Data Technology & Architecture
Written by

Big Data Technology & Architecture

Wang Zhiwu, a big data expert, dedicated to sharing big data technology.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.