3

I am new to scala, using alpakka-elasticsearch client to perform query with elastic search.

Single search query is working fine with below two ways which internally calls to _search url of elastic search:

val writeCustomIndex = ElasticsearchSource
 .typed[Book](
  indexName = "source",
  typeName = "_doc",
  query = """{"match_all": {}}"""
 )

OR

val readWithSearchParameters = ElasticsearchSource
.typed[TestDoc](
  indexName,
  Some(typeName),
  searchParams = Map(
  "query" -> """ {"match_all": {}} """,
  "_source" -> """ ["id", "a", "c"] """
  )

What I am looking for is to perform below multi query(_msearch) with this client.

url - http://localhost:9200/index1/_msearch?
request :
[
 {"query" : {"match_all" : {}}, "from" : 0, "size" : 1},
 {"index" : "index2"},
 {"query" : {"match_all" : {}}, "from" : 0, "size" : 2}
]

elastic client source : https://doc.akka.io/docs/alpakka/current/elasticsearch.html

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
RKP
  • 750
  • 2
  • 12
  • 23
  • 1
    I think you should merge separate sources (one for each search request) by something like https://doc.akka.io/docs/akka/current/stream/operators/Source-or-Flow/merge.html – Aleksey Isachenkov Jun 18 '19 at 09:32

1 Answers1

1

Have tried with one approach as per suggestion, where I have merged two sources.

Hope, this may help someone!

 var elasticRecord: Future[Seq[ElasticRecord]] = ElasticsearchSource
  .typed[ElasticRecord](
  indexName1,
  Some(typeName1),
  query1,
  settings = ElasticsearchSourceSettings()).map { message =>
  message.source
}.merge(ElasticsearchSource
  .typed[ElasticRecord](
  indexName2,
  Some(typeName2),
  query1,
  settings = ElasticsearchSourceSettings()).map { message =>
  message.source
}).runWith(Sink.seq)
RKP
  • 750
  • 2
  • 12
  • 23