我们一直在项目中使用 Elasticsearch 插件。从别名获取索引名称时出错
错误
{
"error": "AssertionError[Expected current thread[Thread[elasticsearch[Seth][http_server_worker][T#2]{New I/O worker #20},5,main]] to not be a transport thread. Reason: [Blocking operation]]", "status": 500
}
法典
String realIndex = client.admin().cluster().prepareState()
.execute().actionGet().getState().getMetaData()
.aliases().get(aliasName).iterator()
.next().key;
是什么原因导致此问题??谷歌搜索它没有得到任何帮助
从错误的外观来看,似乎不允许在传输线程上执行此操作,因为它会阻塞线程,直到您得到结果。您需要在执行线程上执行此操作。
public String getIndexName() {
final IndexNameHolder result = new IndexNameHolder(); // holds the index Name. Needed a final instance here, hence created a holder.
getTransportClient().admin().cluster().prepareState().execute(new ActionListener<ClusterStateResponse>() {
@Override
public void onResponse(ClusterStateResponse response) {
result.indexName = response.getState().getMetaData().aliases().get("alias").iterator().next().key;
}
@Override
public void onFailure(Throwable e) {
//Handle failures
}
});
return result.value;
}
还有另一种execute()
方法,一种需要听众的方法。您需要实现自己的侦听器。在我的回答中,我有一个匿名的监听实现。
我希望它有所帮助