wuyunfeng commented on a change in pull request #3454: URL: https://github.com/apache/incubator-doris/pull/3454#discussion_r440585954
########## File path: fe/src/main/java/org/apache/doris/external/elasticsearch/EsIndexState.java ########## @@ -44,7 +47,43 @@ public EsIndexState(String indexName) { this.partitionDesc = null; this.partitionKey = null; } - + + /** + * Parse shardRoutings from the json + * @param indexName indexName(alias or really name) + * @param shardLocation the return value of _search_shards + * @return shardRoutings is used for searching + */ + public static EsIndexState fromShardLocation(String indexName, String shardLocation) { + EsIndexState indexState = new EsIndexState(indexName); + JSONObject jsonObject = new JSONObject(shardLocation); + JSONObject nodesMap = jsonObject.getJSONObject("nodes"); + JSONArray shards = jsonObject.getJSONArray("shards"); + int length = shards.length(); + for (int i = 0; i < length; i++) { + List<EsShardRouting> singleShardRouting = Lists.newArrayList(); + JSONArray shardsArray = shards.getJSONArray(i); + int arrayLength = shardsArray.length(); + for (int j = 0; j < arrayLength; j++) { + JSONObject shard = shardsArray.getJSONObject(j); + String shardState = shard.getString("state"); + if ("STARTED".equalsIgnoreCase(shardState) || "RELOCATING".equalsIgnoreCase(shardState)) { + try { + singleShardRouting.add(EsShardRouting.parseShardRoutingV55(shardState, String.valueOf(i), shard, nodesMap)); Review comment: should not appear such xxxV55 ########## File path: fe/src/main/java/org/apache/doris/external/elasticsearch/EsIndexState.java ########## @@ -44,7 +47,43 @@ public EsIndexState(String indexName) { this.partitionDesc = null; this.partitionKey = null; } - + + /** + * Parse shardRoutings from the json + * @param indexName indexName(alias or really name) + * @param shardLocation the return value of _search_shards + * @return shardRoutings is used for searching + */ + public static EsIndexState fromShardLocation(String indexName, String shardLocation) { + EsIndexState indexState = new EsIndexState(indexName); + JSONObject jsonObject = new JSONObject(shardLocation); + JSONObject nodesMap = jsonObject.getJSONObject("nodes"); + JSONArray shards = jsonObject.getJSONArray("shards"); + int length = shards.length(); + for (int i = 0; i < length; i++) { + List<EsShardRouting> singleShardRouting = Lists.newArrayList(); + JSONArray shardsArray = shards.getJSONArray(i); + int arrayLength = shardsArray.length(); + for (int j = 0; j < arrayLength; j++) { + JSONObject shard = shardsArray.getJSONObject(j); + String shardState = shard.getString("state"); + if ("STARTED".equalsIgnoreCase(shardState) || "RELOCATING".equalsIgnoreCase(shardState)) { + try { + singleShardRouting.add(EsShardRouting.parseShardRoutingV55(shardState, String.valueOf(i), shard, nodesMap)); + } catch (Exception e) { + LOG.info( Review comment: You should throw this exception, because EsStateStore would store the lastException for displaying error to user ########## File path: fe/src/main/java/org/apache/doris/external/elasticsearch/EsIndexState.java ########## @@ -44,7 +47,43 @@ public EsIndexState(String indexName) { this.partitionDesc = null; this.partitionKey = null; } - + + /** + * Parse shardRoutings from the json + * @param indexName indexName(alias or really name) + * @param shardLocation the return value of _search_shards + * @return shardRoutings is used for searching + */ + public static EsIndexState fromShardLocation(String indexName, String shardLocation) { Review comment: ```suggestion public static EsShardPartitions findShardPartitions(String indexName, String shardLocation) { ``` ########## File path: fe/src/main/java/org/apache/doris/external/elasticsearch/EsIndexState.java ########## @@ -44,7 +47,43 @@ public EsIndexState(String indexName) { this.partitionDesc = null; this.partitionKey = null; } - + + /** + * Parse shardRoutings from the json + * @param indexName indexName(alias or really name) + * @param shardLocation the return value of _search_shards + * @return shardRoutings is used for searching + */ + public static EsIndexState fromShardLocation(String indexName, String shardLocation) { Review comment: shardLocation maybe not suitable for this function parameter. ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org