一、简单使用:(6.x与7.x版本在构建type时会有差别,以7的版本为例)
1.构建名为web_user的索引:
PUT localhost:9200/web_user
{
"mappings": {
"properties": {
"name": { "type": "text" },
"user_name": { "type": "keyword" },
"email": { "type": "keyword" },
"tweeted_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || yyyy/MM/dd HH:mm:ss|| yyyy/MM/dd ||epoch_millis"
}
}
}
}
2.插入数据:
POST localhost:9200/web_user/_doc/ (自动生成Id,需要使用post方式提交),如果追加参数?op_type=create,会在失败时报错。
{
"name": "lisi",
"user_name": "zhangsan",
"email": "test@163.com",
"tweeted_at": "2019-08-20"
}
PUT localhost:9200/web_user/_doc/1 (指定id,如果存在则为更新)
3.更新数据:
POST localhost:9200/web_user/_doc/1/_update
{
"doc": {
"name": "lisi",
"user_name": "zhangsanmodify",
"email": "test@163.com",
"tweeted_at": "2019-08-20"
}
}
4.删除数据:
DELETE localhost:9200/web_user/_doc/1
5.查看所有的数据:
localhost:9200/web_user/_doc/_search
6.更新索引类型
6.1:使用scroll进行游标查询,用 bulk api 新建索引、重建字段索引。
6.2:使用索引别名,轻松替换索引
6.3:es5之后,使用reindex
https://blog.csdn.net/weixin_37703281/article/details/91049175