ZPY博客

elasticsearch7 x某一个字段完全匹配,其它字段里模糊匹配的

---
title: ElasticSearch7.x某一个字段完全匹配,其它字段里模糊匹配的写法
date: 2019-11-08 08:03:37
categories: 全文检索
tags:
- elasticsearch
- 7.x
- 完全匹配
- 字段
- must
- bool
- match
- multi_match
---

现在es里有四个字段,分别是title,content,author,type,现在想指定type和keyword,在指定的type里搜索keyword,在官方文档里找了关天也没有找到相应的例子,网上找了下,由于这个比较难描述,也没有什么相符合的。

无意间看到must可以嵌套,这就好搞了。query DSL写法如下:

GET /_search
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
          "query": "集团",
          "fields": ["title","content","author"]
        }
        },
        {
          "bool": {
            "must": [
              {
                "match": {
                  "type": "专题"
                }
              }
            ]
          }
        }
      ]
    }
  }
}