elasticsearch - Elasticsearch - 如何为搜索和索引指定相同的分析器
问题描述
我正在开发一个西班牙搜索引擎。(我不会说西班牙语)但根据我的研究,目标或多或少是这样的: 1. 过滤停用词,如“dos”、“de”、“la”... 2. 为两个搜索词干和索引。例如,如果您搜索“primera”,那么“primero”、“primer”也应该出现。
我的尝试:
es_analyzer={
"settings": {
"analysis": {
"filter": {
"spanish_stop": {
"type": "stop",
"stopwords": "_spanish_"
},
"spanish_stemmer": {
"type": "stemmer",
"language": "spanish"
}
},
"analyzer": {
"default_search": {
"type": "spanish"
},
"rebuilt_spanish": {
"tokenizer": "standard",
"filter": [
"lowercase",
"spanish_stop",
"spanish_stemmer"
]
}
}
}
}
}
问题:当我在 中使用"type":"spanish"
时"default_search"
,我的查询“primera”被提取为“primer”,这是正确的,但即使我指定"spanish_stemmer"
在过滤器中使用,索引中的文档也不会被提取。因此,当我搜索“primera”时,它只显示“primer”的完全匹配。有关解决此问题的任何建议吗?
潜在的修复,但我还没有弄清楚语法:
- 在过滤器中使用内置
"spanish"
分析器。语法是什么? - 在
"default_search"
. 但我不知道如何在那里使用复合设置。
解决方案
添加具有索引数据、映射、搜索查询和搜索结果的工作示例
索引映射:
{
"settings": {
"analysis": {
"filter": {
"spanish_stop": {
"type": "stop",
"stopwords": "_spanish_"
},
"spanish_stemmer": {
"type": "stemmer",
"language": "spanish"
}
},
"analyzer": {
"default_search": {
"type":"spanish",
"tokenizer": "standard",
"filter": [
"lowercase",
"spanish_stop",
"spanish_stemmer"
]
}
}
}
},
"mappings":{
"properties":{
"title":{
"type":"text",
"analyzer":"default_search"
}
}
}
}
指数数据:
{
"title": "primer"
}
{
"title": "primera"
}
{
"title": "primero"
}
搜索查询:
{
"query":{
"match":{
"title":"primer"
}
}
}
搜索结果:
"hits": [
{
"_index": "stof_64420517",
"_type": "_doc",
"_id": "3",
"_score": 0.13353139,
"_source": {
"title": "primer"
}
},
{
"_index": "stof_64420517",
"_type": "_doc",
"_id": "1",
"_score": 0.13353139,
"_source": {
"title": "primera"
}
},
{
"_index": "stof_64420517",
"_type": "_doc",
"_id": "2",
"_score": 0.13353139,
"_source": {
"title": "primero"
}
}
]
推荐阅读
- javascript - jQuery - 需要添加 setTimeout 函数将每 5 秒运行一次以检查是否定义了 jQuery,最多 1 分钟
- python - AttributeError:“SpooledTemporaryFile”对象没有属性“翻译”
- webpack - [Vue 警告]:uglify 后组件名称无效
- angular - 在 ngFor 中处理 textarea 输入
- ios - UIView 是否可见?
- php - PHP根据值连续遍历数组
- r - 每年每种类型有多少计数?使用 group_by() 或 Split()
- angular - 无法读取未定义的属性“名称”-Angular 6。所有字段都重复错误
- c# - c# Linq 获取实体查询中列表元素的id
- c# - 如何分离 NCrunch 节点服务使用的所有 LocalDb 数据库