栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

应用分析器/过滤器时搜索elasticsearch错误

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

应用分析器/过滤器时搜索elasticsearch错误

我只是简化了你的问题,为简单起见,我们假设你只需要1场被称为

title
包含了像不同的语言
c
c++
c#
f#

title
字段的索引设置和映射。

{    "settings": {        "index": { "analysis": {     "analyzer": {         "my_analyzer": {  "filter": [      "lowercase"  ],  "char_filter": [      "pre_mapping"  ],  "tokenizer": "standard" --> notice `standard`         }     },     "char_filter": {         "pre_mapping": {  "type": "mapping",  "mappings": [      "++ => plusplus",      "c# => csharp",      "C# => csharp",      "F# => fsharp",      "f# => fsharp",      ".net => dotnet",      ".Net => dotnet",      ".NET => dotnet",      "( => map_lp",      ") => map_rp",      "& => and",      "# => hash",      "+ => plus"  ]         }     } }        }    },    "mappings": {        "properties": { "title": {     "type": "text",     "analyzer": "my_analyzer" --> using custom analyzer created in settings }        }    }}

为一些文档编制索引

POST / _doc / {doc-is}

{    "title": "c#"}{    "title": "c++"}{    "title": "c"}{    "title": "F#"}

搜索查询,这是为您提供的问题中提取包含的所有记录的问题

c

{    "query": {        "bool": { "must": [     {         "match": {  "title": "c++"         }     } ]        }    },    "size": 10}

现在对我而言,它仅检索仅包含

c++
我的搜索API结果中所示的文档。

"hits": {        "total": { "value": 1, "relation": "eq"        },        "max_score": 0.9808292,        "hits": [ {     "_index": "cplus",     "_type": "_doc",     "_id": "1",     "_score": 0.9808292,     "_source": {         "title": "c++"     } }        ]    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/376357.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号