0

I'm following a tutorial on elastic search here. It is not with .NET but I've been able to pretty much follow everything being discussed using NEST. I've gotten to the part about mapping and I do not know how to represent the request below using NEST

curl -XPUT "http://localhost:9200/movies/movie/_mapping" -d'
{
   "movie": {
      "properties": {
         "director": {
            "type": "multi_field",
            "fields": {
                "director": {"type": "string"},
                "original": {"type" : "string", "index" : "not_analyzed"}
            }
         }
      }
   }
}'

I have checked for solutions everywhere and the closest I could get was this stack overflow question.

How do I achieve this? I will also appreciate links to sites for complete beginners to elasticsearch with example I can follow.

Community
  • 1
  • 1
ritcoder
  • 3,274
  • 10
  • 42
  • 62
  • Is there a particular reason you need to declare this mapping? From the look of those fields, Elasticsearch might do what you need by default. Have you tried just indexing the document and then checking what Elasticsearch does? – Josh C. Aug 24 '14 at 04:12
  • It is from the tutorial that I'm following in the link above. They explained that the string property (in this case, we are saving movies and it is the director field), the values are broken down into the individual words and searches with multiple words will yield no result. I've actually confirmed this. The solution is to make that field a multi_field as in the code above. I'm just not sure of how to do this in NEST. – ritcoder Aug 24 '14 at 05:11

1 Answers1

1

The best example/documentation for NEST related to Mappings is to look at this file in the source code FluentMappingFullExampleTests.cs

Following that file as an example, if you have declared a corresponding Movie class in your project, you could do the following

 var result = this._client.Map<Movie>(m => m
     .Properties(props => props
        .MultiField(s => s
            .Name(p => p.Name)
            .Fields(pprops => pprops
                        .String(ps => ps.Name(p => p.Name).Index(FieldIndexOption.Analyzed))
                        .String(ps => ps.Name("original").Index(FieldIndexOption.NotAnalyzed))
                )
             )
         )
     )
Paige Cook
  • 22,415
  • 3
  • 57
  • 68
  • 1
    Also, when 1.1 is released, or using the latest code from the dev branch, you'll be able set `Fields()` directly on the primary property. See http://stackoverflow.com/questions/25432661/elasticsearch-analyzed-fields – Greg Marzouka Aug 25 '14 at 21:44