简体   繁体   English

ES 7 - 使用匹配查询和过滤器

[英]ES 7 - Use match query with filters

I use ElasticSearch 7.0, and I have this simple query:我使用 ElasticSearch 7.0,我有这个简单的查询:

"bool": {
    "must": {
        "match": {
            "title": {
                "query": "engineer"
            }
        }
    },
    "filter": {
        "0": {
            "term": {
                "type_id": 1
            }
        },
        "term": {
            "active": 1
        }
    }
}

And I get this error:我得到这个错误:

[match] malformed query, expected [END_OBJECT] but found [FIELD_NAME] [匹配] 格式错误的查询,应为 [END_OBJECT],但找到了 [FIELD_NAME]

I tried:我试过了:

"must": {
    "match": {
        "title": "engineer"
    }
},

But same error, I can't see my syntax mistake here?但是同样的错误,我在这里看不到我的语法错误? I have same query working with multimatch with same filters.我有相同的查询使用具有相同过滤器的多重匹配。

Your filters must be enclosed in an array, like this:您的过滤器必须包含在一个数组中,如下所示:

{
  "bool": {
    "must": {
      "match": {
        "title": {
          "query": "engineer"
        }
      }
    },
    "filter": [
      {
        "term": {
          "type_id": 1
        }
      },
      {
        "term": {
          "active": 1
        }
      }
    ]
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM