The correct way to create multiple fields using NEST

I want to implement full-text search and tokenized search using NEST, so I want to get multi-field as follows:

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

My current mapping to NEST is currently

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

I searched the documentation for NEST and ElasticSearch.net, but nothing worked.

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

+7
elasticsearch nest
source share
1 answer

Checkout this answer .

Basically, you can 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))))))); 
+8
source share

All Articles