[ES from entry to actual combat] 18. Full-text search-ElasticSearch-mapping-mapping creation

Continue from section 17

3、Mapping

1), field type

  • Core type

    • String
      text,keyword
    • Digital type (Numeric)
      long, integer, short, byte, double, float, half_float,scaled_float
    • Date type (Date)
      date
    • Boolean
      boolean
    • Binary type
      binary
  • Compound type

    • Array type (Array)
      Arraysupport is not for specific data types
    • Object type (Object)
      objectAn object used for a single JSON object
    • Nested type (Nested)
      nestedfor arrays of JSON objects
  • Geographical type (Geo)

    • Geographical coordinates (Geo-point)
      geo_pointlatitude/longitude coordinates
    • Geo-shape is
      geo_shapeused for complex shapes such as polygons
  • Specific type

    • IP type (IP) is
      ipused to describe IPv4 and IPv6 addresses
    • Completion type (Completion)
      completionprovides automatic completion prompt
    • Token count type is
      token_countused to count the number of entries in a string
    • Accessory Type (attachment)
      Reference mapper-attachments plugin supports attachments such as Microsoft Office format, open document format, ePub, HTML and other index attachmentdata type.
    • The extraction type (Percolator)
      accepts query-dslqueries from a domain-specific language ( )

For more field types, please refer to the official ES document: reference document-mapping-types

2), mapping

Mapping (mapping)
Mapping 是用来定义一个文档(document),以及它所包含的属性(field)是如何存储和索引的. For example, use mapping to define:

  • Which string attributes should be considered as full text fields

  • Which attributes contain numbers, dates or geographic locations

  • Whether all attributes in the document can be indexed (_all configuration)

  • Date format

  • Custom mapping rules to perform dynamic addition of attributes

  • View mapping information:
    GET bank/_mapping
    Insert picture description here

  • Modify the mapping information:

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

Insert picture description here
ES automatically guessed the mapping type:

JSON type Domain type
Boolean: true, false boolean
Integer: 123 long
Floating point number: 1.23 double
String, valid date 2020-02-02 date
String, foo bar string
Objects, also known as hashes, store object types object

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/106413247