2014-07-01 52 views
2

什么是使用java sdk获得index alias映射的最佳方式。如何获得索引别名映射

以下代码:

public MappingMetaData mapping() throws ApiException { 
    log.info("Calling mappings endpoint for index "); 
    ClusterState cs = client().admin().cluster().prepareState() 
      .setIndices("INDEX_NAME").execute().actionGet().getState(); 
    IndexMetaData imd = cs.getMetaData().index("INDEX_NAME"); 
    return imd.mapping("INDEX_NAME"); 
    } 

返回显示java.lang.NullPointerException。

如果使用的HTTP版本

http://ES_SERVER:9200/INDEX_NAME/INDEX_TYPE/_mapping 

而不是Java SDK它的工作原理确定,别名会自动扩展到真实的物理指标。

感谢您的帮助。

elasticsearch版本1.2.1

回答

0

,你可以这样做:

ClusterState state = client.admin().cluster().prepareState().get().getState(); 
    ImmutableOpenMap<String, MappingMetaData> mappings = state.getMetaData().index("your-index-name").getMappings(); 
    for (ObjectObjectCursor<String, MappingMetaData> mapping : mappings) { 
     Object o = JSONObject.toJSON(mapping.value.getSourceAsMap()); 
     System.out.println(o); 
    }