Nest and Elastic Search - Mapping

三世轮回 提交于 2019-12-24 17:44:15

问题


I am trying to map multiple analyzers to a field in my elastic type. If I use an ElasticAttribute to map an analyzer:

[ElasticProperty(Analyzer = "fulltext")]
public string LongDescription { get; set; }

and I look at the request created I get:

"name": {
      "type": "string",
      "analyzer": "fulltext"
    },

In order to map multiple analyzers to the same field, I use Fluent mapping and add a multifield:

.Properties(prop => prop
                    .MultiField(mf => mf
                        .Name(p => p.Name)
                        .Fields(f => f
                            .String(
                                s =>
                                    s.Name(n => n.Name)
                                        .IndexAnalyzer("autocomplete_analyzer")
                                        .IncludeInAll(false)
                                        .Index(FieldIndexOption.not_analyzed))
                            .String(
                                s =>
                                    s.Name(n => n.Name)
                                        .IndexAnalyzer("fulltext")
                                        .IncludeInAll(false)
                                        .Index(FieldIndexOption.not_analyzed))
                        )
                    )
                )

The request generated looks like this:

 "name": {
      "type": "multi_field",
      "fields": {
        "name": {
          "type": "string",
          "index": "not_analyzed",
          "index_analyzer": "autocomplete_analyzer",
          "include_in_all": false
        },
        "name": {
          "type": "string",
          "index": "not_analyzed",
          "index_analyzer": "fulltext",
          "include_in_all": false
        }
      }
    },

I am specifically interested in the "analyzer"/"index_analyzer" properties. With fluent mapping, I can only set IndexAnalyzer or SearchAnalyzer. I understand the difference between IndexAnalyzer and SearchAnalyzer, but what is the "analyzer" property when I use an ElasticAttribute? Does that just mean the Index and Search are set the same?


回答1:


Just specifying analyzer is indeed setting index_analyzer and search_analyzer at the same time. analyzer is an elasticsearch property and not some magic behavior from NEST.

The fluent mapping is missing the .Analyzer() method, this is now added in 1.0!



来源:https://stackoverflow.com/questions/22308337/nest-and-elastic-search-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!