1

I am trying to use ElasticSearch with Play 2.3.7 Scala. I have installed elastic search, added an index, and have it up and running (tested using curl). However, I am struggling to get elastic4s to work inside of a play controller.

I have created the client using a simple remote url

val client = ElasticClient.remote("localhost", 9300)    

I then try to execute on the client.

client.execute {
    ElasticDsl.index.into("test/test").id(id).fields (
                    "title" -> title,
                    "uid" -> uid
    )
}

This is executed inside of an Action, but I get the following error.

could not find implicit value for parameter executable: com.sksamuel.elastic4s.Executable[com.sksamuel.elastic4s.IndexDefinition,R,Q]
Codemwnci
  • 54,176
  • 10
  • 96
  • 129
  • Have you seen this issue, it seems like your client.execute() needs to be wrapped in multi def. https://github.com/sksamuel/elastic4s/issues/324 – Laksitha Ranasingha Aug 14 '16 at 16:26
  • I did see that issue, but in that example they are doing two searches (hence the need for multi), where as I am doing a single index, so multi should not be needed. I tried regardless though, and got an error to say that multi cannot be used with index. – Codemwnci Aug 14 '16 at 16:27

1 Answers1

1

This appears to be caused because I was not doing a full import of ElasticDsl as follows

import com.sksamuel.elastic4s.ElasticDsl._ 

but instead doing

import com.sksamuel.elastic4s.ElasticDsl

When importing the full object, it clearly invokes the companion objects, including the implicits needed.

The reason for not doing a full import, was because the DSL for elastic was clashing with the DSL for Anorm, so by extracting the Elastic code to a separate function, and using the import inside of the function definition, the ambiguity was removed and the code was able to compile.

Codemwnci
  • 54,176
  • 10
  • 96
  • 129
  • 1
    FYI I had the same problem and `import com.sksamuel.elastic4s.ElasticDsl._ ` fixed it for me – Rhys Bradbury Nov 03 '16 at 11:06
  • 2
    For the version 5.3 I had the same problem. In http://elastic4s.readthedocs.io/en/latest/src/main/tut/docs/ it says that if i've instantiated the `TcpClient`, i need to use the `com.sksamuel.elastic4s.ElasticDSL._` import. However if I use the HttpClient, i need to use the `com.sksamuel.elastic4s.http.ElasticDSL._` (take care that is a different package: see the inner **http** ) – andhdo Apr 19 '17 at 13:48