获取健康值
GET /_cat/health
新增索引
PUT /test2
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "long"
},
"birthday":{
"type": "date"
}
}
}
}
获取索引
GET /test2
获取索引状态
GET /_cat/indices?v
新增文档
PUT /test1/type1/1
{
"name":"Stars",
"link":"http://www.88sv.cn"
}
获取指定文档
GET /test1/type1/1
更新文档
POST /test3/_doc/1/_update
{
"name":"张三1",
"age":24,
"birthday":"2021-08-10"
}
删除文档
DELETE /test1
按照name查询文档
GET /test1/user/_search?q=name:张三
GET /test1/user/_search
{
"query":{
"match": {
"name": "张三"
}
}
}
查询字段过滤
GET /test1/user/_search
{
"query":{
"match": {
"name": "张三"
}
},
"_source":["name","desc"]
}
查询结果排序
GET /test1/user/_search
{
"query":{
"match": {
"name": "张三"
}
},
"_source":["desc","name"],
"sort":[
{
"age":{
"order":"desc"
}
}
]
}
查询结果分页
GET /test1/user/_search
{
"query":{
"match": {
"name": "张三"
}
},
"_source":["desc","name"],
"sort":[
{
"age":{
"order":"desc"
}
}
],
"from":0,
"size":10
}
多条件精确查询
- must(相当于mysql中的and)
GET /test1/user/_search
{
"query":{
"bool": {
"must": [
{
"match": {
"name": "张三"
}
},{
"match": {
"age": 23
}
}
]
}
}
}
- should(相当于mysql中的or)
GET /test1/user/_search
{
"query":{
"bool": {
"should": [
{
"match": {
"name": "张三"
}
},{
"match": {
"age": 23
}
}
]
}
}
}
- must_not(相当于mysql中的not)
GET /test1/user/_search
{
"query":{
"bool": {
"must_not": [
{
"match": {
"age": 23
}
}
]
}
}
}
- 范围筛选
- lt小于
- lte小于等于
- gt大于
- gte大于等于
GET /test1/user/_search
{
"query":{
"bool": {
"must": [
{
"match": {
"name": "张三"
}
}
],
"filter": [
{
"range": {
"age": {
"gte": 10,
"lte": 30
}
}
}
]
}
}
}
GET /test1/user/_search
{
"query":{
"match": {
"tags": "男 技术"
}
}
}
关于分词:
term:直接精准查询
match:会使用分词器解析
GET test1/user/_search
{
"query":{
"match": {
"name": "张三"
}
},
"highlight":{
"fields": {
"name":{}
}
}
}
高亮显示
- 默认高亮
GET test1/user/_search
{
"query":{
"match": {
"name": "张三"
}
},
"highlight":{
"fields": {
"name":{}
}
}
}
- 自定义高亮
GET test1/user/_search
{
"query":{
"match": {
"name": "张三"
}
},
"highlight":{
"pre_tags": "<span style='color:red;'>",
"post_tags": "</span>",
"fields": {
"name":{}
}
}
}