Elasticsearch NEST 创建不区分大小写的索引

Elasticsearch NEST create case-insensitive index

如何在 NEST 中创建一个索引来比较不区分大小写和 TermQuery?

我尝试了以下方法(以及许多类似的方法),但我的 TermQuery 仅 returns 区分大小写的匹配结果。

Client.CreateIndex("my_index", (c) => c
    .Settings(s => s
        .Analysis(an => an
            .Analyzers(ans => ans
                .Custom("analyzer_keyword", cu => cu
                    .Tokenizer("keyword")
                    .Filters("lowercase")
                 )
                .Custom("analyzer_term", cu => cu
                    .Tokenizer("term")
                    .Filters("lowercase")
                 )
            )
        )
    )
);

我不知道如何用 NEST 做到这一点,但我知道一件事 - 你有两个选择:

  1. 你可以指定default分析器

  1. 您需要使用您的analyzer_keywordanalyzer_term作为文档的字段。

因为您的代码现在只指定了一些未在任何地方使用的自定义分析器。

看看specifying an index time analyzer:

At index time, if no analyzer has been specified, it looks for an analyzer in the index settings called default. Failing that, it defaults to using the standard analyzer.

specifying a search time analyzer:

The analyzer to use to search a particular field is determined by looking for:

  • An analyzer specified in the query itself.
  • The search_analyzer mapping parameter.
  • The analyzer mapping parameter.
  • An analyzer in the index settings called default_search.
  • An analyzer in the index settings called default.
  • The standard analyzer.