From ab689c10462e4744842b7341cdcabbd64b6e41ea Mon Sep 17 00:00:00 2001 From: Chuck Che <cche@sumologic.com> Date: Sun, 21 May 2017 20:17:14 -0700 Subject: [PATCH 1/5] update elasticsearch and lucene version --- elasticsearch-core/pom.xml | 6 +++--- elasticsearch-test/pom.xml | 14 ++++---------- .../ElasticsearchIntegrationTest.scala | 8 ++++---- pom.xml | 2 ++ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/elasticsearch-core/pom.xml b/elasticsearch-core/pom.xml index be4adcf..2bb4388 100644 --- a/elasticsearch-core/pom.xml +++ b/elasticsearch-core/pom.xml @@ -69,21 +69,21 @@ <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> - <version>4.10.4</version> + <version>${lucene.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-analyzers-common</artifactId> - <version>4.10.4</version> + <version>${lucene.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> - <version>1.6.2</version> + <version>${elasticsearch.version}</version> <scope>test</scope> </dependency> </dependencies> diff --git a/elasticsearch-test/pom.xml b/elasticsearch-test/pom.xml index 7866d15..04a9a05 100644 --- a/elasticsearch-test/pom.xml +++ b/elasticsearch-test/pom.xml @@ -27,35 +27,29 @@ <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> - <version>4.10.4</version> + <version>${lucene.version}</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-analyzers-common</artifactId> - <version>4.10.4</version> + <version>${lucene.version}</version> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> - <version>1.6.2</version> + <version>${elasticsearch.version}</version> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> - <version>1.6.2</version> + <version>${elasticsearch.version}</version> <type>test-jar</type> </dependency> <!-- Non-Sumo Test Dependencies. --> - <dependency> - <groupId>org.apache.lucene</groupId> - <artifactId>lucene-test-framework</artifactId> - <version>4.10.4</version> - </dependency> - <dependency> <groupId>org.scalatest</groupId> <artifactId>scalatest_${scala.version.major}</artifactId> diff --git a/elasticsearch-test/src/main/scala/com/sumologic/elasticsearch_test/ElasticsearchIntegrationTest.scala b/elasticsearch-test/src/main/scala/com/sumologic/elasticsearch_test/ElasticsearchIntegrationTest.scala index 0453a03..5060d42 100644 --- a/elasticsearch-test/src/main/scala/com/sumologic/elasticsearch_test/ElasticsearchIntegrationTest.scala +++ b/elasticsearch-test/src/main/scala/com/sumologic/elasticsearch_test/ElasticsearchIntegrationTest.scala @@ -22,7 +22,7 @@ import java.io.File import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest import org.elasticsearch.client.transport.TransportClient -import org.elasticsearch.common.settings.ImmutableSettings +import org.elasticsearch.common.settings.Settings import org.elasticsearch.common.transport.{InetSocketTransportAddress, LocalTransportAddress} import org.elasticsearch.node.NodeBuilder import org.scalatest.{BeforeAndAfterAll, Suite} @@ -71,10 +71,10 @@ trait ElasticsearchIntegrationTest extends BeforeAndAfterAll { object ElasticsearchIntegrationTest { private val r = new Random() - private lazy val esNodeSettings = ImmutableSettings.settingsBuilder().put("path.data", createTempDir("elasticsearch-test")).build() + private lazy val esNodeSettings = Settings.builder().put("path.home", createTempDir("elasticsearch-test")).build() private lazy val esNode = NodeBuilder.nodeBuilder().local(true).settings(esNodeSettings).node() - private lazy val settings = ImmutableSettings.settingsBuilder().put("node.local", "true").build() - lazy val client = new TransportClient(settings).addTransportAddress(new LocalTransportAddress("1")) + private lazy val settings = Settings.builder().put("node.local", "true").build() + lazy val client = esNode.client() lazy val globalEndpoint = { val nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get() val nodeAddress = diff --git a/pom.xml b/pom.xml index 404a40f..ec98c1b 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,8 @@ <properties> <scala.version.major>2.11</scala.version.major> <akka.version>2.3.11</akka.version> + <elasticsearch.version>2.3.0</elasticsearch.version> + <lucene.version>5.5.0</lucene.version> </properties> <dependencies> <dependency> From b8a727ef23863dd9822c4049da4be90e717efce9 Mon Sep 17 00:00:00 2001 From: Chuck Che <cche@sumologic.com> Date: Sun, 21 May 2017 20:20:38 -0700 Subject: [PATCH 2/5] fix breaking change in index already exists exception --- .../elasticsearch/restlastic/RestlasticSearchClient.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala b/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala index 4889f61..a578a72 100644 --- a/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala +++ b/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala @@ -160,7 +160,7 @@ class RestlasticSearchClient(endpointProvider: EndpointProvider, signer: Option[ def createIndex(index: Index, settings: Option[IndexSetting] = None): Future[RawJsonResponse] = { implicit val ec = indexExecutionCtx runEsCommand(CreateIndex(settings), s"/${index.name}").recover { - case ElasticErrorResponse(message, status) if message contains "IndexAlreadyExistsException" => + case ElasticErrorResponse(message, status) if message contains "index_already_exists_exception" => throw new IndexAlreadyExistsException(message) } } From ec681082408aaefee4d7432d15ad4ba4aad00d08 Mon Sep 17 00:00:00 2001 From: Chuck Che <cche@sumologic.com> Date: Sun, 21 May 2017 20:32:50 -0700 Subject: [PATCH 3/5] fix breaking change in error response --- .../elasticsearch/restlastic/RestlasticSearchClient.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala b/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala index a578a72..c9a5903 100644 --- a/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala +++ b/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala @@ -257,9 +257,10 @@ object RestlasticSearchClient { case class ScrollId(id: String) case class BulkIndexResponse(items: List[Map[String, BulkItem]]) - case class BulkItem(_index: String, _type: String, _id: String, status: Int, error: Option[String]) { + case class BulkIndexError(reason: String) + case class BulkItem(_index: String, _type: String, _id: String, status: Int, error: Option[BulkIndexError]) { def created = status > 200 && status < 299 && !alreadyExists - def alreadyExists = error.exists(_.contains("DocumentAlreadyExists")) + def alreadyExists = error.exists(_.reason.contains("document already exists")) def success = status >= 200 && status <= 299 } From 18e7630229a64d15459a1e889f6b2d4088381fe1 Mon Sep 17 00:00:00 2001 From: Chuck Che <cche@sumologic.com> Date: Mon, 22 May 2017 07:21:23 -0700 Subject: [PATCH 4/5] fix breaking changes, delete by query only as plugin --- .../restlastic/RestlasticSearchClient.scala | 9 +++++++-- .../restlastic/RestlasticSearchClientTest.scala | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala b/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala index c9a5903..121dcb1 100644 --- a/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala +++ b/elasticsearch-core/src/main/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClient.scala @@ -170,9 +170,14 @@ class RestlasticSearchClient(endpointProvider: EndpointProvider, signer: Option[ runEsCommand(EmptyObject, s"/${index.name}", DELETE) } - def deleteDocument(index: Index, tpe: Type, query: QueryRoot): Future[RawJsonResponse] = { + def deleteDocument(index: Index, tpe: Type, deleteQuery: QueryRoot, pluginEnabled: Boolean = false): Future[RawJsonResponse] = { implicit val ec = indexExecutionCtx - runEsCommand(query, s"/${index.name}/${tpe.name}/_query", DELETE) + if (pluginEnabled) { + runEsCommand(deleteQuery, s"/${index.name}/${tpe.name}/_query", DELETE) + } else { + val documents = Await.result(query(index, tpe, deleteQuery, rawJsonStr = false), 10.seconds).rawSearchResponse.hits.hits.map(_._id) + bulkDelete(index, tpe, documents.map(Document(_, Map()))).map(res => RawJsonResponse(res.toString)) + } } def startScrollRequest(index: Index, tpe: Type, query: QueryRoot, resultWindow: String = "1m"): Future[ScrollId] = { diff --git a/elasticsearch-core/src/test/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClientTest.scala b/elasticsearch-core/src/test/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClientTest.scala index fdfd16b..223f477 100644 --- a/elasticsearch-core/src/test/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClientTest.scala +++ b/elasticsearch-core/src/test/scala/com/sumologic/elasticsearch/restlastic/RestlasticSearchClientTest.scala @@ -275,6 +275,7 @@ class RestlasticSearchClientTest extends WordSpec with Matchers with ScalaFuture } val delFut = restClient.deleteDocument(index, tpe, new QueryRoot(TermQuery("text7", "here7"))) Await.result(delFut, 10.seconds) + refresh() val resFut1 = restClient.query(index, tpe, new QueryRoot(TermQuery("text7", "here7"))) whenReady(resFut1) { res => res.sourceAsMap.toList should be(List()) From ef483621bc8bc6c3ca2fed038bd983f6280ffd92 Mon Sep 17 00:00:00 2001 From: Chuck Che <cche@sumologic.com> Date: Tue, 23 May 2017 10:35:55 -0700 Subject: [PATCH 5/5] update to the highest version in 2.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ec98c1b..a52de50 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ <properties> <scala.version.major>2.11</scala.version.major> <akka.version>2.3.11</akka.version> - <elasticsearch.version>2.3.0</elasticsearch.version> + <elasticsearch.version>2.3.5</elasticsearch.version> <lucene.version>5.5.0</lucene.version> </properties> <dependencies>