Elasticsearch mapping

本文深入探讨了Elasticsearch中的mapping设置,包括分片与副本数的设定、字段动态新增控制、字段类型映射调整及特定字段如时间戳、URL、响应内容的详细配置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ES中mapping设置的一些说明,如下:

curl ${es_host}:9200/_template/prefix-estype -d
  '{
    "order": 0,
    "template": "prefix-*-estype-*",
    "settings": {
      "index": {
		"number_of_shards": "5", #设置分片数
        "number_of_replicas": "1" #设置副本数
      }
    },
    "mappings": {
      "estype": {
        "dynamic": true, #控制字段的新增(true:(默认)允许自动新增字段;false:不允许自动新增字段,文档可以正常写入,但无法对新增字段进行查询等操作;strict:文档不能写入,报错)
        "dynamic_templates": [
          {
            "string_as_keyword": {
              "match_mapping_type": "string", #可以改变ES的想法,本来ES觉得这个字段应该映射成string,可以修改成keyword
              "match": "*", #主要是对字段名称进行匹配处理
              "mapping": {
                "index": "not_analyzed", #设置为该值可以保证该字段能通过检索查询到
                "type": "keyword" #上面定义的类型修改成keyword
              }
            }
          }
        ],
        "properties": {
          "timestamp": {
            "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd HH:mm:ss.SSS||epoch_millis",
            "type": "date",
            "store": true
          },
          "interval": {
            "type": "long",
            "store": true
          },
          "url": {
            "type": "keyword",
            "store": true
          },
          "resp": {
            "search_analyzer": "ik_max_word",
            "analyzer": "ik_max_word",
            "type": "text",
            "store": true
          },
          "params": {
            "search_analyzer": "ik_max_word",
            "analyzer": "ik_max_word",
            "type": "text"
          }
        }
      }
    },
    "aliases": {}
  }'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值