对于使用 Nest 或 Elasticsearch.Net 客户端的某些请求,响应时间超过 500 毫秒。当直接使用 http 客户端或抛出 kibana 接口时,相同的查询大约需要 1-2ms。如果数据库中的文档很少,则会发生这种情况。
我在 localhost 上使用以下设置:
PUT suggestions
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"suggestionelement": {
"properties": {
"suggest": {
"type": "completion",
"max_input_length": 100
}
}
}
}
}
并索引以下文档:
POST suggestions/suggestionelement
{
"suggest": {
"input": "this is just some text for suggestion a",
"weight": 1
}
}
POST suggestions/suggestionelement
{
"suggest": {
"input": "this is just some text for suggestion b",
"weight": 2
}
}
POST suggestions/suggestionelement
{
"suggest": {
"input": "this is just some text for suggestion c",
"weight": 3
}
}
POST suggestions/suggestionelement
{
"suggest": {
"input": "this is just some text for suggestion d",
"weight": 4
}
}
POST suggestions/suggestionelement
{
"suggest": {
"input": "this is just some text for suggestion e",
"weight": 5
}
}
当运行“这只是一些文本”的建议(完成)查询抛出 Nest 或 Elasticsearch.Net 客户端时,它需要超过 500 毫秒。从 kibana 或直接使用 httpclient 运行相同的程序只需不到 2 毫秒
已经做了好几天了……有什么想法吗?
我使用的 C# 代码:
var nodes = new Uri[] { new Uri("http://localhost:9200") };
var connectionPool = new StaticConnectionPool(nodes);
var connectionSettings = new ConnectionSettings(connectionPool)
.DefaultIndex("suggestions")
.RequestTimeout(TimeSpan.FromSeconds(30));
var searchEngineClient = new ElasticClient(connectionSettings);
for (int i = 0; i < 10; i++)
{
return await searchEngineClient.SearchAsync<SuggestionElement>(s =>
s.Suggest(ss => ss
.Completion("sentence-suggest", c => c
.Field(f => f.Suggest)
.Prefix("this is just some text for")
.Size(1000))));
};