0

I need to read data from multiple indices of Elasticsearch. But all of these indices have the same data structure.

For example:

val df1 = spark.read.format("org.elasticsearch.spark.sql")
              .option("query", myquery)
              .option("pushdown", "true")
              .load("news_01/myitem")

val df2 = spark.read.format("org.elasticsearch.spark.sql")
              .option("query", myquery)
              .option("pushdown", "true")
              .load("news_02/myitem")

What happens if I get the array of index names ["news_01", "news_02"]?

How can I avoid creating df1, df2 as I do now?

1
  • You mean, you want to merge the data from two indices? Commented Apr 24, 2018 at 13:24

1 Answer 1

0

Given that ElasticSearch allows you to target multiple indices at the same time during a search request, you could do something like:

val df = spark.read.format("org.elasticsearch.spark.sql")
              .option("query", myquery)
              .option("pushdown", "true")
              .load("news_01,news_02")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.