弹性 / elasticsearch-ruby gem || 如何调用 put_lifecycle 方法

huangapple go评论67阅读模式
英文:

elastic / elasticsearch-ruby gem || How call put_lifecycle method

问题

我正在使用 elasticsearch-ruby (7.15.0)

我想创建一个生命周期策略。

我是这样做的....

```ruby
  $elastic ||= Elasticsearch::Client.new(
    host: $settings['business.elastic_server'],
    user: $settings['business.elastic_username'],
    password: $settings['business.elastic_password'],
    log: false
  )

 $elastic.ilm.put_lifecycle(
    policy: 'my_policy',
    body: {"policy":{"phases":{"delete":{"min_age":"30d","actions":{"delete":{}}}}}}
  )

然后我得到了:

elasticsearch-7.15.0/lib/elasticsearch.rb:43:in `method_missing': undefined method `ilm' 

调用 put_lifecycle 方法的正确方式是什么?

谢谢


<details>
<summary>英文:</summary>

I&#39;m using elasticsearch-ruby (7.15.0)

I want to create a lifecycle policy.

I&#39;m doing it like this....

```ruby
  $elastic ||= Elasticsearch::Client.new(
    host: $settings[&#39;business.elastic_server&#39;],
    user: $settings[&#39;business.elastic_username&#39;],
    password: $settings[&#39;business.elastic_password&#39;],
    log: false
  )

 $elastic.ilm.put_lifecycle(
    policy: &#39;my_policy&#39;,
    body: {&quot;policy&quot;:{&quot;phases&quot;:{&quot;delete&quot;:{&quot;min_age&quot;:&quot;30d&quot;,&quot;actions&quot;:{&quot;delete&quot;:{}}}}}}
  )

Then I got.

elasticsearch-7.15.0/lib/elasticsearch.rb:43:in `method_missing&#39;: undefined method `ilm&#39; 

What is the proper way to call put_lifecycle method?

Thanks

答案1

得分: 1

最后,我决定将我的Gemfile升级为gem 'elasticsearch','8.6.0',并且工作得很好。

这个解释由Fernando Briano(picandocodigo)提供,正如@vasily-kolesnikov在评论中所说

在客户端的7.15版本中,索引生命周期管理API可以通过elasticsearch-xpack gem获得。你是否在你的代码中引用了它?代码的其余部分看起来没问题,如果你已经引入了elasticsearch-xpack,它应该可以工作。如果这是问题,请告诉我,谢谢!

最佳选择是使用与服务器次要版本相同的客户端次要版本。

英文:

Finally I decided to upgrade my Gemfile with gem 'elasticsearch', '8.6.0' and works perfect.

The explanation has been provided by Fernando Briano (picandocodigo ) as @vasily-kolesnikov said in a comment

In version 7.15 of the client, the index lifecycle management APIs are available through the elasticsearch-xpack gem. Have you required it in your code? The rest of the code looks ok, it should work if you have required elasticsearch-xpack.
Let me know if that's the issue, thanks!

The best option is to use the client minor version equal to the server's minor version.

huangapple
  • 本文由 发表于 2023年6月29日 23:34:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76582557.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定