Skip to content

Commit

Permalink
Add support for reindex conflicts field (#2447)
Browse files Browse the repository at this point in the history
* Add support for reindex conflicts field

* Needs to be top level field

* Add test
  • Loading branch information
dragisak committed Jun 9, 2021
1 parent ed015a5 commit 57432c5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ case class ReindexRequest(sourceIndexes: Indexes,
timeout: Option[FiniteDuration] = None,
retryBackoffInitialTime: Option[FiniteDuration] = None,
shouldStoreResult: Option[Boolean] = None,
proceedOnConflicts: Option[Boolean] = None,
remoteHost: Option[String] = None,
remoteUser: Option[String] = None,
remotePass: Option[String] = None,
Expand Down Expand Up @@ -58,6 +59,9 @@ case class ReindexRequest(sourceIndexes: Indexes,
def shouldStoreResult(shouldStoreResult: Boolean): ReindexRequest =
copy(shouldStoreResult = shouldStoreResult.some)

def proceedOnConflicts(proceedOnConflicts: Boolean): ReindexRequest =
copy(proceedOnConflicts = proceedOnConflicts.some)

def script(script: Script): ReindexRequest = copy(script = script.some)

def scroll(scroll: String): ReindexRequest = copy(scroll = scroll.some)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ object ReindexBuilderFn {
def apply(request: ReindexRequest): XContentBuilder = {
val builder = XContentFactory.obj()

request.proceedOnConflicts.foreach {
case true => builder.field("conflicts", "proceed")
case false => builder.field("conflicts", "abort")
}

request.size.foreach(builder.field("size", _))

request.script.foreach { script =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ class ReindexTest extends AnyWordSpec with Matchers with DockerTests {
search("reindextarget")
}.await.result.hits.hits.flatMap(_.sourceAsMap.get("scripted")) shouldBe Array(42, 42, 42)
}
"support proceed parameter" in {
deleteIdx("reindextarget")
createIdx("reindextarget")

client.execute {
reindex("reindex", "reindextarget").proceedOnConflicts(true).refresh(RefreshPolicy.IMMEDIATE)
}.await.result.left.get.created shouldBe 3

deleteIdx("reindextarget")
createIdx("reindextarget")

client.execute {
reindex("reindex", "reindextarget").proceedOnConflicts(false).refresh(RefreshPolicy.IMMEDIATE)
}.await.result.left.get.created shouldBe 3
}
"support multiple sources" in {

deleteIdx("reindextarget")
Expand Down

0 comments on commit 57432c5

Please sign in to comment.