布隆过滤器
一个 bool 过滤器由三部分组成:
{
“bool” : {
“must” : [],
“should” : [],
“mustnot” : [],
}
}must
所有的语句都 必须(must) 匹配,与 AND
等价。must_not
所有的语句都 不能(must not)_ 匹配,与 NOT
等价。should
至少有一个语句要匹配,与 OR
等价。
例子一
SELECT product
FROM products
WHERE (price = 20 OR productID = “XHDK-A-1293-#fJ3”)
AND (price != 30)
GET /my_store/products/_search
{
"query" : {
"filtered" : { //将所有查询包装起来
"filter" : {
"bool" : {
"should" : [
{ "term" : {"price" : 20}},
{ "term" : {"productID" : "XHDK-A-1293-#fJ3"}}
],
"must_not" : {
"term" : {"price" : 30}
}
}
}
}
}
}
例子二
SELECT document
FROM products
WHERE productID = “KDKE-B-9947-#kL5”
OR ( productID = “JODL-X-1937-#pV7”
AND price = 30 )
GET /my_store/products/_search
{
"query" : {
"filtered" : {
"filter" : {
"bool" : {
"should" : [
{ "term" : {"productID" : "KDKE-B-9947-#kL5"}},
{ "bool" : {
"must" : [
{ "term" : {"productID" : "JODL-X-1937-#pV7"}},
{ "term" : {"price" : 30}}
]
}}
]
}
}
}
}
}
例子三-范围查找
gt
:>
大于(greater than)lt
:<
小于(less than)gte
:>=
大于或等于(greater than or equal to)lte
:<=
小于或等于(less than or equal to)
SELECT document
FROM products
WHERE price BETWEEN 20 AND 40
GET /my_store/products/_search
{
"query" : {
"constant_score" : {
"filter" : {
"range" : {
"price" : {
"gte" : 20,
"lt" : 40
}
}
}
}
}
}
日期
“range” : {
“timestamp” : {
“gt” : “2014-01-01 00:00:00”,
“lt” : “2014-01-07 00:00:00”
}
}
查找时间戳在过去一小时内的所有文档:
“range” : {
“timestamp” : {
“gt” : “now-1h”
}
}
加一个月查询
“range” : {
“timestamp” : {
“gt” : “2014-01-01 00:00:00”,
“lt” : “2014-01-01 00:00:00||+1M”
}
}