Skip to content

Instantly share code, notes, and snippets.

@Yegoroff
Created July 11, 2012 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yegoroff/3094421 to your computer and use it in GitHub Desktop.
Save Yegoroff/3094421 to your computer and use it in GitHub Desktop.
PlainElastic.Net Index Settings sample
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;
}
}
}
}
@ilhee
Copy link

ilhee commented May 31, 2016

how can i use the stopword list... or stopwords_path (file)???
{ "settings": { "analysis": { "filter": { "my_stop": { "type": "stop", "stopwords": ["and", "is", "the"] } } } } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment