es的mapping定义

我所用的是kibana的插件

地址:http:localhost:9200/_plugin/kopf/#!/indexTemplates

显示画面:

es的mapping定义_第1张图片

template 是你想定义的index name

示例我定义的一些mapping的模板

代码:

{
  "order": 0,
  "template": "test-*",
  "settings": {
    "index": {
      "number_of_replicas": "1",
      "number_of_shards": "3",
      "refresh_interval": "1s"
    }
  },
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "page_url_field": {
            "mapping": {
              "index": "analyzed",
              "omit_norms": true,
              "fielddata": {
                "format": "disabled"
              },
              "type": "string",
              "fields": {
                "raw": {
                  "index": "not_analyzed",
                  "ignore_above": 512,
                  "doc_values": true,
                  "type": "string"
                }
              }
            },
            "match": "page_url",
            "match_mapping_type": "string"
          }
        },
        {
          "useragent_field": {
            "mapping": {
              "index": "analyzed",
              "omit_norms": true,
              "fielddata": {
                "format": "disabled"
              },
              "type": "string",
              "fields": {
                "raw": {
                  "index": "not_analyzed",
                  "ignore_above": 512,
                  "doc_values": true,
                  "type": "string"
                }
              }
            },
            "match": "useragent",
            "match_mapping_type": "string"
          }
        },
        {
          "page_referrer_field": {
            "mapping": {
              "index": "analyzed",
              "omit_norms": true,
              "fielddata": {
                "format": "disabled"
              },
              "type": "string",
              "fields": {
                "raw": {
                  "index": "not_analyzed",
                  "ignore_above": 512,
                  "doc_values": true,
                  "type": "string"
                }
              }
            },
            "match": "page_referrer",
            "match_mapping_type": "string"
          }
        },
        {
          "string_fields": {
            "mapping": {
              "index": "not_analyzed",
              "ignore_above": 10240,
              "doc_values": true,
              "type": "string"
            },
            "match": "*",
            "match_mapping_type": "string"
          }
        },
        {
          "float_fields": {
            "mapping": {
              "doc_values": true,
              "type": "float"
            },
            "match": "*",
            "match_mapping_type": "float"
          }
        },
        {
          "geolocation_fields": {
            "mapping": {
              "index": "not_analyzed",
              "type": "geo_point"
            },
            "match": "geolocation"
          }
        },
        {
          "loanAmount_fields": {
            "mapping": {
              "index": "not_analyzed",
              "type": "double"
            },
            "match": "loanAmount"
          }
        },
        {
          "collector_date_fields": {
            "mapping": {
              "index": "not_analyzed",
              "type": "string"
            },
            "match": "collector1_date"
          }
        },
        {
          "collector_time_fields": {
            "mapping": {
              "index": "not_analyzed",
              "format": "HH:mm:ss.SSS",
              "type": "date"
            },
            "match": "collector_time"
          }
        },
        {
          "double_fields": {
            "mapping": {
              "doc_values": true,
              "type": "double"
            },
            "match": "*",
            "match_mapping_type": "double"
          }
        },
        {
          "byte_fields": {
            "mapping": {
              "doc_values": true,
              "type": "byte"
            },
            "match": "*",
            "match_mapping_type": "byte"
          }
        },
        {
          "short_fields": {
            "mapping": {
              "doc_values": true,
              "type": "short"
            },
            "match": "*",
            "match_mapping_type": "short"
          }
        },
        {
          "integer_fields": {
            "mapping": {
              "doc_values": true,
              "type": "integer"
            },
            "match": "*",
            "match_mapping_type": "integer"
          }
        },
        {
          "long_fields": {
            "mapping": {
              "doc_values": true,
              "type": "long"
            },
            "match": "*",
            "match_mapping_type": "long"
          }
        },
        {
          "date_fields": {
            "mapping": {
              "doc_values": true,
              "type": "date"
            },
            "match": "*",
            "match_mapping_type": "date"
          }
        },
        {
          "geo_point_fields": {
            "mapping": {
              "doc_values": true,
              "type": "geo_point"
            },
            "match": "*",
            "match_mapping_type": "geo_point"
          }
        }
      ],
      "properties": {
        "@timestamp": {
          "doc_values": true,
          "type": "date"
        },
        "collector_tstamp": {
          "type": "string"
        },
        "geo_location": {
          "type": "geo_point"
        },
        "geoip": {
          "dynamic": true,
          "properties": {
            "location": {
              "doc_values": true,
              "type": "geo_point"
            },
            "longitude": {
              "doc_values": true,
              "type": "float"
            },
            "latitude": {
              "doc_values": true,
              "type": "float"
            },
            "ip": {
              "doc_values": true,
              "type": "ip"
            }
          },
          "type": "object"
        },
        "@version": {
          "index": "not_analyzed",
          "doc_values": true,
          "type": "string"
        }
      },
      "_all": {
        "enabled": false,
        "omit_norms": true
      }
    }
  },
  "aliases": {}
}

refresh_interval 如果想用spark实时查找es的话,这个参数最好是设置比spark batch时间小一些。不然查出来的数据错误

index 可以设置为not_analyzed 表示不分词 ,也可以设置为analyzed 表示分词,由于业务的需求,我这边没有设置分词

转载于:https://my.oschina.net/u/3455048/blog/993835

你可能感兴趣的:(es的mapping定义)