Mappings and datatypes
- ElasticSearch is schema less, i.e. we can store documents with any number of fields and types of fields.
- There are always some set of fields common across all documents in a type.
- Core Data Types
- String Data types
- text: The text datatype is useful for supporting full-text search for fields that contain a description or lenghty text values. Thes fields are analyzed before indexing to support full-text search
- keyword: This type enable analytics on string fields. Fields of this type support sorting, filtering and aggregations
- Numeric data types:
- byte, short, integer and long
- float and double
- half_float
- scaled_float
- Date datatype:
- data: Date with an optional timestamp
- Boolean datatype:
- boolean:
- Binary datatype:
- binary: Allows us to store binary with Base64 encoding
- Range datatypes:
- integer_range, float_range, long_range, double_range, data_range
- String Data types
- Complex Data types:
- Array datatype:
- Object data types:
- Nested data type:
- Other datatypes:
- Geo-point datatype
- Geo-shape datatype
- IP datatype
Understanding Mapping
- In the last session we have inserted a data to the index qualitythought
Inverted Indexes
- Consider we have the following documents with text inserted into elastic search
Document ID | Document |
---|---|
1 | Its Friday tomorrow |
2 | Friday night is beginining of Weekend |
3 | The best day of the week is your choice |
4 | This week is best for sales |
- Elastic search builds a data structure from the three documents that have been indexed. This data structure is called as inverted index
- Documents will be broken down into terms after removing puncutation and placing them in LowerCase
- Terms are sorted alphabetically
- When searching for terms in the documents, it is blazingly fast to locate the document in which given terms appear.
CRUD Operations
- To understand how to perform CRUD Operations, we will look into following APIs under document API
- Index API
- Get API
- Update API
- Delete API
Index API
- Adding a document to a type within an index of elastic search is called as indexing.
- There are two ways to index a document
- Indexing a document by providing an ID
- Indexing a document by without providing an ID
Get API
- This API is used to retrieve documents
Update API
- This is used to update a document.