curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
"mappings": {
"session": {
"properties": {
"user_id": {
"type": "keyword"
},
"last_updated": {
"type": "date"
},
"session_data": { # 1
"enabled": false
}
}
}
}
}
'
curl -XPUT 'localhost:9200/my_index/session/session_1?pretty' -H 'Content-Type: application/json' -d'
{
"user_id": "kimchy",
"session_data": { # 2
"arbitrary_object": {
"some_array": [ "foo", "bar", { "baz": 2 } ]
}
},
"last_updated": "2015-12-06T18:20:22"
}
'
curl -XPUT 'localhost:9200/my_index/session/session_2?pretty' -H 'Content-Type: application/json' -d'
{
"user_id": "jpountz",
"session_data": "none", # 3
"last_updated": "2015-12-06T18:22:13"
}
'
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
"mappings": {
"session": { # 1
"enabled": false
}
}
}
'
curl -XPUT 'localhost:9200/my_index/session/session_1?pretty' -H 'Content-Type: application/json' -d'
{
"user_id": "kimchy",
"session_data": {
"arbitrary_object": {
"some_array": [ "foo", "bar", { "baz": 2 } ]
}
},
"last_updated": "2015-12-06T18:20:22"
}
'
curl -XGET 'localhost:9200/my_index/session/session_1?pretty' # 2
curl -XGET 'localhost:9200/my_index/_mapping?pretty' # 3
建议:enabled 设置允许在同一索引中相同名称的字段有不同设置。 可以使用PUT mapping API在现有字段上更新已经存在字段的值。