Java Code Examples for org.elasticsearch.action.admin.indices.get.GetIndexResponse#getMappings()

The following examples show how to use org.elasticsearch.action.admin.indices.get.GetIndexResponse#getMappings() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Elasticsearch2Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    //----es scher error --
    Thread.currentThread().setName("getTable_001");
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example 2
Source File: Elasticsearch6Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    Thread.currentThread().setName("getTable_001"); //----es scher error --
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example 3
Source File: Elasticsearch5Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    Thread.currentThread().setName("getTable_001"); //----es scher error --
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example 4
Source File: ShowTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void showAll_atLeastOneIndexReturns() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
    String query = "show *";
    GetIndexResponse getIndexResponse = runShowQuery(query);
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = getIndexResponse.getMappings();
    Assert.assertTrue(mappings.size() >= 1);

}
 
Example 5
Source File: ShowTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void showIndex_onlyOneIndexReturn() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
    String query = "show "+ TEST_INDEX_ACCOUNT;
    GetIndexResponse getIndexResponse = runShowQuery(query);
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = getIndexResponse.getMappings();
    Assert.assertEquals(1, mappings.size());
    Assert.assertTrue(mappings.containsKey(TEST_INDEX_ACCOUNT));

}
 
Example 6
Source File: ShowTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void showIndex_onlyOneIndexReturWithMoreThanOneTypes() throws SqlParseException, SQLFeatureNotSupportedException {
    String query = "show " + TEST_INDEX + "*";
    GetIndexResponse getIndexResponse = runShowQuery(query);
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = getIndexResponse.getMappings();
    Assert.assertTrue(mappings.size()>1);
}
 
Example 7
Source File: ShowTest.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
@Test
public void showIndexType_onlyOneTypeReturn() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
    String query = String.format("show %s/account", TEST_INDEX_ACCOUNT);
    GetIndexResponse getIndexResponse = runShowQuery(query);
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = getIndexResponse.getMappings();
    ImmutableOpenMap<String, MappingMetadata> typeToData = mappings.get(TEST_INDEX_ACCOUNT);
    Assert.assertEquals(1,typeToData.size());
}