添加文档---记录
put /qy151/student/1
{
"name":"张三",
"age":15
}
POST /qy151/student
{
"name":"张三1",
"age":14
}
创建索引---数据库
PUT /qy150
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "integer"
}
}
}
}
删除所有---数据库
DELETE /qy150
查询有哪些索引
GET /_cat/indices?v
查询索引的结构
get /qy151
查询文档---id查询
PUT /qy151/student/2
{
"name":"李四",
"age":15
}
查询文档---id查询
GET /qy151/student/1
删除文档---
DELETE /qy151/student/2
# 修改---这种修改必须要求指定所有列,如果只指定部分列,则原来其他列消失
PUT /qy151/student/1
{
"name":"王五"
}
# 只修改部分列
POST /qy151/student/1/_update
{
"doc":{
"age":14
}
}
根据条件搜索
get /qy151/student/_search?q=age:15
查询的条件封装成json数据
GET /qy151/_search
{
"query": {
"match": {
"age": "15"
}
},
"_source": ["name"],
"from": 1,
"size": 1
}
只想查询部分列 分页查询 排序
GET /qy151/_search
{
"query": {
"range": {
"age": {
"gt": 2
}
}
},
"_source": ["name","age"],
"from": 0,
"size": 10,
"sort": [
{
"age": {
"order": "asc"
}
}
]
}
. 多条件查询
GET /qy151/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"name": "张"
}
},
{
"match": {
"age": 15
}
}
]
}
}
}
高亮显示
GET /qy151/_search
{
"query": {
"bool": {
"must_not": [
{
"match": {
"name": "张"
}
}
]
}
}
}
text会分词 keyword不会
put /test
{
"mappings":{
"properties":{
"name":{
"type":"text"
},
"address":{
"type":"keyword"
}
}
}
}
put /test/_doc/1
{
"name":"你好啊",
"address":"我不好啊"
}
term精准匹配
get /test/_search
{
"query":{
"match": {
"address": "我不好啊"
}
}
}