elasticsearch 语法

匹配

按照条件匹配

精准匹配

区间范围匹配

匹配字段过滤

多条件查询

高亮查询

//创建索引
PUT /test/type/1
{
  "name":"小白说elasticseach",
  "age":"28"
}

//设置属性
PUT /test1
{
  "mappings": {
    "properties": {
      "name": {
        "type":"text"
      },
      "birthday": {
        "type":"date"
      }
    }
  }
}
//查询
GET test

//新增
PUT  /test3/_doc/1
{
  "name":"小白",
  "age":"28",
  "brithday":"1997-06-08"
}

GET test3
//健康
GET  _cat/health
//版本
GET _cat/indices?v
//更新
POST /test3/_doc/1/_update
{
  "doc":{
    "age":"66"
  }
}
//删除
DELETE test1

//操作文档
PUT /xiaobai/user/1
{
  "name":"小白",
  "age":23,
  "des":"elasticsearch",
  "tags":["吹","拉","谈","唱"]
}
PUT /xiaobai/user/2
{
  "name":"小艾",
  "age":25,
  "des":"Kibana",
  "tags":["琴","棋","书","画"]
}
PUT /xiaobai/user/4
{
  "name":"小水",
  "age":28,
  "des":"ik",
  "tags":["偷","歼","耍","滑"]
}


GET xiaobai/user/1

POST xiaobai/user/1/_update
{
  "doc":{
    "age": 28
  }
}

//查询
GET  xiaobai/user/_search?q=name:小

//指定字段查询
GET  xiaobai/user/_search
{
  "query": {
    "match": {
      "name": "小白"
    }
  },
  "_source": ["name","tags"]
}

//倒叙查询
GET  xiaobai/user/_search
{
  "query": {
    "match": {
      "name": "小白"
    }
  },
  "sort": [
    {
      "age": {
        "order": "desc"
      }
    }
  ]
}
//分页查询
GET  xiaobai/user/_search
{
  "query": {
    "match": {
      "name": "小白"
    }
  },
  "sort": [
    {
      "age": {
        "order": "desc"
      }
    }
  ],
  "from": 0,
  "size": 2
}
//多条件查询(and)
GET  xiaobai/user/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "白"
          }
        },
        {
          "match": {
            "age": "28"
          }
        }
      ]
    }
  }
}

//(or) should 查询
GET  xiaobai/user/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name": "白"
          }
        },
        {
          "match": {
            "age": "28"
          }
        }
      ]
    }
  }
}

//不包含查询  (not)
GET  xiaobai/user/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "match": {
            "age": "3"
          }
        }
      ]
    }
  }
}
//过滤查询   
//gt    大于
//gte   大于等于
//lt    小于
//lte   小于等于

GET  xiaobai/user/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "小白"
          }
        }
      ],
      "filter":{
        "range": {
          "age": {
            "gte": 0,
            "lte": 10
          }
        }
      }
    }
  }
  
}

//多匹配查询
GET  xiaobai/user/_search
{
  "query": {
     "match": {
       "tags": "偷 画"
     }
  }
}

//精确查询(倒排索引)
GET  xiaobai/user/_search
{
  "query": {
    "term": {
      "name": {
        "value": "小水"
      }
    } 
  }
}

//高亮查询
GET  xiaobai/user/_search
{
  "query": {
    "term": {
      "name": {
        "value": "小"
      }
    }
  },
  "highlight": {
    "pre_tags": "<p color=red> ",
    "post_tags": "</p>", 
    "fields": {
      "name":{}
    }
  }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值