如何在 Elasticsearch 中进行字符串搜索?

How do I do string search in Elasticsearch?

我需要在 Elasticsearch 中进行字符串搜索,例如:

This is the content stored in elasticsearch

我希望它与“content stored in”相匹配,但不与“in stored content”相匹配。目前与简单搜索都匹配。

我还想匹配部分字符串,如“ontent stor”(不是完整的单词)。

我知道有通配符搜索之类的东西,但它们会扫描所有文档。我想使用功能使其 运行 更快。

通配符搜索很繁重。您可以在分析器中使用 ngram token filter 并进行术语搜索。它将负责匹配部分字符串。如果您不使用术语搜索,请确保您使用不同的分析器进行搜索(没有 ngram 标记过滤器)。