1.创建索引
put /index
创建案例
2.查询索引
get /index
删除索引
delete /index
2.文档操作
不指定id创建文档
post /index/_doc
#使用json数据
{
"title":"测试",
"context":"创建文档测试"
}
创建文档 指定id
put/post /index/_doc/_id
#使用json数据
{
"title":"测试",
"context":"创建文档测试"
}
主键查询
GET /index/_doc/_id
全查询
GET /index/_doc/_search
全量修改
修改时会将之前的数据 全量覆盖
put /index/_doc/_id
#JSON 参数 修改的内容
{
"title": "测试",
"context": "修改文档测试"
}
局部修改
post /index/_update/_id
# JSON 参数个格式
{
"doc":{ #修改的参数 }
}
删除文档
delete /index/_doc/_id
删除案例
条件查询
get inex/_search
#JSON 请求格式
{
"query": {
"match": {
#条件
}
}
}
全量查询\分页\排序
get /inex/_search
{ //查询
"query": {
//全部查询
"match_all": {}
},
//页码
"from": 0,
//每页数量
"size": 2,
//展示那些 字段
"_source": [
"字段"
],
//排序
"sort": {
//参与排序的元素
"指定字段": {
"order": "asc"
}
}
}
多条件查询
get /index/_mearch
{
"query": {
"bool": {
//必须 类似 sql的and
"must": [
{
"match": {
"Field": ""
}
},
{
"match": {
"Field": "测试"
}
}
],
//或 类似 sql的or
"should": [
{
"match": {
"Field": ""
}
}
],
//过滤
"filter": {
//范围
"range": {
//字段
"Field": {
//大于
"gt": 3
}
}
}
}
}
}
全文索引
get /index/_mearch
{
"query": {
"match": {
"Field": "value"
}
}
}
完全匹配
get /index/_mearch
{
"query": {
"match_phrase": {
"Field": "value"
}
}
}
字段高亮显示
get /index/_mearch
{
"query": {
"match": {
"Field": "value"
}
},
"highlight": {
"fields": {
"Field": {}
}
}
}
聚合操作