我需要列出所有索引并输入Elasticsearch。
基本上,我使用_client.stats().Indices
来获取索引,并使用foreach
排除的索引列表进行过滤。
代码如:
public Dictionary<string, Stats> AllIndexes()
{
_client = new ElasticClient(setting);
var result = _client.Stats();
var allIndex = result.Indices;
var excludedIndexList = ExcludedIndexList();
foreach (var index in excludedIndexList)
{
if (allIndex.ContainsKey(index)) allIndex.Remove(index);
}
return allIndex;
}
这是从Elasticsearch列出所有索引的正确方法,还是有更好的方法。
答案 0 :(得分:3)
这是有效的,一种略显性感的写作方式是在result.Indices上使用.Except()
。
另一种方法是使用.CatIndices()
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cat-indices.html
答案 1 :(得分:1)
代码Assembly Nest, Version=6.0.0.0
如下
var result = await _client.GetIndexAsync(null, c => c
.AllIndices()
);
您将在result.Indices.Keys
字符串列表中获得结果
答案 2 :(得分:0)
GetIndexAsync
已从Assembly Nest, Version=7.0.0.0
中删除
来自Version=7.0.0.0
的您可以使用此:
var result = await _client.Indices.GetAsync(new GetIndexRequest(Indices.All));
答案 3 :(得分:0)
在 Version=7.0.0.0 中,GetIndexAsync 方法不再接受 null。 解决办法:
def local(time, est_weekday = nil)
days = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday]
local_time = Time.parse(time)
utc_time = TZInfo::Timezone.get('America/New_York').local_to_utc(local_time)
utc_time_formatted = utc_time.strftime("%I:%M %p")
if est_weekday && days.include?(est_weekday.downcase.to_sym)
#extract intended wday for ruby datetime and assign
weekday_index = days.index(est_weekday.downcase.to_sym)
#get placeholder wday from desired EST day/time
temp_est_weekday_index = local_time.wday
#get placeholder wday from adjusted UTC day/time
temp_utc_weekday_index = utc_time.wday
#has the conversion to UTC advanced the wday?
weekday_advances = temp_utc_weekday_index != temp_est_weekday_index
#adjust wday index if timezone conversion has advanced weekday
weekday_index += 1 if weekday_advances
weekday = days[weekday_index]
return {time: utc_time_formatted, day: weekday || nil }
else
return utc_time_formatted
end
end