我正在尝试通过使用 elastic4s API和 Play Framework
我基本上是从 Controller 调用这个方法
def test(){
val client = ElasticClient.local
client.execute { create index "bands" }
client execute { index into "bands/singers" fields "name"->"chris martin" }
client.close()
}
我在 Play 或 Elasticsearch 日志中没有收到任何错误,
然后我检查了 Sense如果数据被索引并且我得到了插件
{
"error": "IndexMissingException[[bands] missing]",
"status": 404
}
看起来查询没有发送到服务器?? ...
最佳答案
这是因为创建索引不是同步的,所以您试图在创建索引完成之前建立索引。
最简单的方法是通过调用同步创建索引
client.sync.execute { 创建索引“bands” }
这将阻塞直到创建索引,这应该 < 1 秒。或者您可以计算返回的 future 。
编辑:在 elastic4s 1.3 中,sync 已替换为 futures 上的 .await 助手。
client.execute(创建索引“bands”).await
关于scala - elastic4s 和 play framework 2.2.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21803201/