• 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
    }
    }
    }

  • 相关阅读:
    《PostgreSQL中的JSON处理:技巧与应用》
    数学学习经验
    Java中的泛型:高效编程的利器
    【HBZ分享】Mysql的InnoDB原理
    iOS开发进阶(八):ipa应用唤起并跳转至指定页面
    Java的JDBC编程
    LGFormer:LOCAL TO GLOBAL TRANSFORMER FOR VIDEO BASED 3D HUMAN POSE ESTIMATION
    Linux环境下socket通信服务器端权限问题
    程序和进程
    VideoScribe基础教程创建动画视频
  • 原文地址:https://blog.csdn.net/mklmlkj/article/details/126497608