弹性搜索和.NET(Elasticsearch and .NET)

120 IT屋

We're considering to switch from Solr/Solr.net to Elasticsearch. We started with NEST. We have only 4 documents in search index.

private static void Main(string[] args)
{
    var node = new Uri("http://localhost:9200");
    var settings = new ConnectionSettings(
        node, "my-application");

    var client = new ElasticClient(settings);

    var stopwatch = Stopwatch.StartNew();
    var sr = client.Get<Movie>(1);

    Console.WriteLine(stopwatch.ElapsedMilliseconds);
}

The code above takes approx. 250ms, while the same code with HttpClient and JsonSerializer takes 30-45ms. 250ms is too much time for just 4 documents.

Can NEST be used on high-traffic news website, or do you recommend HttpClient + JsonSerializer combo? The search page was the most visited page on our website in 2013.

Thanks in advance.

解决方案

There are two things that have to happen in order for NEST to make the first request.

  1. The Json Serializer (Json.net) in this case has to cache the type so that it knows how to serialize and deserialize the object you are sending back and forth.

  2. Nest has its own fluent language for queries that must be translated from the intial types that represent the fluent query language and the delivered as JSON to elastic search. These document types also must be learned by the Json Serializer.

  3. The HTTP client has to be spun up to make the request.

I currently have over 4M documents in a single index that I use with NEST and my searches from server all the way to client over the internet are taking 50-70 ms using NEST. Like you, however, after a cold start the first request is slow.

我们正在考虑从Solr / Solr.net切换到Elasticsearch。我们从 NEST 开始。我们在搜索索引中只有4个文档。



  private static void Main(string [] args)
{
var node = new Uri("http:// localhost:9200");
var settings = new ConnectionSettings(
node,"my-application");

var client = new ElasticClient(settings);

var stopwatch = Stopwatch.StartNew();
var sr = client.Get< Movie>(1);

Console.WriteLine(stopwatch.ElapsedMilliseconds);
}


上面的代码大约需要250ms,而与 HttpClient 和 JsonSerializer 相同的代码需要30-45ms。 250ms是只有4个文件的时间太多。



可以在高流量新闻网站上使用NEST,还是推荐 HttpClient + JsonSerializer 组合?搜索页面是2013年我们网站上访问量最多的网页。



提前感谢。


解决方案

为了让NEST发出第一个请求,有两件事必须发生。




  1. 在这种情况下,Json Serializer(Json.net)必须缓存该类型,以便它知道如何对要发送的对象进行序列化和反序列化,


  2. Nest有自己的流畅的语言,需要从表示流畅查询语言的初级类型翻译出来,并将其作为JSON传递给弹性搜索。这些文档类型也必须由Json Serializer学习。


  3. HTTP客户端必须被转移以提出请求。




我目前在单个索引中使用了超过4M的文档,我与NEST一起使用,我从服务器到互联网上的客户端的搜索正在采取50-70 ms使用NEST。然而,像你一样,冷启动后,第一个请求很慢。


本文地址:IT屋 » 弹性搜索和.NET

相关文章: