2016-12-20 6 views
0

sksamuel/elastic4sでScalaを使用してElasticserach 5.1.1の良い例を見つけることができません。ドキュメンテーションはそれほど役に立ちませんし、サイトのどれもそれについての良い例はありません。インデックス、プットデータ、および検索を作成する簡単な例でも役立ちます。Elasticserach 5.1.1のための良い例はありますか?sksamuel/elastic4sまたは何か他のものを使用しているScala API?

答えて

0

elastic4sのreadmeには、始めに必要なすべての例があります。確かに、高度なユースケースでは軽いですが、単純な例では十分です。

たとえば、quick start guideを読んでください。

import com.sksamuel.elastic4s.TcpClient 
import com.sksamuel.elastic4s.ElasticDsl._ 

object Test extends App { 

    // Here we create an instance of the TCP client 
    val client = TcpClient.transport(ElasticsearchClientUri(host, port)) 

    // await is a helper method to make this operation synchronous instead of async 
    // You would normally avoid doing this in a real program as it will block your thread 
    client.execute { 
    indexInto("bands"/"artists") fields ("name" -> "coldplay") refresh(RefreshPolicy.IMMEDIATE) 
    }.await 

    // now we can search for the document we just indexed 
    val resp = client.execute { 
    search("bands"/"artists") query "coldplay" 
    }.await 

    println(resp) 
} 
関連する問題