Mapping
3142 ワード
defines structure of docs and how values are indexes
--> similar to schema in RDB
explicit mapping : defined by developer
dynamic mapping : auto generate field mapping
combining two are possible field mappings can be created when creating an index or afterwards for entire index for specific field dot notation can be used insted of nesting for better viewability specifying date formatted string milliseconds since the epoch (long) seconds since the epoch (int) custom date format epoch = 1/1/1970
Accepted formats date without time date with time milliseconds since epoch (long) UTC assumed Date must be formatted according to ISO 8601 spec stored internally as milliseconds since epoch how missing fields are handled all fields are optional unlike RDB where NULL allow should be explicitly set integrity checks should be done at application level
--> similar to schema in RDB
explicit mapping : defined by developer
dynamic mapping : auto generate field mapping
1. Explicit Mapping
PUT /reviews
{
"mappings": {
"properties": {
"rating": {"type": "float"},
"content": {"type": "text"},
"product_id": {"type": "integer"},
"author": {
"properties": {
"first_name": {"type": "text"},
"last_name": {"type": "text"},
"email": {"type": "keyword"}
}
}
}
}
}
2. Retrieving Mapping
GET /reviews/_mapping
GET /reviews/_mapping/field/content
// for field in object
GET /reviews/_mapping/field/author.email
3. Using dot notation in field names
PUT /reviews
{
"mappings": {
"properties": {
"rating": {"type": "float"},
"content": {"type": "text"},
"product_id": {"type": "integer"},
"author.first_name": {"type": "text"}
"author.last_name": {"type": "text"}
"author.email": {"type": "keyboard"}
}
}
}
4. Adding Mappings to Existing Indexes
// add time stamp to reviews index
PUT /reviews/_mapping
{
"properties": {
"created_at": {"type": "date"}
}
}
Date data type
default behavior of date fields
how date fields are stored
PUT /reviews/_doc/3
{
"created_at": "2015-04-15T13:07:41Z"
}
Reference
この問題について(Mapping), 我々は、より多くの情報をここで見つけました https://velog.io/@sangmin7648/Mappingテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol