Elasticsearch进行and,or多条件组合DSL结构化查询
2016-08-09 17:53
591 查看
【问题】
需要查询表中的条件sql语句如下:
SELECT * FROM tablename
【解决】
使用Elastic的DSL结构化查询语句,如下:
{
"query": {
"filtered": {
"query" : {
"match_all":{}
},
"filter" : {
"or" : [
{
"and" : [
{"term":{"md5": "6133216c851e44eaf2f47b4eea2bf2df"}},
{"term":{"dstip": "61.54.221.200"}}
]
},
{
"and" : [
{"term":{"fmd5": "59bb8a9905e0856f464b97d5db27bb4a"}},
{"term":{"ip": "none"}}
]
}
]
}
}
},
"from": 0,
"size": 10,
"sort": [],
"aggs": {}
}
【备注】
Elastic的term查询一般如下,只能进行一个字段的查询:
{
"query": {
"bool": {
"must": [
{
"term": {
"md5": "123123123123123"
}
},
{
"term": {
"dstip": "2.3.4.5"
}
}
],
"must_not": [],
"should": []
}
},
"from": 0,
"size": 10,
"sort": [],
"aggs": {}
}
哦了,解决Elastic的多条件组合查询问题!
需要查询表中的条件sql语句如下:
SELECT * FROM tablename
WHERE (md5='000000000000000000000000' AND dstip='1.2.3.4')
OR (fmd5='111111111111111111111' AND ip='5.6.7.8');
【解决】
使用Elastic的DSL结构化查询语句,如下:
{
"query": {
"filtered": {
"query" : {
"match_all":{}
},
"filter" : {
"or" : [
{
"and" : [
{"term":{"md5": "6133216c851e44eaf2f47b4eea2bf2df"}},
{"term":{"dstip": "61.54.221.200"}}
]
},
{
"and" : [
{"term":{"fmd5": "59bb8a9905e0856f464b97d5db27bb4a"}},
{"term":{"ip": "none"}}
]
}
]
}
}
},
"from": 0,
"size": 10,
"sort": [],
"aggs": {}
}
【备注】
Elastic的term查询一般如下,只能进行一个字段的查询:
{
"query": {
"bool": {
"must": [
{
"term": {
"md5": "123123123123123"
}
},
{
"term": {
"dstip": "2.3.4.5"
}
}
],
"must_not": [],
"should": []
}
},
"from": 0,
"size": 10,
"sort": [],
"aggs": {}
}
哦了,解决Elastic的多条件组合查询问题!
相关文章推荐
- 联合两个索引查询,已解决: 还有个进行多条件搜索 and 与 or 的操作
- Elasticsearch使用filter进行匹配关系and,or,not,range查询
- SQL 复合查询条件(AND,OR,NOT)对NULL值的处理
- 如何进行ibatis动态多条件组合查询以及模糊查询
- SQLServer复合查询条件(AND,OR,NOT)对NULL值的处理方法
- thinkphp多条件查询(AND, OR)
- Thinkphp 查询条件 and 和 or同时使用即复合查询
- 如何进行ibatis动态多条件组合查询以及模糊查询(oracle,mysql)
- sql: where条件中AND、OR运算符的组合使用
- mongo java中and、or多条件查询
- think组合查询AND和OR一起用
- SQL 复合查询条件(AND,OR,NOT)对NULL值的处理方法
- 通过组合条件对DAO进行查询操作
- Entity Framework 的多条件组合查询和 LIKE 查询(Combination search and simulate LIKE search with Entity Framework
- C#-WebForm-★★★LinQ-数据的条件组合查询并进行分页展示(未加各种限定)★★★
- iBatis中联合AND和OR进行查询
- 如何进行ibatis动态多条件组合查询以及模糊查询(oracle,mysql)
- ibatis按照or查询条件进行查询
- SQL: where条件中AND、OR运算符的组合使用
- MongoDB 组合多个条件查询($and、$in、$gte、$lte)