Proper way to do multi field with NEST

為{幸葍}努か 提交于 2019-12-21 04:20:35

问题


I want to implement full text search and tokenized search with NEST, so I want to get multifield like that :

     "tweet": {
        "properties": {
           "message": {
              "type": "string",
              "store": true,
              "fields": {
                 "raw": {
                    "type": "string",
                    "index": "not_analyzed"
                 }
              }
           }
        }
     }

Currently, my mapping with NEST is

[ElasticType(Name = "tweet")]
internal class Tweet
{
    [ElasticProperty(Name = "message")]
    public string Message { get; set; }
}

I searched in the documentation on NEST and ElasticSearch.net but nothing came by.

Is there any option to get a raw field inside a field automatically or should I define a nested class and specify myself the raw field (I would prefer a cleaner way) ?


回答1:


Checkout this answer.

Basically, you could do something like this:

client.CreatIndex("tweets", c => c
    .AddMapping<Tweet>(m => m
        .MapFromAttributes()
        .Properties(props => props
            .MultiField(mf => mf
                .Name(t => t.Message)
                .Fields(fs => fs
                    .String(s => s.Name(t => t.Message).Analyzer("standard"))
                    .String(s => s.Name(t => t.Message.Suffix("raw")).Index(FieldIndexOption.not_analyzed)))))));


来源:https://stackoverflow.com/questions/23650618/proper-way-to-do-multi-field-with-nest

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