Created
July 11, 2012 23:27
-
-
Save Yegoroff/3094421 to your computer and use it in GitHub Desktop.
PlainElastic.Net Index Settings sample
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 characters
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; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how can i use the stopword list... or stopwords_path (file)???
{ "settings": { "analysis": { "filter": { "my_stop": { "type": "stop", "stopwords": ["and", "is", "the"] } } } } }