var connection = new InMemoryConnection();
var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(connectionPool, connection);
var client = new ElasticClient(settings);
|
var response = new
{
took = 1,
timed_out = false,
_shards = new
{
total = 2,
successful = 2,
failed = 0
},
hits = new
{
total = new { value = 25 },
max_score = 1.0,
hits = Enumerable.Range(1, 25).Select(i => (object)new
{
_index = "project",
_type = "project",
_id = $"Project {i}",
_score = 1.0,
_source = new { name = $"Project {i}" }
}).ToArray()
}
};
var responseBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response));
var connection = new InMemoryConnection(responseBytes, 200); ①
var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(connectionPool, connection).DefaultIndex("project");
var client = new ElasticClient(settings);
var searchResponse = client.Search<Project>(s => s.MatchAll());
|
public class MyCustomHttpConnection : HttpConnection
{
protected override HttpRequestMessage CreateRequestMessage(RequestData requestData)
{
var message = base.CreateRequestMessage(requestData);
var header = string.Empty;
message.Headers.Authorization = new AuthenticationHeaderValue("Negotiate", header);
return message;
}
}
public class KerberosConnection : HttpConnection
{
protected override HttpRequestMessage CreateRequestMessage(RequestData requestData)
{
var message = base.CreateRequestMessage(requestData);
var header = string.Empty;
message.Headers.Authorization = new AuthenticationHeaderValue("Negotiate", header);
return message;
}
}
|
ElasticSearch-NEST -03Modifying the default connection(修改默认连接) (官网谷歌翻译)
原文:https://www.cnblogs.com/xianchengzhang/p/14629951.html