Search code examples
scalaplayframework-2.0elasticsearchelastic4s

elastic4s and play framework 2.2.1


i'm trying to index some data to elastic search by using the elastic4s API and play framework

I'm basically calling this method from the controller

 def test(){
 val client = ElasticClient.local
 client.execute { create index "bands" }
 client execute { index into "bands/singers" fields "name"->"chris martin" }
 client.close()

 }

I didn't get any error on play or in the elastic search log,

Then i checked with the Sense plugin if the data is indexed and i got

  {
   "error": "IndexMissingException[[bands] missing]",
  "status": 404
   }

It looks like the query didn't go to the server?? ...


Solution

  • It's hard to tell for sure, but it could be that the execute calls actually are throwing exceptions that you aren't seeing because the Client.execute method returns a Future[Res] instead of blocking and returning a Res directly.

    And forgive me if I'm wrong about this, but since it sounds like you're just familiarizing yourself with how this lib works, I'd suggest using an onComplete callback (or some other strategy on the Scala futures page) to see what's going on when the Future is actually completed.