" />
文章

Elasticsearch 通过 mapping 指定字段类型

Elasticsearch 设置mapping的规范模版

{  
  "settings": {  
    "index": {  
      "number_of_shards": "1",  
      "max_result_window": "100000",  
      "number_of_replicas": "0"  
    }  
  },  
  "mappings": {  
    "dynamic_templates": [  
      {  
        "strings_as_keywords": {  
          "match_mapping_type": "string",  
          "mapping": {  
            "type": "keyword"  
          }  
        }  
      },  
      {  
        "dates_with_custom_format": {  
          "match_mapping_type": "date",  
          "match_pattern": "regex",  
          "match": ".*Time$|.*Date$",  
          "mapping": {  
            "type": "date",  
            "format": "yyyy-MM||yyyy-MM-dd||yyyy-MM-dd HH:mm:ss.S||yyyy-MM-dd HH:mm:ss||epoch_millis"  
          }  
        }  
      }  
    ],  
    "properties": {  
      "author": {  
        "type": "keyword"  
      },  
      "bid": {  
        "type": "long"  
      },  
      "content": {  
        "type": "text"  
      },  
      "fid": {  
        "type": "long"  
      },  
      "mid": {  
        "type": "keyword"  
      },  
      "title": {  
        "type": "keyword"  
      },  
      "year": {  
        "type": "long"  
      },  
      "createTime": {  
        "type": "date",  
        "format": "yyyy-MM||yyyy-MM-dd||yyyy-MM-dd HH:mm:ss.S||yyyy-MM-dd HH:mm:ss||epoch_millis"  
      },  
      "registryTime": {  
        "type": "date",  
        "format": "yyyy-MM||yyyy-MM-dd||yyyy-MM-dd HH:mm:ss.S||yyyy-MM-dd HH:mm:ss||epoch_millis"  
      },  
      "modifyTime": {  
        "type": "date",  
        "format": "yyyy-MM||yyyy-MM-dd||yyyy-MM-dd HH:mm:ss.S||yyyy-MM-dd HH:mm:ss||epoch_millis"  
      }  
    }  
  }  
}
License:  CC BY 4.0