mysql 字段="value" elasticsearch

mysql field="value" in elasticsearch

我想在 "google" 搜索时只显示包含该词本身的项目 我怎样才能只搜索只有单词 "google" 的项目?

请求正文 (在邮递员中创建请求)

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "body": "google"
          }
        }
      ]
    }
  }
}

响应正文 (在邮递员中创建请求)

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 0.6587735,
    "hits": [
      {
        "_index": "s_t",
        "_type": "_doc",
        "_id": "3",
        "_score": 0.6587735,
        "_source": {
          "body": "google"
        }
      },
      {
        "_index": "s_t",
        "_type": "_doc",
        "_id": "4",
        "_score": 0.5155619,
        "_source": {
          "body": "google map"
        }
      },
      {
        "_index": "s_t",
        "_type": "_doc",
        "_id": "5",
        "_score": 0.5155619,
        "_source": {
          "body": "google-map"
        }
      }
    ]
  }
}

我需要这个输出 (在邮递员中创建请求)

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 0.69381464,
    "hits": [
      {
        "_index": "s_t",
        "_type": "_doc",
        "_id": "3",
        "_score": 0.69381464,
        "_source": {
          "body": "google"
        }
      }
    ]
  }
}

在 mysql 中,通过这个查询我达到了我的目标。

mysql 中的类似查询:

select * from s_t where body='google'

好吧,我假设您在映射中自动映射或使用文本。 在查询中指定 .keyword。请注意区分大小写。

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "body.keyword": "google"
          }
        }
      ]
    }
  }
}

如果您只想使用完全匹配查询您的正文字段。您需要使用关键字重新索引它。看看: