Skip to content

Commit 5455fc2

Browse files
committed
abstracting refresh setting outside of OSclient implementation
Signed-off-by: Dennis Toepker <[email protected]>
1 parent eba04be commit 5455fc2

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

spark-sql-application/src/main/scala/org/apache/spark/sql/FlintJobExecutor.scala

+7-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,13 @@ trait FlintJobExecutor {
394394
mapping: String): Either[String, Unit] = {
395395
try {
396396
logInfo(s"create $resultIndex")
397-
osClient.createIndex(resultIndex, mapping)
397+
val fastRefreshSettings =
398+
""" {
399+
| "auto_refresh": "true",
400+
| "refresh_interval": "1 Second",
401+
| }
402+
|""".stripMargin
403+
osClient.createIndex(resultIndex, mapping, fastRefreshSettings)
398404
logInfo(s"create $resultIndex successfully")
399405
Right(())
400406
} catch {

spark-sql-application/src/main/scala/org/apache/spark/sql/OSClient.scala

+4-9
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,20 @@ class OSClient(val flintOptions: FlintOptions) extends Logging {
6161
* the name of the index
6262
* @param mapping
6363
* the mapping of the index
64+
* @param settings
65+
* * the index settings as a JSON string
6466
* @return
6567
* use Either for representing success or failure. A Right value indicates success, while a
6668
* Left value indicates an error.
6769
*/
68-
def createIndex(osIndexName: String, mapping: String): Unit = {
70+
def createIndex(osIndexName: String, mapping: String, settings: String): Unit = {
6971
logInfo(s"create $osIndexName")
7072

7173
using(flintClient.createClient()) { client =>
7274
val request = new CreateIndexRequest(osIndexName)
73-
val fastRefreshSettings =
74-
""" {
75-
| "auto_refresh": "true",
76-
| "refresh_interval": "1 Second",
77-
| }
78-
|""".stripMargin
79-
8075
request
8176
.mapping(mapping, XContentType.JSON)
82-
.settings(fastRefreshSettings, XContentType.JSON)
77+
.settings(settings, XContentType.JSON)
8378

8479
try {
8580
client.createIndex(request, RequestOptions.DEFAULT)

0 commit comments

Comments
 (0)