ElasticSearch中关键字和文本之间的区别 [英] Difference between keyword and text in ElasticSearch

查看:184
本文介绍了ElasticSearch中关键字和文本之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以举例说明在ElasticSearch中关键字和文本之间的区别吗?

Can someone explain the difference between keyword and text in ElasticSearch with an example?

推荐答案

关键字类型:
,如果您将字段定义为此类关键字。

keyword type: if you define a field to be of type keyword like this.

 PUT products
{
  "mappings": {
    "_doc": {
      "properties": {
        "name": {
          "type": "keyword"
        }
      }
    }
  }
}

然后在此字段上进行查询时,您必须插入整个值(关键字搜索),即关键字字段。

Then when you make a search query on this field you have to insert the whole value (keyword search) so keyword field.

 POST products/_doc
{
  "name": "washing machine"
}

当您执行以下搜索时:

 GET products/_search
{
  "query": {
    "match": {
      "name": "washing"
    }
  }
}

它将不匹配任何文档。

it will not match any docs. You have to search with the whole word "washing machine".

文本类型会被分析,并且您可以使用来自字段值。 全文搜索

text type on the other hand is analyzed and you can search using tokens from the field value. a full text search in the whole value:

    PUT products
{
  "mappings": {
    "_doc": {
      "properties": {
        "name": {
          "type": "text"
        }
      }
    }
  }
}

搜索:

 GET products/_search
{
  "query": {
    "match": {
      "name": "washing"
    }
  }
}

将返回匹配的文档。

您可以检查此内容以获取更多详细信息关键字Vs。文字

You can check this to more details keyword Vs. text

这篇关于ElasticSearch中关键字和文本之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆