本文整理汇总了C#中Nest.ConnectionSettings类的典型用法代码示例。如果您正苦于以下问题:C# ConnectionSettings类的具体用法?C# ConnectionSettings怎么用?C# ConnectionSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionSettings类属于Nest命名空间,在下文中一共展示了ConnectionSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ElasticRepo
public ElasticRepo()
{
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node, defaultIndex: "restaurant");
var client = new ElasticClient(settings);
_Client = client;
}
示例2: construct_client_with_invalid_hostname
public void construct_client_with_invalid_hostname()
{
Assert.Throws<UriFormatException>(() =>
{
var settings = new ConnectionSettings("some mangled hostname", 80);
});
}
示例3: Run
public void Run(string indexName, int port, int numMessages, int bufferSize)
{
var bulkParms = new SimpleBulkParameters() { Refresh = false };
var settings = new ConnectionSettings("localhost", port)
.SetDefaultIndex(indexName);
var client = new ElasticClient(settings, new ThriftConnection(settings));
Connect(client, settings);
IList<Message> msgBuffer = new List<Message>(bufferSize);
var msgGenerator = new MessageGenerator();
foreach (var msg in msgGenerator.Generate(numMessages))
{
msgBuffer.Add(msg);
// Flush buffer once max size reached
if (msgBuffer.Count >= bufferSize)
{
client.IndexMany(msgBuffer, indexName, bulkParms);
msgBuffer.Clear();
Interlocked.Add(ref NumSent, bufferSize);
// Output how many messages sent so far
if (NumSent % 10000 == 0)
{
Console.WriteLine("Sent {0:0,0} messages over Thrift", NumSent);
}
}
}
}
示例4: Main
static void Main(string[] args)
{
elasticSettings = new ConnectionSettings(new Uri("http://127.0.0.1:9200"))
.SetDefaultIndex("people");
client = new ElasticClient(elasticSettings);
///// ** Basic search with QueryString
var searchResults = client.Search<Person>(s => s.Query(q => q.
QueryString(x => x.Query("toto").
OnField(of => of.LastName))));
foreach (var result in searchResults.Documents)
{
Console.WriteLine("Found: {0}", result.FirstName + " " + result.LastName);
}
///// ** Basic search on Message
//var searchResults = client.Search<Person>(s => s.Query(q => q.
// QueryString(x => x.Query("brother").
// OnField(of => of.Message).
// Operator((Operator.and)))));
//foreach (var result in searchResults.Documents)
//{
// Console.WriteLine("Found: {0}", result.FirstName + " " + result.LastName);
//}
Console.ReadKey();
}
示例5: Client
public ElasticClient Client()
{
var node = new Uri("http://10.128.36.197:9200/");
var settings = new ConnectionSettings(node, defaultIndex: "disk");
return new ElasticClient(settings);
}
示例6: ElasticSearchDistributedLock
/// <summary>
/// C/tor
/// </summary>
/// <param name="namedLock">The name of the lock to create. REQUIRED</param>
/// <param name="client">An instance of an elastic search NEST client. Will be created automatically by default. Use this if connecting to an elastic cluster.</param>
/// <param name="indexName">The name of the elastic search index. Default = distributedlocks</param>
public ElasticSearchDistributedLock(string namedLock, IElasticClient client = null, string indexName = "distributedlocks")
{
if (string.IsNullOrEmpty(namedLock))
throw new ArgumentException("namedLock cannot be null or empty");
mIndex = indexName;
Name = namedLock;
mStopwatch = new Stopwatch();
//Only do this once per process..
if (string.IsNullOrEmpty(mOwner))
{
mOwner = BuildOwnerIdentifier();
}
//Create a default client if none handed in
if (client == null)
{
var settings = new ConnectionSettings(defaultIndex: mIndex);
mClient = new ElasticClient(settings);
}
else
{
mClient = client;
}
}
示例7: BlackListDataManager
public BlackListDataManager()
{
try
{
var elasticSearchUrl = ConfigurationManager.AppSettings["ElasticStoreConnection"];
var index = ConfigurationManager.AppSettings["EIndex_BlackList"];
_settings =
new ConnectionSettings(new Uri(elasticSearchUrl)).SetDefaultIndex(index).PluralizeTypeNames();
_client = new ElasticClient(_settings);
var isIndexExist = _client.IndexExists(i => i.Index(index));
if (!isIndexExist.Exists)
{
_client.CreateIndex(c => c.Index(index));
_settings.SetDefaultIndex(index);
_client = new ElasticClient(_settings);
}
var response =
_client.Map<BlockedUser>(
h =>
h.MapFromAttributes(10).Properties(p => p
.String(s => s.Name(i => i.ByEmail).Index(FieldIndexOption.NotAnalyzed))
.String(s => s.Name(i => i.ToEmail).Index(FieldIndexOption.NotAnalyzed))
));
IsServerError(response);
}
catch (Exception ex)
{
Logger.LogException(ex, _soruce, "BlackListDataManager", Severity.Critical);
throw;
}
}
示例8: Main
public static void Main(string[] args)
{
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node, "elastic-searcher");
settings.SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant());
IElasticClient client = new ElasticClient(settings);
IPersonSearch personSearcher = new PersonSearch(client);
Utils.IndexItems(client);
var value = Console.ReadLine();
int id = Convert.ToInt32(value);
if (id != 0)
{
personSearcher.GetItem<Person>(id);
}
else
{
Utils.ClearItems(client);
}
Console.ReadKey();
}
示例9: SearchDoesNotTakeDefaultIndexIntoAccount
[U] public void SearchDoesNotTakeDefaultIndexIntoAccount()
{
var node = new Uri("http://localhost:9200");
var connectionPool = new SingleNodeConnectionPool(node);
var connectionSettings = new ConnectionSettings(connectionPool, connection: new InMemoryConnection())
.DefaultIndex("logstash-*")
.DefaultFieldNameInferrer(p => p)
.OnRequestCompleted(info =>
{
// info.Uri is /_search/ without the default index
// my ES instance throws an error on the .kibana index (@timestamp field not mapped because I sort on @timestamp)
});
var client = new ElasticClient(connectionSettings);
var response = client.Search<ESLogEvent>(s=>s);
response.ApiCall.Uri.AbsolutePath.Should().Be("/logstash-%2A/eslogevent/_search");
response = client.Search<ESLogEvent>(new SearchRequest<ESLogEvent>{ });
response.ApiCall.Uri.AbsolutePath.Should().Be("/logstash-%2A/eslogevent/_search");
response = client.Search<ESLogEvent>(new SearchRequest { });
response.ApiCall.Uri.AbsolutePath.Should().Be("/_search");
}
示例10: Get
public async Task<IEnumerable<Message>> Get(string q, int from, int size)
{
var url = ConfigurationManager.AppSettings["ES_URL"];
var setting = new ConnectionSettings(new Uri(url));
var client = new ElasticClient(setting);
// Parse the search query
string[] terms = q.Split(' ');
var personTerm = terms.SingleOrDefault(x => x.StartsWith("person:"));
if (!string.IsNullOrEmpty(personTerm))
{
terms = terms.Except(new string[] { personTerm }).ToArray();
personTerm = personTerm.Replace("person:", string.Empty);
}
var textTerms = string.Join(" ", terms);
var searchResults = await client.SearchAsync<Message>(s => s
.AllIndices()
.AllTypes()
.Size(size)
.From(from)
.SortAscending(f => f.Date)
.Query(qry =>
(qry.Term("from", personTerm) ||
qry.Term("to", personTerm)) &&
qry.Match(m => m
.OnField(f => f.Text)
.Query(textTerms)
.Operator(Operator.And))));
return searchResults.Documents;
}
示例11: ReIndexAll
public ActionResult ReIndexAll()
{
var documents = db.Documents.ToList();
var uriString = ConfigurationManager.AppSettings["SEARCHBOX_URL"];
var searchBoxUri = new Uri(uriString);
var settings = new ConnectionSettings(searchBoxUri);
settings.SetDefaultIndex("sample");
var client = new ElasticClient(settings);
// delete index if exists at startup
if (client.IndexExists("sample").Exists)
{
client.DeleteIndex("sample");
}
// Create a new "sample" index with default settings
client.CreateIndex("sample", new IndexSettings());
// Index all documents
client.IndexMany<Document>(documents);
ViewBag.Message = "Reindexing all database is complete!";
return RedirectToAction("Index");
}
示例12: Index
// GET: Search
public ActionResult Index(string r)
{
var uri = new Uri("https://IlwEAOgvDkuHk3yiB74RhwSs1YC0KCUu:@aniknaemm.east-us.azr.facetflow.io");
var settings = new ConnectionSettings(uri).SetDefaultIndex("indexdem");
var client = new ElasticClient(settings);
var result = client.Search<Demotivator>(q => q
.Query(f => f
.QueryString(t => t.Query(r + "*").OnFields(u => u.Name)) || f
.QueryString(t => t.Query(r + "*").OnFields(u => u.Str1)))
);
SearchViewModel model = new SearchViewModel();
List<Demotivator> tr = new List<Demotivator>();
foreach (var t in result.Hits)
{
var sleep = (Demotivator)t.Source;
int temp = new int();
if (sleep != null)
{
tr.Add(sleep);
}
else
{
}
}
model.demotivators = tr;
return View(model);
}
示例13: ProfiledElasticClient
/// <summary>
/// Provides base <see cref="ElasticClient"/> with profiling features to current <see cref="MiniProfiler"/> session.
/// </summary>
/// <param name="configuration">Instance of <see cref="ConnectionSettings"/>. Its responses will be handled and pushed to <see cref="MiniProfiler"/></param>
public ProfiledElasticClient(ConnectionSettings configuration)
: base(configuration)
{
ProfilerUtils.ExcludeElasticsearchAssemblies();
ProfilerUtils.ApplyConfigurationSettings(configuration);
configuration.SetConnectionStatusHandler(response => MiniProfilerElasticsearch.HandleResponse(response, _profiler));
}
示例14: GameDataManager
public GameDataManager()
{
try
{
var elasticSearchUrl = ConfigurationManager.AppSettings["ElasticStoreConnection"];
var index = ConfigurationManager.AppSettings["EIndex_Game"];
_settings =
new ConnectionSettings(new Uri(elasticSearchUrl)).SetDefaultIndex(index).PluralizeTypeNames();
_client = new ElasticClient(_settings);
var isIndexExist = _client.IndexExists(i => i.Index(index));
if (!isIndexExist.Exists)
{
_client.CreateIndex(c => c.Index(index));
_settings.SetDefaultIndex(index);
_client = new ElasticClient(_settings);
}
var response =
_client.Map<Game>(
h =>
h.Properties(p => p
.String(s => s.Name(i => i.GameId).Index(FieldIndexOption.NotAnalyzed))
.String(s => s.Name(i => i.Status).Index(FieldIndexOption.NotAnalyzed))
.String(s => s.Name(i => i.TurnOfPlayer).Index(FieldIndexOption.NotAnalyzed))
.Object<Winner>(o => o.Name(w => w.Winner).Properties(wp => wp.String(f => f.Name(l => l.FacebookId).Index(FieldIndexOption.NotAnalyzed)))
)));
IsServerError(response);
}
catch (Exception ex)
{
Logger.LogException(ex, _source, "GameDataManager", Severity.Critical);
throw;
}
}
示例15: SearchList
public static List<NewsBase> SearchList(string nid)
{
string espath = ConfigurationManager.AppSettings["ESPath"].ToString();
string indexname = ConfigurationManager.AppSettings["IndexName"].ToString();
string typename = ConfigurationManager.AppSettings["TypeName"].ToString();
var node = new Uri(espath);
var settings = new ConnectionSettings(node);
var client = new ElasticClient(settings);
//keyword = String.Format("*{0}*", keyword);
var searchResults = client.Search<NewsBase>(s => s
.Index(indexname)
.Type(typename)
.Query(q => q.QueryString(qs => qs.Query(nid).DefaultOperator(Operator.And)))
.Sort(st => st.OnField(f => f.newsid).Order(SortOrder.Descending)) /*按ID排序,id为数字,排序正常*/
//.Sort(st=>st.OnField(f=>f.PubDate.Suffix("sort")).Descending()) /*按时间排序,时间格式,排序bug;中文字符串bug*/
.From(0)
.Size(1)
);
List<NewsBase> eslist = new List<NewsBase>(searchResults.Documents);
//foreach (var data in searchResults.Documents)
//{
// eslist.Add(data);
//}
return eslist;
}