问题
硬盘满了,不能写入数据,如何解决
清理硬盘,然后解锁索引,*
表示针对所有索引,可写指定的索引名称
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": "测试删除"}}}'