ElasticSearch中关键字和文本的区别 [英] Difference between keyword and text in ElasticSearch
问题描述
谁能用一个例子解释一下 ElasticSearch 中关键字和文本的区别?
Can someone explain the difference between keyword and text in ElasticSearch with an example?
推荐答案
关键字 type:如果您将字段定义为这样的关键字类型.
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"
}
当你像这样执行搜索时:
when you execute search like this:
GET products/_search
{
"query": {
"match": {
"name": "washing"
}
}
}
它不会匹配任何文档.你必须用洗衣机"这个词来搜索.
it will not match any docs. You have to search with the whole word "washing machine".
text 类型被分析,您可以使用字段值中的标记进行搜索.在整个值中进行全文搜索:
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"
}
}
}
将返回一个匹配的文件.
will return a matching documents.
您可以查看更多详细信息关键字 Vs.文字
You can check this to more details keyword Vs. text
这篇关于ElasticSearch中关键字和文本的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!