# ES6.x需要在_mapping后指定type,type可以自动创建
curl -X PUT "node01:9200/nba/_mapping/_doc" -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"
}
}
}
'
# ES7.x
curl -X PUT "node01: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"
}
}
}
'
# ES6.x
curl -X PUT "node01:9200/index4" -H 'Content-Type:application/json' -d'
{
"mappings": {
"test_type": {
"properties": {
"id": {
"type": "text"
}
}
}
}
}
'
# ES7.x
curl -X PUT "node01:9200/index4" -H 'Content-Type:application/json' -d'
{
"mappings": {
"properties": {
"id": {
"type": "text"
}
}
}
}
'
# ES6.0需要指定type
curl -X GET "node01:9200/nba/_mapping/_doc"
# ES7.0不需要指定type
curl -X GET "node01:9200/nba/_mapping"
{
"nba": {
"mappings": {
"_doc": {
"properties": {
"jerse_no": {
"type": "keyword"
},
"name": {
"type": "text"
},
"play_year": {
"type": "keyword"
},
"position": {
"type": "keyword"
},
"team_name": {
"type": "text"
}
}
}
}
}
}
curl -X GET "ip:9200/index/_mapping/type"
curl -X GET "ip:9200/index/_mapping/type1,type2"
curl -X GET "ip:9200/index/_mapping"
curl -X GET "ip:9200/index1,index2/_mapping/type1,type2"
这时会做笛卡尔积,把所有可以查到的index的type的mapping返回
curl -X GET "ip:9200/index*,test*/_mapping"
curl -X GET "ip:9200/*1,*2/_mapping/type*"
使用通配符也会做笛卡尔积,所有满足通配符的index和type,只要可以这个index有这个type就会查出mapping并返回
curl -X GET "ip:9200/index/_mapping/type"
curl -X GET "ip:9200/index/_mapping"
由于只有一个type,所以这两条查询本质上是一样的
curl -X GET "ip:9200/index1,index2/_mapping/type1,type2"
curl -X GET "ip:9200/test*/_mapping"
同样,也是做笛卡尔积,只要可以查出来就返回
curl -X GET "ip:9200/index1,index2/_mapping"
curl -X GET "ip:9200/test*/_mapping"
curl -X GET "node01:9200/test_index1/_mapping"
{
"test_index1":{
"mappings":{
"test_type1":{
"properties":{
"name":{
"type":"text"
}
}
}
}
}
}
curl -X GET "node01:9200/test_index1/_mapping/test_type1"
{
"test_index1":{
"mappings":{
"test_type1":{
"properties":{
"name":{
"type":"text"
}
}
}
}
}
}
curl -X GET "node01:9200/test_index1,test_index2/_mapping"
{ "test_index2":{
"mappings":{
"test_type2":{
"properties":{
"name":{
"type":"text"
}
}
}
}
},
"test_index1":{
"mappings":{
"test_type1":{
"properties":{
"name":{
"type":"text"
}
}
}
}
}
}
curl -X GET "node01:9200/test_index1,test_index2/_mapping/test_type1"
{
"test_index1":{
"mappings":{
"test_type1":{
"properties":{
"name":{
"type":"text"
}
}
}
}
}
}
curl -X GET "node01:9200/test_index1,test_index2/_mapping/test_type2"
{
"test_index2":{
"mappings":{
"test_type2":{
"properties":{
"name":{
"type":"text"
}
}
}
}
}
}
curl -X GET "node01:9200/test_index1,test_index2/_mapping/test_type1,test_type2"
{ "test_index2":{
"mappings":{
"test_type2":{
"properties":{
"name":{
"type":"text"
}
}
}
}
},
"test_index1":{
"mappings":{
"test_type1":{
"properties":{
"name":{
"type":"text"
}
}
}
}
}
}
curl -X GET "node01:9200/test_index*,index*/_mapping"
{
"index3":{
"mappings":{}
},
"test_index":{
"mappings":{
"test_type":{
"properties":{
"message":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"user":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
},
"test_index2":{
"mappings":{
"test_type2":{
"properties":{
"name":{
"type":"text"
}
}
}
}
},
"index2":{
"mappings":{}
},
"index1":{
"mappings":{
"_doc":{
"properties":{
"jerse_no":{
"type":"keyword"
},
"name":{
"type":"text"
},
"play_year":{
"type":"keyword"
},
"position":{
"type":"keyword"
},
"team_name":{
"type":"text"
}
}
}
}
},
"test_index1":{
"mappings":{
"test_type1":{
"properties":{
"name":{
"type":"text"
}
}
}
}
}
}
curl -X GET "ip:9200/_mapping
curl -X GET "ip:9200/_all/_mapping/type1,type2
curl -X GET "ip:9200/_mapping"
curl -X GET "ip:9200/_all/_mapping"
curl -X GET node01:9200/_all/_mapping/test_type1,test_type2
{
"test_index2": {
"mappings": {
"test_type2": {
"properties": {
"name": {
"type": "text"
}
}
}
}
},
"test_index1": {
"mappings": {
"test_type1": {
"properties": {
"name": {
"type": "text"
}
}
}
}
}
}
curl -X GET node01:9200/_mapping
{
"index1": {
"mappings": {
"_doc": {
"properties": {
"jerse_no": {
"type": "keyword"
},
"name": {
"type": "text"
},
"play_year": {
"type": "keyword"
},
"position": {
"type": "keyword"
},
"team_name": {
"type": "text"
}
}
}
}
},
"index2": {
"mappings": {}
},
"test_index2": {
"mappings": {
"test_type2": {
"properties": {
"name": {
"type": "text"
}
}
}
}
},
"test_index": {
"mappings": {
"test_type": {
"properties": {
"message": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"user": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
},
"test2": {
"mappings": {}
},
"nba": {
"mappings": {
"_doc": {
"properties": {
"jerse_no": {
"type": "keyword"
},
"name": {
"type": "text"
},
"play_year": {
"type": "keyword"
},
"position": {
"type": "keyword"
},
"team_name": {
"type": "text"
}
}
}
}
},
"test_index1": {
"mappings": {
"test_type1": {
"properties": {
"name": {
"type": "text"
}
}
}
}
},
"test1": {
"mappings": {}
},
"index3": {
"mappings": {}
}
}
# 只能新增field,不能修改已有field的数据类型
curl -X PUT "node01:9200/test_index1/_mapping/test_type1" -H 'Content-Type:application/json' -d'
{
"properties": {
"id": {
"type": "text"
}
}
}
'
# 如果要写上原有的字段,一定要和以前的数据类型一样
curl -X PUT "node01:9200/test_index1/_mapping/test_type1" -H 'Content-Type:application/json' -d'
{
"properties": {
"id": {
"type": "text"
},
"name": {
"type": "text"
}
}
}
'
# EX7.x不需要指定type
curl -X PUT "node01:9200/test_index1/_mapping" -H 'Content-Type:application/json' -d'
{
"properties": {
"id": {
"type": "text"
}
}
}
'