Elasticsearch Nest多字段映射无法正常工作

时间:2015-09-04 23:57:30

标签: elasticsearch mapping nest

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))
    )
    ))
);

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

screenshot

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

1 个答案:

答案 0 :(得分:0)

以下是如何使用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,并且如果引用的话将是使用的字段没有后缀的字段。默认情况下,将使用 standard analyzer 分析其他地图name.searchable

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"
                     }
                  }
               }
            }
         }
      }
   }
}