Elasticsearch复习笔记

发布于:2025-02-10 ⋅ 阅读:(48) ⋅ 点赞:(0)

ElasticSearch

  • 倒排索引
    keyword id (倒排索引)

name 1001
zhang 1002

基础操作

索引操作

创建索引
  • index就是等于database (索引)发送put请求 (不能使用功能post)
  • /shoping 就是创建索引
获取索引详细信息
  • /_cat/indices?v 使用get的方式
删除索引
  • /shopping 使用delete

操作文档

  • 是直接在索引中添加的
添加文档
  • post请求
  • 请求体是json格式 放入要存储的数据
  • /shopping/_doc/1001 (这个就是自己的id)
  • /shopping/_create/1001
获得文档
  • 使用get的方式
  • /shopping/_doc/1001
  • 获得这个文档的下的所有的:/shopping/_search
修改
  • 使用put方式
  • 全量数据的修改 /shopping/_doc/1001 然后body里面携带内容
  • 局部修改 /shopping/_update/1001 使用post方式 { “doc”:{“title”:“nihao”}}
删除
  • /shopping/_doc/1001 使用delete请求
条件查询
  • get
  • /shopping/_search?q=category:小米
  • 使用请求体来传递条件 /shopping/_search
    {
    “query”:{
    “match” :{
    “category”:“小米”
    }
    }
    }
  • 全量查询
    {
    “query”:{
    “match_all” :{
    “category”:“小米”
    }
    },
    “form”:0,//从第几条开始
    “size”:2,// 每页显示两条
    “_source”:[“title”],
    “sort”:{
    “price”:{
    “order”:“des”
    }
    }
    }
多条件查询

-同时成立
{
“query”:{
“bool”:{
“must”:[{
“match”:{
“category”:“小米”
}
},{
“match”:{
“price”:3999.00
}
}]
}
}
}

  • 其中一个成立
    {
    “query”:{
    “bool”:{
    “should”:[{
    “match”:{
    “category”:“小米”
    }
    },{
    “match”:{
    “category”:“华为”
    }
    }]
    },
    “filter”:{
    “range”:{
    “price”:{
    “gt”:2000
    }
    }
    }
    }
    }
  • 大于成立
    {
    “query”:{
    “bool”:{
    “should”:[{
    “match”:{
    “category”:“小米”
    }
    },{
    “match”:{
    “category”:“华为”
    }
    }],
    “filter”:{
    “range”:{
    “price”:{
    “gt”:2000
    }
    }
    }
    }
    }
    }
  • 看别人写的笔记 https://blog.csdn.net/u011863024/article/details/115721328

网站公告

今日签到

点亮在社区的每一天
去签到