1.创建索引
(1).创建新索引
打开kibana Dev Tools,创建一个名为people的索引。
PUT /people
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1
}
}
(2).设置索引Mapping
为索引people设置mapping结构。
PUT /people/_mapping
{
"properties": {
"name": {
"type": "text"
},
"country": {
"type": "keyword"
},
"age": {
"type": "integer"
},
"birthday": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"description": {
"type": "text"
}
}
}
(3).查看索引Mapping
GET /people/_mapping
(4).修改索引Mapping(只可新增字段)
PUT /people/_mapping
{
"properties": {
"salary": {
"type": "text"
}
}
}
(5).删除索引
DELETE /people
2.增加文档
(1).指定文档id增加
POST /people/_doc/1
{
"name": "Mike Steven",
"country": "China",
"age": 30,
"birthday": "1995-01-01",
"description":"I am Mike Steven."
}
(2).自动产生文档id增加
POST /people/_doc
{
"name": "Mike Sherry",
"country": "China",
"age": 23,
"birthday": "1998-06-01",
"description":"I am Mike Sherry."
}
3.删除
(1).指定文档id删除
DELETE /people/_doc/1
4.修改
(1).指定文档id修改
POST /people/_update/1
{
"doc": {
"name": "steven007"
}
}
(2).使用脚本修改(不常用)
POST /people/_update/1
{
"script": {
"lang": "painless",
"source": "ctx._source.age = params.age",
"params": {
"age": 100
}
}
}
5.查询
(1).指定文档id查询
GET /people/_doc/1
(2).查询所有文档
GET /people/_search
{
"query": {
"match_all": {}
}
}