我不知道如何打开 Elasticsearch 英文单词词干。对不起,我没有找到一个明确的例子来做到这一点。
这是我所做的
创建索引
PUT /staff/list/ -d
{
"settings" : {
"analysis": {
"analyzer": {
"standard": {
"type": "standard"
}
}
}
}
}
添加文档
PUT /staff/list/jason
{
"Title" : "searches"
}
当我搜索
search
GET /staff/list/_search?q=search
结果没有出现。
我应该做哪些索引设置才能使词干提取工作。
提前谢谢了
最佳答案
请注意,默认的 Elasticsearch 分析器不支持词干提取。
为了支持词干提取,您可能需要创建一个自定义分析器。
这是你如何做到的:
创建索引并定义一个名为 my_analyzer 的分析器
PUT /staff
{
"settings" : {
"analysis": {
"filter": {
"filter_snowball_en": {
"type": "snowball",
"language": "English"
}
},
"analyzer": {
"my_analyzer": {
"filter": [
"lowercase",
"filter_snowball_en"
],
"type": "custom",
"tokenizer": "whitespace"
}
}
}
}
}
配置将 my_analyzer 分配给列表类型的映射
PUT /staff/_mapping/list
{
"list": {
"properties": {
"title": {
"type": "string",
"analyzer": "my_analyzer"
}
}
}
}
索引文件
PUT /staff/list/jason
{
"title": "searches"
}
PUT /staff/list/debby
{
"title": "searched open"
}
搜索和词干结果
GET staff/list/_search
{
"query": {
"query_string": {
"query": "title:opened"
}
}
}
结果
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "staff",
"_type": "list",
"_id": "debby",
"_score": 1,
"_source": {
"title": "open"
}
}]
}
}
正如您在搜索结果中看到的,
debby
包含术语的文档open
尽管我们在那里搜索 opened
,但还是返回了.希望有帮助。
关于elasticsearch - 如何打开elasticsearch词干,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35052222/