弹性搜索和.NET [英] Elasticsearch and .NET

查看:235
本文介绍了弹性搜索和.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);
}

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

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.

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

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.

提前感谢。

推荐答案

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

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


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

  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.

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

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.

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

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

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

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.

这篇关于弹性搜索和.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆