elasticsearch .net客户端完成建议器性能

时间:2018-05-21 08:50:22

标签: elasticsearch nest elasticsearch-net

对于使用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))));
        };

0 个答案:

没有答案