1.filter查询语句
1)通过filter可以获取想要的数据
2)通过filter查询有缓存,大大提高查询效率,所以推荐使用filter查询
2.cache缓存
3.实例数据,准备数据:
POST /store/products/_bulk
{"index":{"_id":1}}
{"price":10,"productID":"SD1002136"}
{"index":{"_id":2}}
{"price":20,"productID":"SD2678421"}
{"index":{"_id":3}}
{"price":30,"productID":"SD8897573"}
{"index":{"_id":4}}
{"price":40,"productID":"SD4535233"}
4.查看测试数据
GET /store/products/_mget
{
"ids":[1,2,3,4]
}
5.filter查询
最简单的filter查询
先看看sql语句: select document from products where price = 20
filter的语句
GET /store/products/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"term": {
"price": "20"
}
}
}
}
}
也可以指定多个值
GET /store/products/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"terms": {
"price": [
"10",
"20"
]
}
}
}
}
}
再看另一个 select * from products where productId = "SD4535233"
GET /store/products/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"term": {
"productID"