如何通过Alias在Elasticsearch java api中找到索引? [英] How to find Index by Alias in Elasticsearch java api?

查看:729
本文介绍了如何通过Alias在Elasticsearch java api中找到索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重建索引需要30秒,我不希望我的搜索在每次需要重新索引时离线30秒。我试图这样做:

Reindexing takes 30 seconds and I don't want my search to be offline for 30 seconds every time I need to reindex. I'm trying to do this:


  1. 使用alias = abc123查找旧索引

  2. 创建新的索引并填写新数据

  3. 删除别名并删除旧索引

  4. 给新索引alias = abc123

  1. Find old index with alias = abc123
  2. Create new index and fill with new data
  3. Remove alias and delete old index
  4. Give new index alias = abc123


    我似乎找不到任何java代码,1)。一切都好任何人?或者还有另一种方法更好吗?

I can't seem to find any java code that does 1). Everything else is fine. Anyone? or is there another way that is better?

使用Elasticsearch 0.90.9。

Using Elasticsearch 0.90.9.

推荐答案

您可以使用它来获取所有别名:

You can use this to get all of the aliases:

 client.admin().cluster()
    .prepareState().execute()
    .actionGet().getState()
    .getMetaData().getAliases();

这将返回一个索引名称为键的地图别名作为值。因此,您可以遍历地图以获取索引名称。

This returns a map with the index name as the key and the aliases as the value. So you can iterate over the map to get the index name.

这篇关于如何通过Alias在Elasticsearch java api中找到索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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