DSL语句
GET /idx_hippo_sku_statistics_index/sku_statistics_index/_search
{
"from" : 0,
"size" : 100,
"query" : {
"bool" : {
"must":[
{
"range" : {
"salePrice" : {
"from" : 1.9,
"to" : 2.1,
"include_lower": true,
"include_upper": true
}
}
}
,
{
"bool": {
"must": {
"term": {
"cityId": 136
}
}
}
}
]
}
},
"sort": [
{
"salePrice": "asc"
}
],
"_source": ["productName","salePrice"]
}
"_source": ["productName","salePrice"] 表示查询的结果集只返回 这里面的字段;
"sort": [ { "salePrice": "asc" } ], 表示根据salePrice 字段做升序排序;
"range" : { "salePrice" : { "from" : 1.9, "to" : 2.1, "include_lower": true, "include_upper": true } }
根据 salePrice 查询在>= 1.9 ,小于等于2.1 的数据;
include_lower 为true 表示 >=
include_upper 为true 表示<=
term 查询,类似mysql = 查询;
这篇博客探讨了DSL语句如何在Elasticsearch中用于数据查询和过滤。通过示例展示了如何使用布尔查询、范围查询以及排序来获取价格在1.9到2.1之间的商品,并按价格升序排列。同时,只返回指定的源字段并优化了查询性能。
8861

被折叠的 条评论
为什么被折叠?



