简介:⼿把⼿教你怎么操作mapping

新增
  • 请求
curl -X PUT "localhost:9200/nba/_mapping" -H 'Content-Type:
application/json' -d'
{
	"properties": {
		"name": {
			"type": "text"
		},
		"team_name": {
			"type": "text"
		},
		"position": {
			"type": "keyword"
		},
		"play_year": {
			"type": "keyword"
		},
		"jerse_no": {
			"type": "keyword"
		}
	}
}
  • 响应
{
 "acknowledged": true
}
获取
  • 请求
curl -X GET "localhost:9200/xdclass/_mapping"
  • 响应
{
	"nba": {
		"mappings": {
			"properties": {
				"jerse_no": {
					"type": "keyword"
				},
				"name": {
					"type": "text"
				},
				"play_year": {
					"type": "keyword"
				},
				"position": {
					"type": "keyword"
				},
				"team_name": {
					"type": "text"
				}
			}
		}
	}
}
批量获取
  • 请求
curl -X GET "localhost:9200/nba,cba/mapping"
  • 响应
{
	"nba": {
		"mappings": {
			"properties": {
				"jerse_no": {
					"type": "keyword"
				},
				"name": {
					"type": "text"
				},
				"play_year": {
					"type": "keyword"
				},
				"position": {
					"type": "keyword"
				},
				"team_name": {
					"type": "text"
				}
			}
		}
	},
	"cba": {
		"mappings": {}
	}
}
获取所有
  • 请求(一)
curl -X GET "localhost:9200/_mapping"
  • 响应(一)
{
	"nba": {
		"mappings": {
			"properties": {
				"jerse_no": {
					"type": "keyword"
				},
				"name": {
					"type": "text"
				},
				"play_year": {
					"type": "keyword"
				},
				"position": {
					"type": "keyword"
				},
				"team_name": {
					"type": "text"
				}
			}
		}
	},
	"cba": {
		"mappings": {}
	}
}
  • 请求(二)
curl -X GET "localhost:9200/_all/_mapping"
  • 响应(二)
{
	"nba": {
		"mappings": {
			"properties": {
				"jerse_no": {
					"type": "keyword"
				},
				"name": {
					"type": "text"
				},
				"play_year": {
					"type": "keyword"
				},
				"position": {
					"type": "keyword"
				},
				"team_name": {
					"type": "text"
				}
			}
		}
	},
	"cba": {
		"mappings": {}
	}
}
修改
  • 请求
curl -X PUT "localhost:9200/nba/_mapping" -H 'Content-Type:
application/json' -d'
{
	"properties": {
		"name": {
			"type": "text"
		},
		"team_name": {
			"type": "text"
		},
		"position": {
			"type": "keyword"
		},
		"play_year": {
			"type": "keyword"
		},
		"jerse_no": {
			"type": "keyword"
		},
		"country": {
			"type": "keyword"
		}
	}
}
  • 响应
{
 "acknowledged": true
}