创建索引
PUT test_index/
创建一个叫test_index的索引
创建mapping
PUT test_index/test01/_mapping
{
"test01":{
"properties":{
"id":{
"type":"text"
},
"title":{
"type":"text"
}
}
}
}
创建test_index索引,type为test01的mapping,properties里装字段的数据类型
text keyword 都是文本类型,text支持分词,可以设置分词,而keyword不支持分词,用来过滤、排序和聚合。加粗样式
可以参考 https://blog.youkuaiyun.com/sunjinjuan/article/details/81986164
增
通过post上传数据
POST test_index/test01
{
"id":"aa",
"title":"bb"
}
通过post请求添加数据到索引为test_index,type为test01中,在代码中我们也可以通过发生post请求来进行增加数据,同时可以配合安全认证shield
这是增加了一条数据后返回的值,因为,我们上传数据时,没有指定Document,所以这里,生成了一个随机的id
查
我们可以通过下面语句来查询
查询单条数据
GET test_index/test01/jVsnEW0BZpThbqaNUwCw
GET 索引/类型/文档
查询所有数据
GET test_index/test01/_search
{"query": {
"match_all": {}
}
相当于
GET test_index/test01/_search
查询id为aa的数据,并且只显示title字段
GET test_index/test01/_search
{
"query": { "match": {
"id":"aa"
} },
"_source": ["title"]
}
删
DELETE 索引名
还有许多复杂的查询语句,可以看官方文档