elasticsearch - 定义了一个edgeNGram,搜索只对完整的单词起作用,而不是tokens
问题描述
我使用 es 6.4 作为 AWS 服务。这是我的映射 -
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "my_tokenizer"
}
}
},
"tokenizer": {
"my_tokenizer": {
"type": "edge_ngram",
"min_gram": 3,
"max_gram": 20,
"token_chars": [
"letter"
]
}
}
},
"mappings": {
"tsetse": {
"properties": {
"id": {
"type": "integer"
},
"user_id": {
"type": "integer"
},
"description": {
"type": "text",
"analyzer": "my_analyzer"
},
"type": {
"type": "integer"
}
}
}
}
}
该指数有一个描述=“地球上最伟大的表现”的记录。当我尝试搜索时,它总是适用于完整的词 - 地球或性能。不返回出色或性能的结果。我错过了什么?
这是使用 EdgeNGram 更新的映射`
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"tsetse": {
"properties": {
"id": {
"type": "integer"
},
"user_id": {
"type": "integer"
},
"description": {
"type": "text",
"analyzer": "my_analyzer"
},
"type": {
"type": "integer"
}
}
}
}
}
`
Gist 脚本 - https://gist.github.com/swati-patil/0b1cea74fc52b1b96d44ad239ad2580d 谢谢,
解决方案
感谢您的要点。我可以看到您没有正确创建索引:
- 您正在使用 POST 而不是 PUT
- 你指定了一个你不应该指定的类型
- 最后需要删除两个闭合花括号
改为这样做:
# first delete your index
curl -XDELETE 'my-instance-us-east1.amazonaws.com/my_index'
# then create it correctly
curl -XPUT "my-instance-us-east1.amazonaws.com/my_index" -H 'Content-Type: application/json' -d '{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"my_type": {
"properties": {
"text": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
}'
# then analyze works
curl -XPOST my-instance-us-east1.amazonaws.com/my_index/_analyze -H 'Content-Type: application/json' -d '{
"analyzer": "my_analyzer",
"text": "Greatest performance on earth"
}'
然后索引您的文档并运行您的查询,它们都会起作用。
推荐阅读
- algorithm - 随机分配数量
- java - 如何从 URL 解析 json 数据并将其添加到自动完成搜索视图
- javascript - 我有一个简单的 HTML 表单:个性测验,有一组单选按钮的 Javascript 功能。如何在 PHP 文件中分析它
- javascript - 使用“深度”数组对 useState 做出反应,而不是重新渲染组件
- php - 使用 PHP 数组的灵活列类
- node.js - 总是返回 401 Unauthorized in passport-jwt
- node.js - 有没有办法在vue中引用图像?
- javascript - 如何将 application/vnd.ms-excel 与非拉丁语言一起使用?
- python - 如何让 python 从列表中返回尽可能多的谜语
- wpf - UWP - 父控件拦截指针事件(其中子控件为 ScrollViewer)