Created
July 11, 2012 23:27
Revisions
-
Alexander Yegorov created this gist
Jul 11, 2012 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,75 @@ using System; using PlainElastic.Net; using PlainElastic.Net.IndexSettings; namespace IndexSettigsSample { class Program { static void Main() { var connection = new ElasticConnection("localhost", 9200); var settings = BuildIndexSettings(); string result; if (IsIndexExists("store", connection)) { // We can't update settings on active index. // So we need to close it, then update settings and then open index back. connection.Post(new CloseCommand("store")); result = connection.Put(new UpdateSettingsCommand("store"), settings); connection.Post(new OpenCommand("store")); } else { // Create Index with settings. result = connection.Put(Commands.Index("store").Refresh(), settings); } Console.WriteLine("Index Settings: " + settings); Console.WriteLine("JSON result: " + result); Console.ReadKey(); } private static string BuildIndexSettings() { return new IndexSettingsBuilder() .Analysis(als => als .Analyzer(a => a .Custom("lowerkey", custom => custom .Tokenizer(DefaultTokenizers.keyword) .Filter(DefaultTokenFilters.lowercase) ) .Custom("fulltext", custom => custom .CharFilter(DefaultCharFilters.html_strip) .Tokenizer(DefaultTokenizers.standard) .Filter(DefaultTokenFilters.word_delimiter, DefaultTokenFilters.lowercase, DefaultTokenFilters.stop, DefaultTokenFilters.standard) ) ) ) .BuildBeautified(); } private static bool IsIndexExists(string indexName, ElasticConnection connection) { try { connection.Head(new IndexExistsCommand(indexName)); return true; } catch (OperationExeception ex) { if (ex.HttpStatusCode == 404) return false; throw; } } } }