-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CC-1385: Enhance connector to use text type with ES 5+ #169
Changes from 4 commits
64bb440
93de790
e064acd
9446aa4
bc24949
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,11 +39,16 @@ | |
</scm> | ||
|
||
<properties> | ||
<!-- | ||
<es.version>6.0.0</es.version> | ||
<lucene.version>7.0.1</lucene.version> | ||
<es.version>5.0.0</es.version> | ||
<lucene.version>6.2.0</lucene.version> | ||
--> | ||
<es.version>2.4.1</es.version> | ||
<lucene.version>5.5.2</lucene.version> | ||
<jna.version>4.2.1</jna.version> | ||
<hamcrest.version>2.0.0.0</hamcrest.version> | ||
<jest.version>2.0.0</jest.version> | ||
<hamcrest.version>1.3</hamcrest.version> | ||
<jest.version>2.4.0</jest.version> | ||
<confluent.maven.repo>http://packages.confluent.io/maven/</confluent.maven.repo> | ||
</properties> | ||
|
||
|
@@ -71,15 +76,9 @@ | |
<artifactId>jest</artifactId> | ||
<version>${jest.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.java.dev.jna</groupId> | ||
<artifactId>jna</artifactId> | ||
<version>${jna.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-junit</artifactId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<version>${hamcrest.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
@@ -101,13 +100,41 @@ | |
<version>${lucene.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- For ES 2.x --> | ||
<dependency> | ||
<groupId>org.elasticsearch</groupId> | ||
<artifactId>elasticsearch</artifactId> | ||
<version>${es.version}</version> | ||
<scope>test</scope> | ||
<type>test-jar</type> | ||
</dependency> | ||
<!-- For ES 5.x (requires Java 8) --> | ||
<!-- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'm assuming the commented out section will be removed before merging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to leave this in as when we move to Java 8 these will come back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, considering we'll want to change this in a few months, I think it's fine to keep as-is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we will have to change a bunch of things to move to Java 8, so it might be fine to delete the commented sections for now. And then tackle the Java 8 independently when the time comes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, these are the only changes required for Java 8. However, I'll remove these comments for now. |
||
<dependency> | ||
<groupId>org.elasticsearch.test</groupId> | ||
<artifactId>framework</artifactId> | ||
<version>${es.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.elasticsearch.plugin</groupId> | ||
<artifactId>transport-netty4-client</artifactId> | ||
<version>${es.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-api</artifactId> | ||
<version>2.7</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<version>2.7</version> | ||
<scope>test</scope> | ||
</dependency> | ||
--> | ||
<dependency> | ||
<groupId>org.elasticsearch</groupId> | ||
<artifactId>elasticsearch</artifactId> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* Copyright 2018 Confluent Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
**/ | ||
|
||
package io.confluent.connect.elasticsearch; | ||
|
||
import com.google.gson.JsonObject; | ||
import io.confluent.connect.elasticsearch.bulk.BulkRequest; | ||
import io.confluent.connect.elasticsearch.bulk.BulkResponse; | ||
import org.apache.kafka.connect.data.Schema; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public interface ElasticsearchClient extends AutoCloseable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
|
||
enum Version { | ||
ES_V1, ES_V2, ES_V5, ES_V6 | ||
} | ||
|
||
/** | ||
* Gets the Elasticsearch version. | ||
* | ||
* @return the version, not null | ||
*/ | ||
Version getVersion(); | ||
|
||
/** | ||
* Creates indices. | ||
* | ||
* @param indices the set of index names to create, not null | ||
*/ | ||
void createIndices(Set<String> indices); | ||
|
||
/** | ||
* Creates an explicit mapping. | ||
* | ||
* @param index the index to write | ||
* @param type the type for which to create the mapping | ||
* @param schema the schema used to infer the mapping | ||
* @throws IOException if the client cannot execute the request | ||
*/ | ||
void createMapping(String index, String type, Schema schema) throws IOException; | ||
|
||
/** | ||
* Gets the JSON mapping for the given index and type. Returns {@code null} if it does not exist. | ||
* | ||
* @param index the index | ||
* @param type the type | ||
* @throws IOException if the client cannot execute the request | ||
*/ | ||
JsonObject getMapping(String index, String type) throws IOException; | ||
|
||
/** | ||
* Creates a bulk request for the list of {@link IndexableRecord} records. | ||
* | ||
* @param batch the list of records | ||
* @return the bulk request | ||
*/ | ||
BulkRequest createBulkRequest(List<IndexableRecord> batch); | ||
|
||
/** | ||
* Executes a bulk action. | ||
* | ||
* @param bulk the bulk request | ||
* @return the bulk response | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add it. |
||
* @throws IOException if the client cannot execute the request | ||
*/ | ||
BulkResponse executeBulk(BulkRequest bulk) throws IOException; | ||
|
||
/** | ||
* Executes a search. | ||
* | ||
* @param query the search query | ||
* @param index the index to search | ||
* @param type the type to search | ||
* @return the search result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add it. |
||
* @throws IOException if the client cannot execute the request | ||
*/ | ||
JsonObject search(String query, String index, String type) throws IOException; | ||
|
||
/** | ||
* Shuts down the client. | ||
*/ | ||
void close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I overrode it to not throw Exception |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,6 @@ | |
|
||
package io.confluent.connect.elasticsearch; | ||
|
||
import org.apache.kafka.connect.data.Schema.Type; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ElasticsearchSinkConnectorConstants { | ||
public static final String MAP_KEY = "key"; | ||
public static final String MAP_VALUE = "value"; | ||
|
@@ -34,19 +29,6 @@ public class ElasticsearchSinkConnectorConstants { | |
public static final String FLOAT_TYPE = "float"; | ||
public static final String DOUBLE_TYPE = "double"; | ||
public static final String STRING_TYPE = "string"; | ||
public static final String TEXT_TYPE = "text"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ES also has a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add it now as a placeholder. |
||
public static final String DATE_TYPE = "date"; | ||
|
||
static final Map<Type, String> TYPES = new HashMap<>(); | ||
|
||
static { | ||
TYPES.put(Type.BOOLEAN, BOOLEAN_TYPE); | ||
TYPES.put(Type.INT8, BYTE_TYPE); | ||
TYPES.put(Type.INT16, SHORT_TYPE); | ||
TYPES.put(Type.INT32, INTEGER_TYPE); | ||
TYPES.put(Type.INT64, LONG_TYPE); | ||
TYPES.put(Type.FLOAT32, FLOAT_TYPE); | ||
TYPES.put(Type.FLOAT64, DOUBLE_TYPE); | ||
TYPES.put(Type.STRING, STRING_TYPE); | ||
TYPES.put(Type.BYTES, BINARY_TYPE); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we delete this section instead of leaving it commented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove.