We need specific documentation / examples of building a complex index using the NEST ElasticSearch library

I would like to use the NEST Fluent library interface to create an index that includes setting up custom filters, analyzers, and type mappings. I would like to avoid decorating my classes with NEST-specific annotations.

I saw the documentation at http://nest.azurewebsites.net/indices/create-indices.html and http://nest.azurewebsites.net/indices/put-mapping.html . This documentation, showing some examples, is not comprehensive enough to help me understand how to use the Fluent API to create complex indexing scripts.

I found a tutorial at http://euphonious-intuition.com/2012/08/more-complicated-mapping-in-elasticsearch/ to be quite helpful; some code showing how to create filters, analyzers, and mappings in this tutorial via the NEST Fluent interface instead of direct JSON would be a great answer to this question.

+7
elasticsearch nest
source share
1 answer

The more specific you can be about your question, the better the answers you get. However, there is an index that sets the analyzer (with a filter) and the tokenizer (EdgeNGram), and then uses them to create an autocomplete index in the "Name" field of the Tag class.

public class Tag { public string Name { get; set; } } Nest.IElasticClient client = null; // Connect to ElasticSearch var createResult = client.CreateIndex(indexName, index => index .Analysis(analysis => analysis .Analyzers(a => a .Add( "autocomplete", new Nest.CustomAnalyzer() { Tokenizer = "edgeNGram", Filter = new string[] { "lowercase" } } ) ) .Tokenizers(t => t .Add( "edgeNGram", new Nest.EdgeNGramTokenizer() { MinGram = 1, MaxGram = 20 } ) ) ) .AddMapping<Tag>(tmd => tmd .Properties(props => props .MultiField(p => p .Name(t => t.Name) .Fields(tf => tf .String(s => s .Name(t => t.Name) .Index(Nest.FieldIndexOption.not_analyzed) ) .String(s => s .Name(t => t.Name.Suffix("autocomplete")) .Index(Nest.FieldIndexOption.analyzed) .IndexAnalyzer("autocomplete") ) ) ) ) ) ); 

There is also a fairly complete mapping example in a NEST unit test project on github. https://github.com/elasticsearch/elasticsearch-net/blob/develop/src/Tests/Nest.Tests.Unit/Core/Map/FluentMappingFullExampleTests.cs

Edit:

To request an index, do the following:

 string queryString = ""; // search string var results = client.Search<Tag>(s => s .Query(q => q .Text(tq => tq .OnField(t => t.Name.Suffix("autocomplete")) .QueryString(queryString) ) ) ); 
+9
source share

All Articles