[ES from entry to actual combat] 19. Full-text search-ElasticSearch-mapping-add new field mapping

Continue from section 18

3), the new version changes

ES7 and above remove the concept of type.

  • Two data representations in a relational database are independent, even if they have columns with the same name in them, it does not affect the use, but this is not the case in ES. Elasticsearch is a search engine developed based on Lucene, and files with the same name under different types in ES are ultimately processed in the same way in Lucene.
    • Two user_names under two different types are actually considered to be the same file under the same ES index. You must define the same file mapping in two different types. Otherwise, the same field names in different types will conflict during processing, resulting in a decrease in Lucene processing efficiency.
    • The purpose of removing the type is to improve the efficiency of ES processing data.

Elasticsearch 7.x:

  • The type parameter in the URL is optional. For example, indexing a document no longer requires the document type.

Elasticsearch 8.x:

  • The type parameter in the URL is no longer supported.

解决:
1) Migrate the index from multi-type to single-type, with an independent index for each type of document.
2) Migrate all the type data under the existing index to the specified location. See data migration for details

1. Create a mapping

Create index and specify mapping

PUT /my-index
{
    
    
  "mappings": {
    
    //映射规则
    "properties": {
    
    
      "age":    {
    
     "type": "integer" },  
      "email":  {
    
     "type": "keyword"  },//keyword不会进行全文检索 
      "name":   {
    
     "type": "text"  }//text保存的时候进行分词,搜索的时候进行全文检索   
    }
  }
}

Insert picture description here

2. Add new field mapping

PUT /my-index/_mapping
{
    
    
  "properties": {
    
    
    "employee-id": {
    
    
      "type": "keyword",
      "index": false//索引选项控制是否对字段值建立索引。 它接受true或false,默认为true。未索引的字段不可查询。
    }
  }
}

Insert picture description here

3. Update the mapping

We cannot update existing mapping fields. Update must create a new index for data migration

Reference document-mapping


reference:

Elasticsearch Reference

elastic

Getting started with the full-text search engine Elasticsearch

Guess you like

Origin blog.csdn.net/runewbie/article/details/106413964