我们是否需要在每个搜索请求之后关闭elasticsearch节点 [英] do we need to close elasticsearch node after the every search request

查看:108
本文介绍了我们是否需要在每个搜索请求之后关闭elasticsearch节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道:每次完成查询/搜索过程时,是否都必须调用 node.close()还是只是 client.close()>可以吗?这是我的代码:

I want to know: do we have to call node.close() every time when we are done with our querying/searching process or just client.close() is fine? Here is my code:

val node =nodeBuilder().client(true).node()
val client =node.client()
val query = QueryBuilders.matchQuery(fieldName.toString(), q).fuzziness(Fuzziness.AUTO)//user can make 2 typo mistakes

val response = client.prepareSearch("arteciatedb")
      .setTypes("readOnlyAdmin")
      .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
      .addFields("uuid","FirstName","LastName","Email","SecondryEmail","UserStatus","_source")
      .setQuery(query)
      .execute()
      .actionGet()


 val hits = response.getHits

 totalHits=hits.getTotalHits
log.info("total search result {}",)   
client.close()
node.close()

我经常运行此代码;因此,在 node.close()之后,下次我执行此代码时,它将再次启动节点(导致搜索响应延迟),这是不希望的.我想知道 node.close()在我们需要经常调用此搜索代码时是否正确.

I am running this code frequently; so, after node.close(), the next time I execute this code, it starts up the node again (causing delays in search response), which is not desired. I want to know if node.close() is the right thing to do when we need to call this searching code frequently.

推荐答案

简而言之:不,您可以随时间重复使用同一客户端而不会遇到麻烦. close()仅应在关机时使用.此外,频繁启动和停止一个或多个节点客户端会在整个群集中产生不必要的噪音.

In short: no, you can reuse the same client over time without trouble. close() should be used on shutdown only. Moreover, frequently starting and stopping one or more node clients creates unnecessary noise across the cluster.

请注意,使用 nodeBuilder().client(true).node(),您正在创建一个节点,该节点将加入ES集群.如果您只想要一个客户端而不是一个节点,则应使用 TransportClient (

Note that using nodeBuilder().client(true).node(), you are creating a node, that will join the ES cluster. If you just want a client and not a node, you should use TransportClient (https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html).

这篇关于我们是否需要在每个搜索请求之后关闭elasticsearch节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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