• elasticsearch的基本操作


    创建索引

    put /shopping

    查看索引

    get /_cat/indices?v

    查看单个索引

    get /shooping

    删除索引

    delete /shopping

    #创建文档,添加数据就是创建文档
    post /shopping/_doc
    {
    “title”:“小米手机”,
    “category”:“小米”,
    “images”:“http://www.hahhahhah.com/xm.jpg”,
    “price”:3999.00
    }

    查看文档

    get /shopping/_odc/1

    #修改文档
    #完全覆盖,全量更新

    put /shopping/_doc/1001(自定的id)
    {
    “title”:“小米手机”,
    “category”:“小米手机”,
    “images”,:“klasjklafsdlkfsdalf”
    “price”:“4999.00”
    }

    部分修改

    post /shopping/_doc/101
    {
    “doc”:{
    “title”:“华为手机”
    }
    }

    #ES的条件查询

    get /shopping/_search
    {
    “query”:{
    “match”:{
    “category”:“小米”
    }
    }
    }

    全量查询

    get /shopping/_search
    {
    “query”:{
    “match_all”:{}
    }
    }

    分页查询&排序

    get /shopping/_search
    {
    “query”:{
    “match_all”:{
    }
    },
    “from”:0, #起始位置
    “size”:2,
    “sort”:{
    “price”:{
    “order”:“desc”#asc
    }
    }
    }

    #多条件查询

    must:必须是条件同时满足 should:条件满足一个就行了

    get /shopping/_search
    {
    “query”:{
    “bool”:{ # 条件参数
    “must”:[ #多个条件同时成立
    {
    “match”:{
    “category”:“小米”
    }
    },
    {
    “match”:{
    “price”:1999.00
    }
    }
    ],
    “filter”:{ # 条件查询
    “range”:{
    “gt” : 3000
    }
    }
    }
    }
    }

    匹配

    match_phrase:完全匹配 match:全文检索匹配

    get /shopping/_search
    {
    “query”:{
    “match_phrase”:{ #完全匹配
    “category”: “小米”
    },
    “highlight”:{
    “fields”:{
    “category”:{

    }
    }
    }
    }
    }

    #聚合

    avg:平均值 terms:分组

    get /shopping/_search
    {
    “aggs”:{ # 聚合操作
    “price_group”:{ # 名称,随便起的
    “terms”:{ # 分组操作
    “field”:“price” # 分组字段
    }
    }
    }
    “size”:0
    }

    映射

    put /user/_mapping
    {
    “properties”:{
    “name”:{
    “type”:“text”,#单匹配
    “index”:true
    },
    “sex”:{
    “type”:“keyword”, #全量匹配
    “index”:true
    },
    “tel”:{
    “type”:“keyword”, #
    “index”:true
    }
    }
    }

  • 相关阅读:
    Mysql 45讲学习笔记(二十四)MYSQL主从一致
    面试系列Spring:Spring的事务传播
    HDL-Bits 刷题记录 02
    spring源码之下载及构建
    Go语言之channel实现原理
    优麒麟安装完后设置root密码
    第6周学习:Vision Transformer & Swin Transformer
    【stm32】外部中断接口函数
    MYSQL之DML(数据库操作语言)
    (附源码)node.js物资管理系统 毕业设计 071130
  • 原文地址:https://blog.csdn.net/mklmlkj/article/details/126497608