Nest documentation: where are the examples?

Version 1.x of Next/Elasticsearch .Net client was much richer with examples on how to set up the indexes and perform searches, etc. I've noticed this version seems to only give unit test style examples. Are there actual c#.net code examples to look at?

Reason i ask is upgrading from 1.x to 2.x (or 5) is so dramatically different in indexing, etc and i am having a very difficult time trying to figure out how to build the indexes, for example, using Nest. I understand much of it is to be used with AutoMap(), given the configuration options are supposed to be inferred or explicitly mapped using field attributes, but my indexes are much more complex. I have a lot of nested objects and fields that have multiple properties, based on very specific analizers, etc.

For example, i have the need to map an index of artists like this (multifield):

artist.name
artist.name.wo
artist.name.ti
artist.name.raw

where artist.name is indexed using one custom analyzer, and artist.name.wo is indexed using another custom anazlyer, etc, etc.

there are no concrete examples on how to accomplish this using 2.x or 5 in the documentation.

please shore up the documentation with possible use-case examples and more detail. thank you!

here's an example of the way i used to map the artist.name field as mentioned above:

private static void SetPutMappingDescriptorNames(PutMappingDescriptor pm, string fieldName)
{
pm.Properties(props => props
.Object(x => x
.Name(fieldName).MapFromAttributes()
.Name(fieldName).Properties(pp => pp.MultiField(
mf => mf
.Name(s => s.Name)
.Fields(f => f
.String(s => s.Name(o => o.Name).Analyzer("nameAnalyzer").OmitNorms())
.String(s => s.Name(o => o.Name.Suffix("ti")).Analyzer("titleAnalyzer").OmitNorms())
.String(s => s.Name(o => o.Name.Suffix("wo")).Analyzer("titleWordAnalyzer").OmitNorms())
.String(s => s.Name("st").Analyzer("stemmerWordAnalyzer"))
.String(s => s.Name(o => o.Name.Suffix("raw")).Index(FieldIndexOption.NotAnalyzed))
)))));
}

Thanks for the feedback @bigerock.

The documentation is a living entity so is a constant work in progress. We pushed out documentation for 2.x at the time the 2.x client was released and this includes details on automapping.

We have plans to add further details on analysis and other APIs as well as add sections for getting started with querying, aggregations, etc. and reorganise the current documentation.

Here's what your mapping would look like in 2.x (assuming the following models):

public class MyDocument
{
    public Artist Artist { get; set; } 
}

public class Artist
{
    public string Name { get; set; }
}

client.Map<MyDocument>(m => m
    // let NEST infer the Elasticsearch field types for your POCO
    // based on the .NET property types. This is akin to .MapFromAttributes() in
    // NEST 1.x
    .AutoMap()
    // Now, override any inferred mappings
    .Properties(p => p
        .Object<Artist>(x => x
            .AutoMap()
            .Name(n => n.Artist)
            .Properties(pp => pp
                .String(s => s
                    .Name(o => o.Name)
                    .Analyzer("nameAnalyzer")
                    .Norms(n => n.Enabled(false))
                    .Fields(ff => ff
                        .String(ss => ss
                            .Name("ti")
                            .Analyzer("titleAnalyzer")
                            .Norms(n => n.Enabled(false))
                        )
                        .String(ss => ss
                            .Name("wo")
                            .Analyzer("titleWordAnalyzer")
                            .Norms(n => n.Enabled(false))
                        )
                        .String(ss => ss
                            .Name("st")
                            .Analyzer("stemmerWordAnalyzer")
                        )
                        .String(ss => ss
                            .Name("raw")
                            .NotAnalyzed()
                        )
                    )
                )
            )       
        )
    )
);

This generates the following mapping

{
  "properties": {
    "artist": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "fields": {
            "ti": {
              "type": "string",
              "norms": {
                "enabled": false
              },
              "analyzer": "titleAnalyzer"
            },
            "wo": {
              "type": "string",
              "norms": {
                "enabled": false
              },
              "analyzer": "titleWordAnalyzer"
            },
            "st": {
              "type": "string",
              "analyzer": "stemmerWordAnalyzer"
            },
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          },
          "norms": {
            "enabled": false
          },
          "analyzer": "nameAnalyzer"
        }
      }
    }
  }
}
1 Like

thanks Russ. i did some experimentation and was able to find the solution to my indexing just before you posted it. glad to know i did it correctly, though it did take an awful lot of experimentation.

glad to hear you're working on some real world examples and how-to type documentation. i know the community would appreciate it.

thanks for your hard work!

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.