9

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

Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68

1 Answers1

8

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)))))));
Community
  • 1
  • 1
Greg Marzouka
  • 3,315
  • 1
  • 20
  • 17
  • Thank you for your answer (and sorry for my late answer). It is working well when I'm creating an index like that but do you have an idea on how to do it with a connected client and an already created index ? I defined a new property called Raw and added it to my attribute based mapping. I iterating through the type Tweet and checking if a raw attribute is there and then I want to make it multi-field. –  Jun 13 '14 at 14:42
  • http://nest.azurewebsites.net/indices/put-mapping.html The TypeMapping example seems perfect but it is not working anymore. No more reference to TypeMapping –  Jun 13 '14 at 14:51
  • What version of NEST are you using? The API has changed a lot in the newer version, and the documentation needs updating. Regardless, you are still going to need to reindex your data with the new mapping, so it might be worth it to recreate your index as well. – Greg Marzouka Jun 13 '14 at 15:36
  • I use the latest version of NEST (nuget packages). I found an answer by yourself in another thread and I think I'm making progress. ESclient.Map(m => m.Index(indexName).MapFromAttributes().Properties(p => EnsureRawMapping())); I'm doing something like that currently, I still have to figure out how can I iterate through my attributes and creating the multifield where I need to. –  Jun 13 '14 at 15:47