<commit_before>package com.sksamuel.elastic4s

import com.sksamuel.elastic4s.ElasticDsl._
import org.scalatest.{ FlatSpec, Matchers }
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.mock.MockitoSugar

/** @author <NAME> */
class GetTest extends FlatSpec with Matchers with ScalaFutures with MockitoSugar with ElasticSugar {

  client.execute {
    bulk(
      index into "beer/lager" fields ("name" -> "coors light", "brand" -> "coors") id 4,
      index into "beer/lager" fields ("name" -> "bud lite", "brand" -> "bud") id 8
    )
  }.await

  refresh("beer")
  blockUntilCount(2, "beer")

  "A Get request" should "retrieve a document by id" in {

    val resp = client.execute {
      get id 8 from "beer/lager"
    }.await
    assert("8" === resp.getId)
  }

  it should "retrieve a document asynchronously by id" in {

    val resp = client.execute {
      get id 8 from "beer/lager"
    }

    whenReady(resp) { result =>
      result.isExists should be(true)
      result.getId shouldBe "8"
    }
  }

  it should "retrieve a document asynchronously by id w/ source" in {

    val resp = client.execute {
      get id 8 from "beer/lager"
    }

    whenReady(resp) { result =>
      result.isExists should be(true)
      result.getId shouldBe "8"
      result.getSource should not be (null)
      result.getFields should have size 0
    }
  }

  it should "retrieve a document asynchronously by id w/o source" in {

    val resp = client.execute {
      get id 8 from "beer/lager" fetchSourceContext false
    }

    whenReady(resp) { result =>
      result.isExists should be(true)
      result.getId shouldBe "8"
      result.getSource should be(null)
      result.getFields should have size 0
    }
  }

  it should "retrieve a document asynchronously by id w/ name and w/o source" in {

    val resp = client.execute {
      get id 8 from "beer/lager" fields ("name")
    }

    whenReady(resp) { result =>
      result.isExists should be(true)
      result.getId shouldBe "8"
      result.getSource should be(null)
      result.getFields should (contain key ("name") and not contain key("brand"))
    }
  }

  it should "retrieve a document asynchronously by id w/ name and brand and source" in {

    val resp = client.execute {
      get id 4 from "beer/lager" fields ("name") fetchSourceContext true
    }

    whenReady(resp) { result =>
      result.isExists should be(true)
      result.getId shouldBe "4"
      result.getSource should not be (null)
      result.getFields should (contain key ("name") and not contain key("brand"))
    }
  }

  it should "not retrieve any documents w/ unknown id" in {

    val resp = client.execute {
      get id 1 from "beer/lager" fields ("name") fetchSourceContext true
    }

    whenReady(resp) { result =>
      result.isExists should be(false)
    }
  }

}
<commit_msg>Added test to show how multi values retrieval works #251<commit_after>package com.sksamuel.elastic4s

import com.sksamuel.elastic4s.ElasticDsl._
import org.scalatest.{ FlatSpec, Matchers }
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.mock.MockitoSugar

/** @author <NAME> */
class GetTest extends FlatSpec with Matchers with ScalaFutures with MockitoSugar with ElasticSugar {

  client.execute {
    bulk(
      index into "beer/lager" fields("name" -> "coors light", "brand" -> "coors", "ingredients" -> Seq("hops",
        "barley",
        "water",
        "yeast")) id 4,
      index into "beer/lager" fields ("name" -> "bud lite", "brand" -> "bud") id 8
    )
  }.await

  refresh("beer")
  blockUntilCount(2, "beer")

  "A Get request" should "retrieve a document by id" in {

    val resp = client.execute {
      get id 8 from "beer/lager"
    }.await
    assert("8" === resp.getId)
  }

  it should "retrieve a document asynchronously by id" in {

    val resp = client.execute {
      get id 8 from "beer/lager"
    }

    whenReady(resp) { result =>
      result.isExists should be(true)
      result.getId shouldBe "8"
    }
  }

  it should "retrieve a document asynchronously by id w/ source" in {

    val resp = client.execute {
      get id 8 from "beer/lager"
    }

    whenReady(resp) { result =>
      result.isExists should be(true)
      result.getId shouldBe "8"
      result.getSource should not be null
      result.getFields should have size 0
    }
  }

  it should "retrieve a document asynchronously by id w/o source" in {

    val resp = client.execute {
      get id 8 from "beer/lager" fetchSourceContext false
    }

    whenReady(resp) { result =>
      result.isExists should be(true)
      result.getId shouldBe "8"
      result.getSource should be(null)
      result.getFields should have size 0
    }
  }

  it should "retrieve a document asynchronously by id w/ name and w/o source" in {

    val resp = client.execute {
      get id 8 from "beer/lager" fields "name"
    }

    whenReady(resp) { result =>
      result.isExists should be(true)
      result.getId shouldBe "8"
      result.getSource should be(null)
      result.getFields should (contain key "name" and not contain key("brand"))
    }
  }

  it should "retrieve a document asynchronously by id w/ name and brand and source" in {

    val resp = client.execute {
      get id 4 from "beer/lager" fields "name" fetchSourceContext true
    }

    whenReady(resp) { result =>
      result.isExists should be(true)
      result.getId shouldBe "4"
      result.getSource should not be null
      result.getFields should (contain key "name" and not contain key("brand"))
    }
  }

  it should "not retrieve any documents w/ unknown id" in {

    val resp = client.execute {
      get id 1 from "beer/lager" fields "name" fetchSourceContext true
    }

    whenReady(resp) { result =>
      result.isExists should be(false)
    }
  }

  import scala.collection.JavaConverters._

  it should "retrieve multi value fields" in {
    val resp = client.execute {
      get id 4 from "beer/lager" fields "ingredients"
    }
    whenReady(resp) {
      result => println(result.getField("ingredients").getValues.asScala)
    }
  }

}

{'fraction_non_alphanumeric': 0.10203412073490814, 'fraction_numerical': 0.007217847769028871, 'mean_word_length': 2.6951515151515153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6434357', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1923, 'n_words': 623}