2

I am a beginner in Elasticsearch. While doing a sample application as like https://msdn.microsoft.com/en-us/magazine/dn904674.aspx , it shows an error in

public void CreateMarketingIndex()
{
 this.client.CreateIndex("marketing", c =>.AddMapping<MarketingDocument>
     (m => m.Properties(ps => ps.Attachment
       (a => a.Name(o => o.Document)
         .TitleField(t => t.Name(x => x.Name).TermVector(TermVectorOption.WithPositionsOffsets))))));
} 

'CreateIndexDescriptor' does not contain a definition for 'AddMapping' and no extension method 'AddMapping' accepting a first argument of type 'CreateIndexDescriptor' could be found (are you missing a using directive or an assembly reference?)

Am I missing any reference. I referenced Elasticsearch.net and Nest

Brian from state farm
  • 2,825
  • 12
  • 17
Ajoe
  • 1,397
  • 4
  • 19
  • 48

2 Answers2

2

I think that AddMapping may have been for the old version of the Nest client. I've been using Mappings instead. Try something like this:

this.client.CreateIndex("marketing", c => c
    .Mappings(md => md
        .Map<MarketingDocument>(m => m.Properties(ps...
coconaut
  • 166
  • 4
  • Thank you, your answer helped me. Also I have a similar error coming in var queryResult = this.client.Search(d => d.AllIndices() .AllTypes() .** QueryString(queryTerm));** Can you please suggest a solution? – Ajoe May 24 '16 at 05:23
  • Maybe try something like: client.Search(d => d.AllIndices().AllTypes().Query(q => q.QueryString(qs => qs.Query(queryTerm)))); The first .Query starts the query portion of the search. Then the inner q is a query container descriptor with which you get to start defining the query. So I'm saying the query is a QueryString query, and then that inner qs describes the query string, with which you can query by your search term. – coconaut May 24 '16 at 13:12
1

You can do it like this:

var descriptor = new CreateIndexDescriptor(mIndexName)
     .Mappings(x => x.Map<Model>(m => m.AutoMap()));

or without object type

var descriptor = new CreateIndexDescriptor(mIndexName)
     .Mappings(x => x.Map(model, m => m.AutoMap()));
Marius
  • 562
  • 5
  • 26