diff --git a/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/client/ElasticsearchClient.java b/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/client/ElasticsearchClient.java index 55caaf8fef42b..4740310c16788 100644 --- a/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/client/ElasticsearchClient.java +++ b/presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/client/ElasticsearchClient.java @@ -492,6 +492,10 @@ public IndexMetadata getIndexMetadata(String index) // Older versions of ElasticSearch supported multiple "type" mappings // for a given index. Newer versions support only one and don't // expose it in the document. Here we skip it if it's present. + + if (!mappings.elements().hasNext()) { + return new IndexMetadata(new IndexMetadata.ObjectType(ImmutableList.of())); + } mappings = mappings.elements().next(); } diff --git a/presto-elasticsearch/src/test/java/com/facebook/presto/elasticsearch/TestElasticsearchIntegrationSmokeTest.java b/presto-elasticsearch/src/test/java/com/facebook/presto/elasticsearch/TestElasticsearchIntegrationSmokeTest.java index fc15c6daf5d5e..d4ff79bcdd31e 100644 --- a/presto-elasticsearch/src/test/java/com/facebook/presto/elasticsearch/TestElasticsearchIntegrationSmokeTest.java +++ b/presto-elasticsearch/src/test/java/com/facebook/presto/elasticsearch/TestElasticsearchIntegrationSmokeTest.java @@ -805,4 +805,12 @@ private void createIndex(String indexName, @Language("JSON") String mapping) client.getLowLevelClient() .performRequest("PUT", "/" + indexName, ImmutableMap.of(), new NStringEntity(mapping, ContentType.APPLICATION_JSON)); } + + @Test + public void testEmptyIndexNoMappings() + throws IOException + { + client.getLowLevelClient().performRequest("PUT", "/emptyindex"); + assertQueryFails("SELECT * FROM emptyindex", "line 1:8: SELECT \\* not allowed from relation that has no columns"); + } }