Elasticsearch Mapping

Elasticsearch Mapping示例

PUT my_index {   // 建立 my_index索引
  "mappings": {
    "user": {  // 建立名稱爲user的type
      "_all":       { "enabled": false  },  //Disable the _all meta field for the user mapping type
      "properties": { 
        "title":    { "type": "string"  }, 
        "name":     { "type": "string"  }, 
        "age":      { "type": "integer" }  
      }
    },
    "blogpost": { 
      "properties": { 
        "title":    { "type": "string"  }, 
        "body":     { "type": "string"  }, 
        "user_id":  {
          "type":   "string", 
          "index":  "not_analyzed"
        },
        "created":  {
          "type":   "date", 
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
  }}

type: 字段的數據類型,例如 string 和 datehtml

index: 字段是否應當被當成全文來搜索(analyzed),或被當成一個準確的值(not_analyzed),仍是徹底不可被搜索(no)elasticsearch

analyzer: 肯定在索引和或搜索時全文字段使用的分析器。ide


Elasticsearch Field DataTypes

Elasticsearch supports a number of different datatypes for the fields in a document:post

Core datatypesedit

Complex datatypesedit

Geo datatypesedit

Specialised datatypesedit

  • IPv4 datatype

  • ip for IPv4 addresses

  • Completion datatype

  • completion to provide auto-complete suggestions

  • Token count datatype

  • token_count to count the number of tokens in a string

  • mapper-murmur3

  • murmur3 to compute hashes of values at index-time and store them in the index

  • Attachment datatype

  • See the mapper-attachments plugin which supports indexing attachments like Microsoft Office formats, Open Document formats, ePub, HTML, etc. into an attachment datatype.

Multi-fieldsedit

It is often useful to index the same field in different ways for different purposes. For instance, a string field could be indexed as an analyzed field for full-text search, and as a not_analyzed field for sorting or aggregations. Alternatively, you could index a string field with the standard analyzer, the english analyzer, and the frenchanalyzer.

相關文章
相關標籤/搜索