PUT /my_index
- PUT /my_index
- {
- "mappings": {
- "properties": {
- "age": {
- "type": "integer"
- },
- "email": {
- "type": "keyword"
- },
- "name": {
- "type": "text" # 保存时候分词,检索时候进行分词匹配
- }
- }
- }
- }
- PUT /my_index/_mapping
- {
- "properties": {
- "employee-id": {
- "type": "keyword",
- "index": false # 字段不能被检索。检索
- }
- }
- }
对于已经存在的字段映射,我们不能更新。更新必须创建新的索引,进行数据迁移。
创建新映射
- PUT /newbank
- {
- "mappings": {
- "properties": {
- "account_number": {
- "type": "long"
- },
- "address": {
- "type": "text"
- },
- "age": {
- "type": "integer"
- },
- "balance": {
- "type": "long"
- },
- "city": {
- "type": "keyword"
- },
- "email": {
- "type": "keyword"
- },
- "employer": {
- "type": "keyword"
- },
- "firstname": {
- "type": "text"
- },
- "gender": {
- "type": "keyword"
- },
- "lastname": {
- "type": "text",
- "fields": {
- "keyword": {
- "type": "keyword",
- "ignore_above": 256
- }
- }
- },
- "state": {
- "type": "keyword"
- }
- }
- }
- }
查询映射
GET /newbank/_mapping
数据迁移
- POST _reindex
- {
- "source": {
- "index": "bank",
- "type": "account"
- },
- "dest": {
- "index": "newbank"
- }
- }
数据查询
GET /newbank/_search