elasticsearch配置mapping时,对所有的type有效

本文介绍了如何在Elasticsearch中为一个index下的所有type设置通用mapping。通过使用特定字段创建template,可以在未预知type数量的情况下确保mapping生效。参考链接提供了详细配置示例。
摘要由CSDN通过智能技术生成

在elasticsearch中一个index下面会有很多的type,在一个项目中type的数量未知,所以在建立template的时候需要mapping不指定type(对所有的type有效)
因此需要用到_default_字段:

PUT /my_index{
"mappings": {
    "_default_": {
            "properties": {
                "field1": {
                    "type": "string",
                    "index": "analyzed"
                }
             }
     }
}

在项目中需要用到的配置帖出来,大家参考:

{
    "template":"projectlog*",
    "settings":{
         "number_of_shards" : 5
    },
    "mappings": {

            "_default_": {
                "_source" : { "enabled" : true },
                "properties": {
                    "additionInfo": {
                        "type": "string",
                        "index": "not_analyzed" },
                    "devEnv": {
                        "type": "string",
                        "index": "not_analyzed" },
                    "eventId": {
                        "type": "string",
                        "index": "not_analyzed" },
                    "eventName": {
                        "type": "string",
                        "index": "not_analyzed" },
                    "hit": {
                        "type": "integer" },
                    "hitRules": {
                        "type": "string",
                        "index": "not_analyzed" },
                    "ip": {
                        "type": "string",
                        "index": "not_analyzed" },
                    "mainBody": {
                        "type": "string",
                        "index": "not_analyzed" },
                    "requestTime": {
                        "type": "long" },
                    "riskParam": {
                       "index": "not_analyzed",
                        "type": "string" },
                    "ruleId": {
                        "type": "string",
                        "index": "not_analyzed" },
                    "serialNumber": {
                        "type": "string",
                        "index": "not_analyzed" },
                    "shootPenalties": {
                        "type": "string",
                        "index": "not_analyzed" }
                }
            }          

        }
}

http://stackoverflow.com/questions/27277609/elasticsearch-is-it-possible-to-set-mapping-for-field-in-index-for-all-types

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值