要不要也来分享分享一下啊

es6.Xrange过滤器,区间值有多个如何构建json查询?

Elasticsearch | 作者 flyfeifei66 | 发布于2018年02月12日 | 阅读数:3161

{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "测试",
"fields": [
"content"
]
}
},
"filter": [
{
"range": {
"count": {
"gte": 100,
"lte": 105
}
}
},
{
"range": {
"price": {
"gte": 82,
"lte": 82
}
}
},
{
"terms": {
"channel": [
"bbc",
"bc"
]
}
}
]
}
}
}
现在只搞定了range是区间一个的情况,我觉得可以用should,但是如果有多个条件都是多个区间,json就会变的复杂,有没有像term/terms那样的语法?
已邀请:

flyfeifei66

赞同来自:


{
"min_score": "0.01",
"from": 0,
"size": 5,
"query": {
"bool": {
"must": {
"multi_match": {
"query": "测试",
"fields": [
"content"
]
}
},
"filter": [
{
"terms": {
"channel": [
"bbc",
"bc"
]
}
},
{
"bool": {
"should": [
{
"range": {
"price": {
"gte": 80,
"lte": 82
}
}
},
{
"range": {
"price": {
"gte": 83,
"lte": 100
}
}
}
]
}
},
{
"bool": {
"should": [
{
"range": {
"count": {
"gte": 103,
"lte": 104
}
}
},
{
"range": {
"count": {
"gte": 105,
"lte": 106
}
}
}
]
}
}
]
}
},
"highlight": {
"fields": {
"title": {
"pre_tags": "[<b>]",
"post_tags": "[</b>]"
},
"content": {
"pre_tags": "[<b>]",
"post_tags": "[</b>]"
}
}
},
"sort": {
"count": "asc",
"_score": "desc"
}
}
用bool搞定了,老是觉得应该有更简介的语法,类似term terms

要回复问题请先登录注册