elasticsearch映射mapping

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yaohuan2017/article/details/85335086

映射

映射是创建索引的时候,可以预先定义字段的类型以及相关属性

elasticsearch会根据JSON源数据的数据基础类型猜测你想要的字段映射。将输入的数据转变成可搜索的索引项。Mapping就是根据我们自己定义的字段的数据类型,同时告诉Elasticsearch如何索引数据以及是否可以被搜索。
作用:会让索引建立的更加细致和完善
类型:静态映射和动态映射
内置类型:
文本类型: text,keyword(text会被分词等解析、可搜索)
数字类型:long,integer,short,byte,double,float
日期:date
bool类型:boolean
binary类型:binary
复制类型:object,nested
geo类型:geo-point,geo-shape
专业类型:ip,competion

#创建mapping
PUT lagou
{
  "mappings": {
    "job":{
      "properties":{
        "title":{
          "type": "text"
        },
        "salary_min": {
          "type": "integer"
        },
        "city":{
          "type":"keyword"
        },
        "company":{
          "properties":{
            "name":{
              "type": "text"
            },
            "company_addr":{
              "type":"text"
            },
            "employee_count":{
              "type":"integer"
            }
          }
        },
        "publish_date":{
          "type":"date",
          "format":"yyyy-MM-dd"
        },
        "comments":{
          "type": "integer"
        }
      }
    }
  }
}
#插入数据
PUT lagou/job/1
{
  "title":"python分布式爬虫开发",
  "salary_min":15000,
  "city":"北京",
  "company":{
    "name":"百度",
    "company_addr":"北京市软件园",
    "employee_count":50
  },
  "publish_date":"2017-4-16",
  "comments":15
}

猜你喜欢

转载自blog.csdn.net/yaohuan2017/article/details/85335086