您的位置:首页 > 其它

ES 基本使用《三》--terms

2017-10-19 17:32 169 查看
1.查找多个精确值

 
term
 查询对于查找单个值非常有用,但通常我们可能想搜索多个值。 如果我们想要查找价格字段值为
$20 或 $30 的文档该如何处理呢?

不需要使用多个 
term
 查询,我们只要用单个 
terms
 查询(注意末尾的 s ), 
terms
 查询好比是 
term
 查询的复数形式(以英语名词的单复数做比)。

它几乎与 
term
 的使用方式一模一样,与指定单个价格不同,我们只要将 
term
 字段的值改为数组即可:
{
"terms" : {
"price" : [20, 30]
}
}

带评分的DSL:

GET /my_store/products/_search
{
"query": {
"terms": {
"price": [
"20",
"30"
]
}
}
}

不带评分:

GET /my_store/products/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"price": [
"20",
"30"
]
}
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ES 索引 terms