es命令测试
1.新建索引并赋值 :put/索引名/文档名/id //文档名后面会逐渐取消 相当表
PUT /test1/type1/1
{
"nmae":"hb",
"age":"3"
}
错误现象:
使用 Elasticsearch Head 查看“数据浏览”时,右侧不出数据,使用浏览器F12查看后,发现 406 Not Acceptable 错误。
解决方法
1、进入 es-head 安装目录;
2、cd _site/
3、编辑 vendor.js 共有两处
将 6886行 contentType: "application/x-www-form-urlencoded"
修改为 contentType: "application/json;charset=UTF-8"
然后再将 7574行 var inspectData = s.contentType === "application/x-www-form-urlencoded"
&& 修改为 var inspectData = s.contentType === "application/json;charset=UTF-8" &&
4、强制刷新浏览器验证。
2.新建索引并给字段设置类型(创建索引一般不用例1 因为没有设定字段类型 没规则不符合开发要求)
PUT /test2
{
"mappings":{
"properties":{
"name":{
"type":"text"
},
"age":{
"type":"long"
},
"birthday":{
"type":"date"
}
}
}
}
3.查看索引
GET /test1
4.覆盖索引
PUT /test1/_doc/1
{
}
5.修改索引 修改
POST /test1/_doc/1_update
{
"doc":{
"name":"hh"
}
}
6.删除索引
DELETE test1
7.基本的查询
GET 索引名/doc名/_search?q=查询条件
如:GET test1/_doc/_search?q=name:"hb"
8.复杂的查询(排序 分页 高亮 模糊查询 精准查询!)
//match为匹配查询 _source为指定查询返回结果的字段 sort指定排序方式 from和size表示分页
GET test1/_doc/_search
{
"query":{
"match":{
"name":"hb"
}
},
"_source":["name","age"],
"sort":[
{
"age":{"order":"desc"}
}
],
"from":0,
"size":20,
}