Article directory
1, Government Bunkaji Site
2, Character type
1,
定义
: Mapping is the process of defining how documents and the fields they contain are stored and indexed.
2. Each document is a collection of fields, and each field has its own data type.
3. When mapping data, you can create a mapping definition that contains a list of fields related to the document
4. The mapping definition also includes metadata fields, such as The _source field, which customizes how the document's associated metadata is processed.
5. You can use动态映射
and显式映射
to define data.
Create a mapping explicitly
Explicit mapping allows you to choose exactly how to define the mapping, for example:
- Which string fields should be considered full-text fields.
- Which fields contain numbers, dates, or locations.
- The format of the date value.
- Customize rules to control mapping of dynamically added fields.
Explicitly create the mapping; that is, create it by defining a custom mapping before adding data to the index
PUT /my-index-000001
{
"mappings": {
"properties": {
"age": {
"type": "integer" },
"email": {
"type": "keyword" },
"name": {
"type": "text" }
}
}
}
View the mapping definition of a specific index
GET index_name/_mapping
GET bank/_mapping
You can see the field types defined in mapping, where account_number is long type, address field is full-text search, and it also defines that the following keyword attribute is a keyword type, that is, inseparable words. This also explains very welladdress.keyword
why it is an exact match
Add a new attribute to an existing mapping
The mapping information has been defined for the indexmy-index-000001
before, as follows
PUT /my-index-000001
{
"mappings": {
"properties": {
"age": {
"type": "integer" },
"email": {
"type": "keyword" },
"name": {
"type": "text" }
}
}
}
Now I want to add a new attribute to itemployee_id
. How to do it? As shown in the code snippet below
PUT /my-index-000001/_mapping
{
"properties": {
"employee-id": {
"type": "keyword",
"index": false
}
}
}
where"index": false
indicates that the current field cannot be indexed; thisindex和type一样都叫 mapping parameters
, is the entrance to the official document a>
View the definition information of the specified field in the mapping
For example, if you only want to view the definition information of the field in my-index-000001
, you can use the following commandemployee_id
GET /my-index-000001/_mapping/field/employee-id
The API response results are as follows:
{
"my-index-000001" : {
"mappings" : {
"employee-id" : {
"full_name" : "employee-id",
"mapping" : {
"employee-id" : {
"type" : "keyword",
"index" : false
}
}
}
}
}
}
Update a field that already has a mapping
This section only makes simple records. For specific operations, read the official documentation to find the corresponding solution.
The official statement clearly states:除了支持的映射参数外,您不能更改现有字段的映射或字段类型。更改现有字段可能会使已经索引的数据无效;如果需要更改索引中字段的映射,请创建具有正确映射的新索引,并将数据重新索引到该索引中。
- Cannot directly modify existing mappings
- Redefine a correct mapping
- Use
reindex
Migrate data
The official mentioned a term here reindx , which is also a specific solution for updating a certain field in the mapping