简体   繁体   English

如何为ElasticSearch 5.x使用NEST流畅的映射指定索引/字段分析器?

[英]How can I specify index / field analyzers using NEST fluent mapping for ElasticSearch 5.x?

Reasonably new to ElasticSearch / NEST - I have a property on a mapping that holds UK postcodes (eg DT5 2HW, BB1 9DR). 对于ElasticSearch / NEST来说是相当新的-我在一个包含英国邮政编码(例如DT5 2HW,BB1 9DR)的映射上具有一个属性。 At the moment, I have the following code:- 目前,我有以下代码:

if (!client.IndexExists("user").Exists)
{
    client.CreateIndex("user", c => c.Mappings(
                                        m => m.Map<User>(
                                              mp => mp.AutoMap()
                                        )
                                    )                                                                    
                      );
}

I'm trying to find the correct place to specify an analyzer when creating a fluent mapping ( so I can implement what's being done here ), but:- 我试图在创建流畅的映射时找到指定分析仪的正确位置( 以便我可以在此处实现正在执行的操作 ),但是:-

  • calling mp.AutoMap().Analyzer() is marked as deprecated / to be removed in 6.0 with a warning that default analyzers are to be removed at the type level, and need to be specified at the index or field level (sidenote: by field, do they mean property?) 调用mp.AutoMap().Analyzer()被标记为已弃用/在6.0中将被删除,并警告将在类型级别删除默认分析器,并且需要在索引或字段级别指定(注意:字段,它们是指财产吗?)
  • Analyzer() is not available in Intellisense after either Keyword() or Name() Keyword()Name()之后, Analyzer()在Intellisense中不可用

Is it just not possible to do so via a fluent mapping? 仅通过流畅的映射就不​​可能做到这一点吗? Does this mean that I have to specify the available analyzers via CreateIndex -> Settings -> Analysis, then specify the Analyzers to use on a property level with attributes on the POCO? 这是否意味着我必须通过CreateIndex->​​ Settings-> Analysis指定可用的分析器,然后指定要在POCO上具有属性的属性级别上使用的分析器?

I feel like I've gone fundamentally wrong somewhere - any pointers would be greatly appreciated! 我觉得我在某个地方犯了根本性的错误-任何指针将不胜感激!

It turns out the answer isn't about it being fluent or not, but you cannot specify analyzers for Keyword fields , so the data is to be used as-is. 事实证明,答案并不是关于它是否流利,但是您不能为“关键字”字段指定分析器 ,因此数据应按原样使用。

You can see the difference between the documentation for keyword with the documentation for text fields . 您可以看到关键字 文档和文本字段文档之间的区别。 I was a little misled by the text at the top of the reference for the keyword datatype that said "A field to index structured content such as email addresses, hostnames, status codes, zip codes or tags". 关键字数据类型的引用顶部的文本使我有些困惑,该数据表示“用于索引结构化内容的字段,例如电子邮件地址,主机名,状态代码,邮政编码或标签”。

I suspect what I'm trying to do is what Normalizers is being developed for, but it's still marked as experimental, but at least I can use Text for now. 我怀疑我想做的是针对规范化程序进行开发的,但仍被标记为实验性的,但至少我现在可以使用文本。

c => c.Mappings(m => m.Map<User>(
                    mp => mp.AutoMap()
                            .Properties(p => p.Text(
                                     t => t.Name(n => n.Postcode)
                                           .Analyzer("my_analyzer")
                                                   )
                                       )
                                )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM