1

我使用默认分析器“英语”来搜索文档,它非常好。但是,当搜索查询拼写错误或通过此类拼写错误的短语进行搜索时,我还需要“您的意思是”结果。

我需要什么分析器/过滤器/查询来实现这种行为?

源文本

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 search
distrib a ted => 分布式
Apac j e => Apache

额外空间
弹性搜索 => 弹性搜索

没有空间
开源 => 开源

拼写错误的短语
serach engne => 搜索引擎

4

1 回答 1

1

您的第一个丢失字母或其他内容的示例可以使用模糊查询来实现,第二个示例使用使用ngramedge-ngram 标记器的自定义分析器来获取示例,请参阅我关于自动完成的博客

在示例文档中添加模糊查询示例

索引映射

{
    "mappings": {
        "properties": {
            "title": {
                "type": "text"
    
            }
        }
    }
}

索引您的示例文档并使用以下搜索查询

{
    "query": {
        "fuzzy": {
            "title": {
                "value": "distributed"
            }
        }
    }
}

并搜索资源

 "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"
                }
            }
        ]
于 2020-09-14T08:19:41.667 回答