9
INTRODUCTION TO MAPPING by Bo Andersen - codingexplained.com

Introduction to Elasticsearch Mapping

Embed Size (px)

Citation preview

Page 1: Introduction to Elasticsearch Mapping

INTRODUCTION TO MAPPING

by Bo Andersen - codingexplained.com

Page 2: Introduction to Elasticsearch Mapping

OUTLINE

➤ What is mapping in Elasticsearch?

➤ Field data types

➤ Meta fields

➤ Dynamic mapping

➤ Explicit mapping

➤ Mapping gotchas

Page 3: Introduction to Elasticsearch Mapping

WHAT IS MAPPING IN ELASTICSEARCH?

➤ Defines how documents and their fields are stored and indexed

➤ Most commonly involves defining the data types for fields

➤ Quite similar to database schemas for relational databases

➤ Can also be used to

➤ Define the format of date fields

➤ Define whether or not field values should be indexed into the catch-all _all field

➤ ... and more!

Page 4: Introduction to Elasticsearch Mapping

FIELD DATA TYPES

➤ A mapping type contains fields

➤ E.g. title, category, content for an "article" type

➤ Each field has a data type

➤ E.g. string, long, double, boolean, date, ...

➤ These data types can be defined in the mapping

➤ Similar to data types for columns in relational databases

Page 5: Introduction to Elasticsearch Mapping

META FIELDS

➤ A mapping type also contains meta fields

➤ The behavior of some of the meta fields can be customized

➤ Examples

➤ _id

➤ _type

➤ _uid

➤ _index

Page 6: Introduction to Elasticsearch Mapping

DYNAMIC MAPPING

➤ The automatic detection and addition of new types and fields

➤ Fields and mapping types do not need to be defined before being used

➤ You can add a document without first defining a mapping type and defining its

fields

➤ You can even add a document without creating an index

➤ Elasticsearch will create the index, mapping type and fields automatically

➤ Elasticsearch will infer the data types based on the document's data

Page 7: Introduction to Elasticsearch Mapping

EXPLICIT MAPPING

➤ Enables you to specify explicit mappings

➤ When creating an index, mapping types and field mappings can be created

➤ These can also be added to existing indexes by issuing a PUT request

➤ Useful if you have some requirements for the data (e.g. specific date formats)

➤ Useful if Elasticsearch cannot guess or infer the correct mapping information

➤ Dynamic mapping is great for getting started, but eventually you will probably want to

add explicit mappings

Page 8: Introduction to Elasticsearch Mapping

MAPPING GOTCHAS

➤ Existing type and field mappings cannot be updated

➤ Create a new index and reindex your data into that index

➤ Fields are shared across mapping types

➤ If a title field exists in both an employee and article mapping type, the fields

must have exactly the same mapping in each type

➤ Can be resolved by choosing more descriptive names, e.g. employee_title and

article_title

Page 9: Introduction to Elasticsearch Mapping

THANK YOU FOR WATCHING!