【问题标题】:Elasticsearch Nest multifield mapping not workingElasticsearch Nest 多字段映射不起作用
【发布时间】:2015-12-01 04:57:41
【问题描述】:

http://nest.azurewebsites.net/nest/indices/put-mapping.html 说我可以像这样进行多字段映射:

var result = this._client.Map<ElasticsearchProject>(m => m
    .Properties(props => props
    .String(s => s
    .Name(p => p.Name)
    .Path(MultiFieldMappingPath.Full)
    .Index(FieldIndexOption.not_analyzed)
    .Fields(pprops => pprops
        .String(ps => ps.Name(p => p.Name.Suffix("searchable")).Index(FieldIndexOption.analyzed))
    )
    ))
);

但是,当我尝试时,自动完成功能不起作用。我收到此错误:

我从 NuGet 安装了最新的稳定版 NEST (1.7.1),但这似乎没有帮助。

【问题讨论】:

    标签: elasticsearch mapping nest


    【解决方案1】:

    这是一个如何使用 NEST 设置 multi_field 映射的示例

    void Main()
    {
        var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
            .SetDefaultIndex("location-details");   
        var client = new ElasticClient(settings);
    
        var indexResult = client.CreateIndex(indexDescriptor => indexDescriptor
            .Index("location-details-v1")
            .AddMapping<LocationDetails>(mapping => mapping
                // map properties using the default conventions and
                // any NEST attributes
                .MapFromAttributes()
                // override default mappings explicitly
                .Properties(properties => properties
                    .MultiField(multi => multi
                        .Name(p => p.Name)
                        .Fields(fields => fields
                            .String(s => s
                                .Name(p => p.Name)
                                .Index(FieldIndexOption.NotAnalyzed)
                            )
                            .String(s => s
                                .Name(p => p.Name.Suffix("searchable"))
                            )
                        )
                    )
                )
            )
        );
    
        if (!indexResult.IsValid)
        {
            throw indexResult.ConnectionStatus.OriginalException;
        }
    }
    
    public class LocationDetails
    {
        public string Name { get; set; }
    }
    

    Name 属性在 Elasticsearch 中映射为 multi_field - 该字段的默认 映射为 not_analyzed,如果引用不带后缀的字段,则将使用该字段。其他映射name.searchable会默认使用standard analyzer进行分析。

    Elasticsearch 中的映射如下所示

    curl -XGET "http://localhost:9200/location-details-v1/locationdetails/_mapping"
    
    {
       "location-details-v1": {
          "mappings": {
             "locationdetails": {
                "properties": {
                   "name": {
                      "type": "string",
                      "index": "not_analyzed",
                      "fields": {
                         "searchable": {
                            "type": "string"
                         }
                      }
                   }
                }
             }
          }
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 2015-10-27
      • 2016-04-23
      • 1970-01-01
      相关资源
      最近更新 更多