Elasticsearch常用操作

问题

硬盘满了,不能写入数据,如何解决

清理硬盘,然后解锁索引,*表示针对所有索引,可写指定的索引名称

curl -X PUT 'http://127.0.0.1:9200/*/_settings' -H "Content-Type: application/json" -d '{"index.blocks.read_only_allow_delete":null}'

索引操作

如何查看所有索引的使用状况

curl -X GET 'http://localhost:9200/_cat/indices?v'

如何删除索引数据

常用方式

curl -X POST 'http://localhost:9200/index_name/_delete_by_query' -H 'Content-Type: application/json' -d '
{"query": {"match_all": {}}}'

快速方式,需要创建索引

curl -X DELETE 'http://localhost:9200/index_name' -H 'Content-Type: application/json'

查询

获取索引的一条数据

通过size控制

curl -X GET http://localhost:9200/index_name/_search -H 'Content-Type: application/json' -d '
{
  "query": {
    "match_all": {}
  },
  "size": 1
}'

字符串条件

等于
curl -X GET http://localhost:9200/index_name/_search -H 'Content-Type: application/json' -d '
{
  "query": {
    "match": {
      "name": "测试删除"
    }
  }
}'
包含
curl -X GET http://localhost:9200/index_name/_search -H 'Content-Type: application/json' -d '
{
  "query": {
  "match_phrase": {
    "event": "喜欢 推销"
    }
  }
}'

查询结果排序

curl -X GET http://localhost:9200/index_name/_search -H 'Content-Type: application/json' -d '
{
  "query": {
    "match_all": {}
  },
  "sort": [{           // multi condition
    "timestamp": {
      "order": "desc"  // asc and desc
    }
  }],
  "size": 10
}'

查询结果聚合计数

curl -X GET http://localhost:9200/index_name/_search -H 'Content-Type: application/json' -d '
{
  "size": 0,  // 不需要显示数据
  "aggs": {   // 缩写,全称是aggregations
    "format_name": {                       // 定义一个聚合的名字
      "terms": {                           // 定义单个桶(集合)的类型为 terms
        "field": "data.format.keyword"     // 按照field指定的字段进行分类
      }
    }
  }
}'

查询结果聚合过滤

curl -X GET http://localhost:9200/index_name/_search -H 'Content-Type: application/json' -d '
{
  "query": {
    "bool": {
      "must": [
        {"term": {
          "alert.signature.threat_type.keyword": {
            "value": ""
          }
        }}
      ]
    }
  },
  "aggs": {   
    "NAME": {                       
      "terms": {                           
        "field": "alert.signature.behavior.keyword",
        "size": 10
      }
    }
  },
  "size": 0
}'

删除

curl -X POST http://localhost:9200/index_name/_delete_by_query -H 'Content-Type: application/json' -d '
{"query": {"match": {"name": "测试删除"}}}'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值