mongo、es用的比较多,mysql现在不常用,留作备份
mongo 基本语法
- 更新某个collection数据
# 匹配公司名称后,修改site和lastseen,并将from字段更新(不存在时才添加)
col_company.update(
{'name': companyname},
{'$set': {'site': site, 'lastseen': lastseen},'$addToSet':{"from":fromwhere}}
)
# 返回: {'n': 0, 'nModified': 0, 'ok': 1.0, 'updatedExisting': False} n代表有无执行
- 删除数组中的数据
db.Company.update({'from':null},{'$pop':{"from":1}},true,true)
# 第一个true表示多行更新,第二个为找不到的情况下是否插入
- 查看表中vulns字段中的list是否存在数据
db.getCollection('IPaddr').find({'vulns.0':{$exists:true}})
mysql基本语法
- 某个字段含空格
"select ID from vuln.vulns_all where `Plugin Name` = %s "%repr(pluginname)
- 查询某个字段
select * from vuln.new_vulns_all WHERE ID= 'xxVULN_2019xxxx_0xxx';
- 更新某个字段的数据
UPDATE vuln.new_vulns_all SET Status='未xx' WHERE ID= 'xxVULN_2019xxxx_0xxx';
- 删除数据库的某个表的所有数据
delete from vvv.xxx_xxxx_all;
- 统计某个数据表的数量
SELECT count(*) FROM vvv.xxx_xxxx_all where xxx <> '未知' ;
- 去重后的数量
select count(distinct SIG_hhh) FROM vvv.xxx_xxxx_all;
- mysql 以json格式输出
SELECT json_object('Status', Status,'Owner', Owner ) FROM db.table where Status = '未修复' and Owner_num <> xx;
- 查询非空数据
select * from table where item is null;
elasticsearch 查询语法
- 多条件组合查询
{
"query": {
"bool" : {
"must" : {
"term" : { "user" : "kimchy" }
},
"filter": {
"term" : { "tag" : "tech" }
},
"must_not" : {
"range" : {
"age" : { "gte" : 10, "lte" : 20 }
}
},
"should" : [
{ "term" : { "tag" : "wow" } },
{ "term" : { "tag" : "elasticsearch" } }
],
"minimum_should_match" : 1,#说明
"boost" : 1.0
}
}
}
有时候会发现should匹配的数据,并不是自己想要的.通过 minimum_should_match 参数控制需要匹配的 should 语句的数量, 它既可以是一个绝对的数字,也可以为百分数。
- 模糊查询
{
"wildcard":{#保留字
"itemname":{
"value":"*RTF_Generic*"#keyword
}
}
}
- 聚合
"aggs": {
"fileHash": {
"terms": {
"field": "fileHash",
"size": ES_AGGREATE_NUM
},
"aggs": {
"useremail":{
"terms":{
"field":"UserName",
"size": ES_AGGREATE_NUM
}
}
}
}
}