자바 코드 분석 elasticsearch 색인 데이터

10194 단어 esutil
\#요청 URL:
private static final String URL_ALL_INDEX = "http://esHost:9200/_cat/indices?v";
\#step 2:색인 데이터 가 져 오기  responseBody  후 해석
package com.dzh.extra.utils;

import com.dzh.extra.consts.ConstNumber;
import com.dzh.extra.consts.ConstStringCommon;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class EsUtil {

    private static final String SPLIT_REGEX = "pri.store.size";

    /**
     *   ES    
     */
    public static List> getAllIndex(String responseBody) {
        List> listAll = new ArrayList<>();
        //     
        String[] splitString = responseBody.split(SPLIT_REGEX, ConstNumber.TWO);
        //     
        if (StringUtil.isBlank(splitString[1])){
            return listAll;
        }
        String[] splitBodyString = splitString[1].split(ConstStringCommon.NEW_LINE, ConstNumber.SIX_THOUSAND);
        List splitBody = Arrays.asList(splitBodyString);
        //      
        List listElement = null;
        for (int i = 0; i < splitBody.size(); i++) {
            String[] split = splitBody.get(i).split(ConstStringCommon.BLANK_STRING, ConstNumber.SIX_THOUSAND);
            List splitBodyElement = Arrays.asList(split);
            if (CollectionUtil.isNotEmpty(splitBodyElement)){
                listElement = new ArrayList<>();
                for (String s : splitBodyElement) {
                    if (StringUtil.isNotBlank(s)){
                        listElement.add(s);
                    }
                }
            }
            if (CollectionUtil.isNotEmpty(listElement))
                listAll.add(listElement);
        }
        return listAll;
    }
}
package com.dzh.extra.consts;

public class ConstStringCommon {

    public static final String NEW_LINE = "
"; public static final String COLON = ":"; public static final String SPILT_LINE = ","; public static final String SLASH = "/"; public static final String EMPTY_STRING = ""; public static final String BLANK_STRING = " "; public static final String CHARSET_NAME_ISO = "ISO-8859-1"; public static final String CHARSET_NAME_UTF8 = "UTF-8"; public static final String CHARSET_NAME_GB = "GB2312"; public static final String TRUE = "true"; public static final String FALSE = "false"; }
package com.dzh.extra.consts;

public class ConstNumber {

    public static final Integer ZERO = 0;

    public static final Integer TWO = 2;

    public static final Integer TEN = 10;

    public static final Integer SIXTEEN = 16;

    public static final Integer THOUSAND = 1000;

    public static final Integer SIX_THOUSAND = 6000;

    public static final Integer TWELVE_THOUSAND = 12000;

    public static final Integer HUNDRED_THOUSAND = 100000;

}

#  뒤에 도 맵 으로 바 꿀 수 있어 요.

좋은 웹페이지 즐겨찾기