ElasticSeach学习(四、mapping)

什么是Mapping

mapping是定义索引中有什么字段,字段类型等结构信息。相当于数据库的表结构或者solr的schema.

solr7.X以上不需要再定义类型_doc,已经废除

PUT test {  #定义索引名称为test
    "mappings" : {  #映射定义
            "properties" : {  #字段定义
                "field1" : { "type" : "text" }  #名为field1、类型为text的字段
            }
    }
}

字段属性

https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html

基本类型

text类型用于分词

keyword类型用于排序和聚合分析

Multi-fields多重字段

一个字段需要多种不同定义,如city即要分词索引,也要排序聚合:

PUT /test
{
  "mappings": {
    "properties": {
      "city":{
        "type": "text",
        "fields": {
          "raw":{
            "type":"keyword"
          }
        }
      }
    }
  }
}

其他类型

 例如format

PUT /test
{
  "mappings": {
    "properties": {
      "date":{
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd"
      }
    }
  }
}

只能上传上面定义的格式,es内部会将时间转换为long类型的毫秒数

猜你喜欢

转载自www.cnblogs.com/Unlimited-Blade-Works/p/12550756.html
今日推荐