#查看所有索引
GET/_cat/indices?v
#删除某个索引
DELETE/skuinfo
#新增索引
PUT/user
#创建映射
PUT/user/userinfo/_mapping
{"properties": {"name":{"type": "text","analyzer": "ik_smart","search_analyzer": "ik_smart","store": false},"city":{"type": "text","analyzer": "ik_smart","search_analyzer": "ik_smart","store": false},"age":{"type": "long","store": false},"description":{"type": "text","analyzer": "ik_smart","search_analyzer": "ik_smart","store": false}
}
}
#新增文档数据 id=1PUT/user/userinfo/1{"name":"李四","age":22,"city":"深圳","description":"李四来自湖北武汉!"}
#新增文档数据 id=2PUT/user/userinfo/2{"name":"王五","age":35,"city":"深圳","description":"王五家住在深圳!"}
#新增文档数据 id=3PUT/user/userinfo/3{"name":"张三","age":19,"city":"深圳","description":"在深圳打工,来自湖北武汉"}
#新增文档数据 id=4PUT/user/userinfo/4{"name":"张三丰","age":66,"city":"武汉","description":"在武汉读书,家在武汉!"}
#新增文档数据 id=5PUT/user/userinfo/5{"name":"赵子龙","age":77,"city":"广州","description":"赵子龙来自深圳宝安,但是在广州工作!","address":"广东省茂名市"}
#新增文档数据 id=6PUT/user/userinfo/6{"name":"赵毅","age":55,"city":"广州","description":"赵毅来自广州白云区,从事电子商务8年!"}
#新增文档数据 id=7PUT/user/userinfo/7{"name":"赵哈哈","age":57,"city":"武汉","description":"武汉赵哈哈,在深圳打工已有半年了,月薪7500!"}
#根据ID查询
GET/user/userinfo/4#更新数据,id=4覆盖原来的数据
PUT/user/userinfo/4{"name":"张三丰","description":"在武汉读书,家在武汉!在深圳工作!"}
#恢复文档数据 id=4PUT/user/userinfo/4{"name":"张三丰","age":66,"city":"武汉","description":"在武汉读书,家在武汉!"}
#使用POST更新某个域的数据 , 不会覆盖原来的数据
POST/user/userinfo/4/_update
{"doc":{"name":"张三丰","description":"在武汉读书,家在武汉!在深圳工作!"}
}
#删除数据
DELETE user/userinfo/4#查询某个类型(表)的所有数据
GET/user/userinfo/_search
#查询索引库(数据库)所有
GET/user/_search
#搜索排序
GET/user/userinfo/_search
{"query":{"match_all": {}
},"sort":{"age":{"order":"desc"}
}
}
#分页实现
GET/user/userinfo/_search
{"query":{"match_all": {}
},"sort":{"age":{"order":"desc"}
},"from": 0,"size": 2}
#过滤查询-term 完全匹配
GET/user/userinfo/_search
{"query":{"term":{"city":"武汉"}
}
}
#过滤查询-terms 允许多个Term
GET/user/userinfo/_search
{"query":{"terms":{"city":
["武汉","广州"]
}
}
}
#过滤-range 范围过滤
#gt表示> gte表示=>#lt表示< lte表示<=GET/user/userinfo/_search
{"query":{"range": {"age": {"gte": 30,"lte": 57}
}
}
}
#过滤搜索bool#must : 多个查询条件的完全匹配,相当于 and。
#must_not : 多个查询条件的相反匹配,相当于 not。
#should : 至少有一个查询条件匹配, 相当于 or。
GET/user/userinfo/_search
{"query": {"bool": {"must": [
{"term": {"city": {"value": "深圳"}
}
},
{"range":{"age":{"gte":20,"lte":99}
}
}
]
}
}
}
#查询所有 match_all
GET/user/userinfo/_search
{"query": {"match_all": {}
}
}
#字符串匹配
GET/user/userinfo/_search
{"query": {"match": {"description": "武汉"}
}
}
#多个域匹配搜索
GET/user/userinfo/_search
{"query": {"multi_match": {"query": "深圳","fields": ["city","description"]
}
}
}
#前缀匹配 prefix
GET/user/userinfo/_search
{"query": {"prefix": {"name": {"value": "赵"}
}
}
}