本文整理汇总了C#中Nest.ElasticClient类的典型用法代码示例。如果您正苦于以下问题:C# ElasticClient类的具体用法?C# ElasticClient怎么用?C# ElasticClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ElasticClient类属于Nest命名空间,在下文中一共展示了ElasticClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: construct_client_with_null
public void construct_client_with_null()
{
Assert.Throws<ArgumentNullException>(() =>
{
var client = new ElasticClient(null);
});
}
示例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: GenerateAndIndex
protected static void GenerateAndIndex(ElasticClient client, string indexName, int numMessages, int bufferSize)
{
var msgGenerator = new MessageGenerator();
var tasks = new List<Task>();
var partitionedMessages = msgGenerator.Generate(numMessages).Partition(bufferSize);
client.CreateIndex(indexName, c => c
.NumberOfReplicas(0)
.NumberOfShards(1)
.Settings(s => s.Add("refresh_interval", "-1"))
.AddMapping<Message>(p=>p.MapFromAttributes())
);
Interlocked.Exchange(ref NumSent, 0);
foreach (var messages in partitionedMessages)
{
var t = client.IndexManyAsync(messages, indexName)
.ContinueWith(tt =>
{
Interlocked.Add(ref NumSent, bufferSize);
Console.WriteLine("Sent {0:0,0} messages to {1}, {2}", NumSent, indexName, tt.Result.Took);
})
;
tasks.Add(t);
}
Task.WaitAll(tasks.ToArray());
client.UpdateSettings(u => u
.Index(indexName)
.RefreshInterval("1s")
);
}
示例5: TestAlternateIdLookup
public void TestAlternateIdLookup()
{
var client = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200")));
var expectedGuid = Guid.NewGuid();
var id = new IdResolver().GetIdFor(new AlternateIdClass { Guid = expectedGuid });
StringAssert.AreEqualIgnoringCase(expectedGuid.ToString(), id);
}
示例6: SingleNode
/** = Connection Pooling
* Connection pooling is the internal mechanism that takes care of registering what nodes there are in the cluster and which
* we can use to issue client calls on.
*/
/** == SingleNodeConnectionPool
* The simplest of all connection pools, this takes a single `Uri` and uses that to connect to elasticsearch for all the calls
* It doesn't opt in to sniffing and pinging behavior, and will never mark nodes dead or alive. The one `Uri` it holds is always
* ready to go.
*/
[U] public void SingleNode()
{
var uri = new Uri("http://localhost:9201");
var pool = new SingleNodeConnectionPool(uri);
pool.Nodes.Should().HaveCount(1);
var node = pool.Nodes.First();
node.Uri.Port.Should().Be(9201);
/** This type of pool is hardwired to optout out sniffing*/
pool.SupportsReseeding.Should().BeFalse();
/** and pinging */
pool.SupportsPinging.Should().BeFalse();
/** When you use the low ceremony ElasticClient constructor that takes a single Uri
* We default to this SingleNodeConnectionPool */
var client = new ElasticClient(uri);
client.ConnectionSettings.ConnectionPool.Should().BeOfType<SingleNodeConnectionPool>();
/** However we urge that you always pass your connection settings explicitly */
client = new ElasticClient(new ConnectionSettings(uri));
client.ConnectionSettings.ConnectionPool.Should().BeOfType<SingleNodeConnectionPool>();
/** or even better pass the connection pool explicitly */
client = new ElasticClient(new ConnectionSettings(pool));
client.ConnectionSettings.ConnectionPool.Should().BeOfType<SingleNodeConnectionPool>();
}
示例7: 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();
}
示例8: SearchAdapter
private SearchAdapter()
{
esconnSetting = new ConnectionSettings(
new Uri(ESConnectionSetting.Node), "lt028310");
esClient = new ElasticClient(esconnSetting);
}
示例9: LogstashRepo
public LogstashRepo()
{
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node, defaultIndex: "logstash-2015.08.18");
var client = new ElasticClient(settings);
_client = client;
}
示例10: 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();
}
示例11: 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");
}
示例12: 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");
}
示例13: ElasticClientForIndexingFiles
private static ElasticClient ElasticClientForIndexingFiles(
IConnectionSettingsValues connectionSettingsForIndexingFiles)
{
var elasticClientForIndexingFiles =
new ElasticClient(connectionSettingsForIndexingFiles);
return elasticClientForIndexingFiles;
}
示例14: 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;
}
示例15: ProductRepository
public ProductRepository(IAggregateFactory aggregateFactory)
{
_client = new ElasticClient();
_factory = aggregateFactory;
Mapper.CreateMap<Product, ProductDTO>();
}