elasticsearch 创建 mapping

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/h_sn9999/article/details/102769660

Mapping is the process of defining how a document, and the fields it contains, are stored and indexed. For instance, use mappings to define:

  • which string fields should be treated as full text fields.
  • which fields contain numbers, dates, or geolocations.
  • the format of date values.
  • custom rules to control the mapping for dynamically added fields.

简而言之,Mapping就是数据的映射关键,决定具体的数据类型及判断是否被分词

下面是具体的创建过程


PUT test_index2
{
  "settings":{
           "number_of_shards":1, 
           "number_of_replicas":0     
            },
  "mappings": {
      "dynamic": false,
      "properties": {
        "title": {
          "type": "text"
        },
        "name": {
          "type": "keyword"
        },
        "size": {
          "type": "integer"
        },
          "price": {
          "type": "integer"
        },
        "area": {
          "type": "integer"
        },
        "createTime": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "lastUpdateTime": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "layoutDesc" : {
          "type": "text"

         }
      }
    
  }
}

生产系统需要注意下面两个配置

"number_of_shards":1,   ##数据大,就需要多些数据节点,可以把数据均衡分布到不同的节点,可以分布式的查询(并行)
"number_of_replicas":0  ###设置副本数量,提高数据安全行,同时提升查询性能

扫描二维码关注公众号,回复: 7647759 查看本文章

****分片的数量创建后不能改变,副本可以

查看分片信息:

http://127.0.0.1:9200/test_index2/_settings?pretty

kibanna查看:

GET test_index2/_settings?pretty
GET test_index2/_mapping?pretty

猜你喜欢

转载自blog.csdn.net/h_sn9999/article/details/102769660