I've been using elastic4s for my data retrieval and have begun looking into testing for my current code. I am trying to create a local client that I can then use (and pass to my actors) that will be more manageable for testing than having to deploy an elastic cluster on a build server and keep it maintained.
Below is the code I've been trying so far. This should start a simple instance, create an index, add a video into the "videos" index, and then retrieve it.
val essettings = ImmutableSettings
.settingsBuilder().put("cluster.name", conf.getString("elasticsearch.cluster-name")).build()
ElasticsearchConnection.setInstance(ElasticClient.local(essettings))
val client = ElasticsearchConnection.getInstance()
client.execute( create index "videos" mappings(
"video" as (
"artist" typed StringType,
"title" typed StringType
)
)
)
client.execute(
bulk(
index into "videos" id 1 fields ("title" -> "Worth It", "artist" -> "Fifth Harmony")
)
).await
val resp = client.execute(
search in "videos" types "video" limit 1 query bool {
must (
matchQuery("artist", "Fifth Harmony")
)
}
).await
However it is not working as I'd expect it to. It runs through without breaking on any of the lines, but no data is found in resp
. I use the same type of queries with an external ES cluster, so I think there's something wrong with how I'm setting it up.