shimamoto commented on a change in pull request #1180: [CALCITE-3023] Upgrade
to Elasticsearch 7.0.0
URL: https://github.com/apache/calcite/pull/1180#discussion_r285420257
##########
File path:
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java
##########
@@ -60,91 +57,74 @@
/**
* Allows schema to be instantiated from existing elastic search client.
- * This constructor is used in tests.
+ *
* @param client existing client instance
* @param mapper mapper for JSON (de)serialization
* @param index name of ES index
*/
public ElasticsearchSchema(RestClient client, ObjectMapper mapper, String
index) {
- this(client, mapper, index, null);
- }
-
- public ElasticsearchSchema(RestClient client, ObjectMapper mapper, String
index, String type) {
- this(client, mapper, index, type,
ElasticsearchTransport.DEFAULT_FETCH_SIZE);
+ this(client, mapper, index, ElasticsearchTransport.DEFAULT_FETCH_SIZE);
}
@VisibleForTesting
ElasticsearchSchema(RestClient client, ObjectMapper mapper,
- String index, String type,
- int fetchSize) {
+ String index, int fetchSize) {
super();
this.client = Objects.requireNonNull(client, "client");
this.mapper = Objects.requireNonNull(mapper, "mapper");
- this.index = Objects.requireNonNull(index, "index");
Preconditions.checkArgument(fetchSize > 0,
"invalid fetch size. Expected %s > 0", fetchSize);
this.fetchSize = fetchSize;
- if (type == null) {
+
+ if (index == null) {
try {
- this.tableMap = createTables(listTypesFromElastic());
+ this.tableMap = createTables(indicesFromElastic());
} catch (IOException e) {
- throw new UncheckedIOException("Couldn't get types for " + index, e);
+ throw new UncheckedIOException("Couldn't get indices", e);
}
} else {
- this.tableMap = createTables(Collections.singleton(type));
+ this.tableMap = createTables(Collections.singleton(index));
}
-
}
@Override protected Map<String, Table> getTableMap() {
return tableMap;
}
- private Map<String, Table> createTables(Iterable<String> types) {
+ private Map<String, Table> createTables(Iterable<String> indices) {
final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
- for (String type : types) {
+ for (String index : indices) {
final ElasticsearchTransport transport = new
ElasticsearchTransport(client, mapper,
- index, type, fetchSize);
- builder.put(type, new ElasticsearchTable(transport));
+ index, fetchSize);
+ builder.put(index, new ElasticsearchTable(transport));
}
return builder.build();
}
/**
- * Queries {@code _mapping} definition to automatically detect all types for
an index
+ * Queries {@code _alias} definition to automatically detect all indices
*
- * @return list of types associated with this index
+ * @return list of indices
* @throws IOException for any IO related issues
* @throws IllegalStateException if reply is not understood
*/
- private Set<String> listTypesFromElastic() throws IOException {
- final String endpoint = "/" + index + "/_mapping";
- final Response response = client.performRequest("GET", endpoint);
+ private Set<String> indicesFromElastic() throws IOException {
+ final String endpoint = "/_alias";
+ final Response response = client.performRequest(new Request("GET",
endpoint));
try (InputStream is = response.getEntity().getContent()) {
final JsonNode root = mapper.readTree(is);
- if (!root.isObject() || root.size() != 1) {
+ if (!root.isObject() || root.size() == 0) {
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services