我使用默认的分析器“英语”来搜索文档,这非常好。
但是当搜索查询拼写错误或通过此类拼写错误的短语进行搜索时,我还需要“您是不是要”结果。
我需要什么分析器/过滤器/查询才能达到这种效果?
源文本
Elasticsearch is a distributed, open source search and analytics engine for all types of data,
including textual, numerical, geospatial, structured, and unstructured. Elasticsearch is built
on Apache Lucene and was first released in 2010 by Elasticsearch N.V. (now known as Elastic).
Known for its simple REST APIs, distributed nature, speed, and scalability, Elasticsearch is
the central component of the Elastic Stack, a set of open source tools for data ingestion,
enrichment, storage, analysis, and visualization. Commonly referred to as the ELK Stack
(after Elasticsearch, Logstash, and Kibana), the Elastic Stack now includes a rich collection
of lightweight shipping agents known as Beats for sending data to Elasticsearch.
搜索词搜索查询=>您是说XXX吗?
错过的信件或类似的东西
Elastisearch => Elasti c 搜索
distrib a ted =>已分发
Apac j e => Apache
多余的空间
flex 搜索=> Elasticsearch
没有空间
开源=>开源
拼写错误的词组
serach engne =>搜索引擎
最佳答案
您可以使用fuzzy query来实现您的第一个字母遗漏示例,而第二个示例可以使用使用ngram或edge-ngram tokenizer作为示例的自定义分析器来实现,请引用my blog on autocomplete。
在示例文档上添加模糊查询示例
索引映射
{
"mappings": {
"properties": {
"title": {
"type": "text"
}
}
}
}
索引您的样本文档,并在下面的搜索查询中使用{
"query": {
"fuzzy": {
"title": {
"value": "distributed"
}
}
}
}
并搜索res "hits": [
{
"_index": "didyou",
"_type": "_doc",
"_id": "2",
"_score": 0.89166296,
"_source": {
"title": "distribated"
}
}
]
对于Elasticsearch
{
"query": {
"fuzzy": {
"title": {
"value": "Elasticsearch"
}
}
}
}
并搜索结果 "hits": [
{
"_index": "didyou",
"_type": "_doc",
"_id": "1",
"_score": 0.8173577,
"_source": {
"title": "Elastisearch"
}
}
]