我在下面的查询中要在名称字段或消息字段中获取搜索词"Schwarz"
。语言必须为奥地利语,并且状态类型应等于提供的列表。我收到以下异常,但无法弄清原因:
QueryParsingException [[my_test_index] [_na]查询格式错误,start_object之后没有字段]; }]“,
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"term": {
"name": "Schwarz"
}
},
{
"term": {
"message": "Schwarz"
}
}
],
"minimum_should_match": 1
}
},
{
"terms": {
"status_type": [
"1",
"2",
"3",
"4",
"5",
"6",
"7"
]
}
},
{
"term": {
"language": "Austrian"
}
}
]
}
}
}
},
"sort": [
{
"total": {
"order": "desc"
}
}
]
}
这是没有筛选器仍然有效的查询:
{
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"match": {
"standard_analyzed_name": "Schwarz"
}
},
{
"match": {
"standard_analyzed_message": "Schwarz"
}
}
],
"must": [
{
"terms": {
"buzzsumo_status_type": [
"1",
"2",
"3",
"4",
"5",
"6",
"7"
]
}
},
{
"term": {
"language": "Austrian"
}
}
]
}
}
}
},
"sort": [
{
"total_interactions": {
"order": "desc"
}
}
]
}
最佳答案
在经过过滤的查询中,您必须具有过滤器部分,此处未提供。我建议像这样重写它,即将terms
和term
部分移到filter
部分:
{
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"term": {
"name": "Schwarz"
}
},
{
"term": {
"message": "Schwarz"
}
}
],
"minimum_should_match": 1
}
},
"filter": {
"bool": {
"must": [
{
"terms": {
"status_type": [
"1",
"2",
"3",
"4",
"5",
"6",
"7"
]
}
},
{
"term": {
"language": "Austrian"
}
}
]
}
}
}
},
"sort": [
{
"total": {
"order": "desc"
}
}
]
}
一种替代方法是不使用
filtered
查询,而只是像这样编写它:{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"term": {
"name": "Schwarz"
}
},
{
"term": {
"message": "Schwarz"
}
}
],
"minimum_should_match": 1
}
},
{
"terms": {
"status_type": [
"1",
"2",
"3",
"4",
"5",
"6",
"7"
]
}
},
{
"term": {
"language": "Austrian"
}
}
]
}
},
"sort": [
{
"total": {
"order": "desc"
}
}
]
}
关于elasticsearch - 嵌套 bool 应查询不能与最小值匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31863592/