vincent chou
vincent chou

Reputation: 91

elastic4s query document with list of keys

I'm trying to retrieve records from elastic search repo. And my method looks like this

def findPartialFieldWithId(id: String, path: String): Future[SearchResponse] = {
client.execute {
    search in IndexType query {
    termQuery("_id", id)
    } sourceInclude (path)
}

}

But if id is a list of String instead of String, what DSL should i use?

tried to read elastic4s docs and test cases, but still can't make it work

Upvotes: 1

Views: 535

Answers (1)

sksamuel
sksamuel

Reputation: 16387

termsQuery is the way to go:

def findPartialFieldWithId(ids: Seq[String], path: String): Future[SearchResponse] = {
  import scala.collection.JavaConverters._
  client.execute {
    search in IndexType query {
      termsQuery("_id", ids: _* )
    } sourceInclude (path)
  }
}

Upvotes: 1

Related Questions