'types'에 해당되는 글 3건

  1. 2020.07.13 [AWS] DescribeInstanceTypes from Java
  2. 2013.04.16 [elasticsearch] Mapping - Array/Object/Nested Type
  3. 2013.04.16 [elasticsearch] Java API : mapping property.

[AWS] DescribeInstanceTypes from Java

Cloud&Container/AWS 2020. 7. 13. 18:06

본 API 가 삭제 되었기 때문에 그냥 아래와 같이 단순하게 구성해 보았습니다.

 

@Service
@Log4j2
@RequiredArgsConstructor
public class Ec2Service {

  public ResponseEntity<String> describeInstanceTypes() {
    ProcessBuilder builder = new ProcessBuilder();
    String instances = "{}";

    try {
      builder.command("bash", "-c", "aws ec2 describe-instance-types");
      Process process = builder.start();

      instances = new BufferedReader(
        new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)).lines()
        .collect(Collectors.joining("\n"));

      int exitCode = process.waitFor();

      JSONObject jsonObject = new JSONObject(instances);
      JSONArray jsonArray = jsonObject.getJSONArray("InstanceTypes");
      JSONArray sortedJsonArray = new JSONArray();
      List list = new ArrayList();

      for(int i = 0; i < jsonArray.length(); i++) {
        list.add(jsonArray.getJSONObject(i));
      }

      Collections.sort(list, new Comparator<JSONObject>() {

        @Override
        public int compare(JSONObject a, JSONObject b) {
          String source = new String();
          String target = new String();

          try {
            source = (String)a.get("InstanceType");
            target = (String)b.get("InstanceType");
          } catch(Exception e) {
          }

          return source.compareTo(target);
        }
      });

      for(int i = 0; i < jsonArray.length(); i++) {
        sortedJsonArray.put(list.get(i));
      }

      instances = "{\"InstanceTypes\": " +sortedJsonArray.toString()+ "}";
    } catch(Exception e) {
      e.printStackTrace();
    }

    return ResponseEntity.ok(instances);
  }
}

 

코드 자체는 AWS CLI 를 ProcessBuilder 를 이용해서 외부 파일을 실행 시켜 데이터를 받아와서 처리 하는 내용입니다.

AWS CLI 로 데이터를 가져 오게 되면 정렬이 안된 상태로 데이터가 넘어 와서 별도 sort 기능 구현이 필요 합니다.

그냥 CLI 에서도 JSON Sort 옵션 하나 넣어 주면 좋았을 걸 아쉽더라고요.

 

근데 왜 이 API 를 없앴는지 차암....

 

1.x 에서 삭제 되어서 2.x 로 변경해서 사용 하시면 됩니다.

    Ec2Client ec2Client = Ec2Client.builder().build();
    DescribeInstanceTypesRequest request = DescribeInstanceTypesRequest.builder()
      .maxResults(100)
      .build();

    DescribeInstanceTypesResponse response = ec2Client.describeInstanceTypes(request);
    log.debug("{}", response.instanceTypes());

한번에 100개 씩 밖에 못 가져 오기 때문에 nextToken 으로 끝까지 요청 하셔야 합니다.

:

[elasticsearch] Mapping - Array/Object/Nested Type

Elastic/Elasticsearch 2013. 4. 16. 12:04

본 문서는 개인적인 테스트와 elasticsearch.org 그리고 community 등을 참고해서 작성된 것이며,

정보 교환이 목적입니다.


잘못된 부분에 대해서는 지적 부탁 드립니다.

(예시 코드는 성능 및 보안 검증이 되지 않았습니다.)



[elasticsearch 리뷰]

원문 링크

http://www.elasticsearch.org/guide/reference/mapping/

http://www.elasticsearch.org/guide/reference/mapping/array-type/

http://www.elasticsearch.org/guide/reference/mapping/object-type/

http://www.elasticsearch.org/guide/reference/mapping/nested-type/


원문 예제가 잘 나와 있어 그대로 사용 합니다.


[Document]

"tweet" : { "message" : "some arrays in this tweet...", "tags" : ["elasticsearch", "wow"], "lists" : [ { "name" : "prog_list", "description" : "programming list" }, { "name" : "cool_list", "description" : "cool stuff list" } ] } 


[Mapping]

"tweet" : { "properties" : { "message" : {"type" : "string"}, "tags" : {"type" : "string", "index_name" : "tag"}, "lists" : { "properties" : { "name" : {"type" : "string"}, "description" : {"type" : "string"} } } } } 



[설명]

- elasticsearch 가 지원 하는 장점 중 하나 입니다.

- mapping 정보를 보면 문서 안에 sub 문서를 만들어 넣을 수 있습니다.

- _parent field 의 경우 index type 에 대한 parent 구조를 만들 수 있다고 하면 이건 document 자체에 parent-child 구조를 만들수 있습니다.

- mapping 에서 사용하는 index_name 의 경우 이런 array type 에 대해서 색인 시 field 명을 정의 할 수가 있습니다.

- nested loop 구조를 요구하는 문서가 있을 경우 잘 활용 하시면 좋습니다.

- 예를 들면 대화방이 있고 대화방안에는 여러 사람들이 나눈 대화 목록이있을 경우

"chat_room" : {

    "properties" : {

        "room_id" : {.....},

        ........

        "chat_lists" : {

            "properties" : {

                "chat_id" : {....},

                "sender" : {....},

                "receiver" : {....},

                "message" : {....)

            }

        }

    }

}

    . 이와 같은 구조로 생성을 할 수도 있습니다.



[Object/Nested]

- 이 두가지 type 도 array 와 유사 합니다.

- array 의 경우 [] 이와 같이 사용했다면, object 는 {} 을 사용하게 됩니다.

- nested 타입은 정의한 field 형식의 집합을 구성하게 됩니다. object 로 정의한 형식이 있다면 이것을 여러개의 집합으로 구성을 하게 됩니다.

아래 원문에 나온 예제를 보시면 쉽게 이해가 됩니다.


[Object 예제]

"person" : { "properties" : { "name1" : { "type" : "object", "path" : "just_name", "properties" : { "first1" : {"type" : "string"}, "last1" : {"type" : "string", "index_name" : "i_last_1"} } }, "name2" : { "type" : "object", "path" : "full", "properties" : { "first2" : {"type" : "string"}, "last2" : {"type" : "string", "index_name" : "i_last_2"} } } } } 

- path 는 두가지 옵션을 갖습니다.

    . just_name 과 full

    . just_name 의 경우 mapping 에서 정의한 index_name 을 사용하게 되며

    . full 의 경우 mapping 에서 정의한 full name 을 사용하게 됩니다.

- 즉 원문에 나온 결과를 보시면 이해가 쉽습니다.

JSON NameDocument Field Name
name1/first1first1
name1/last1i_last_1
name2/first2name2.first2
name2/last2name2.i_last_2


[Nested 예제]

{
    "type1" : {
        "properties" : {
            "obj1" : {
                "type" : "nested"
            }
        }
    }
}

- 위 예제에서는 "obj1" 내부 field 정의가 빠져 있으나 설정이 가능 합니다.

- 아래와 같이 하시면 됩니다.


"obj1" : {

    "type" : "nested",

    "properties" : {

        "first_name" : { "type" : "string", ....},

        "last_name" : { "type" : "string", ....}

        ......

    }

}



:

[elasticsearch] Java API : mapping property.

Elastic/Elasticsearch 2013. 4. 16. 10:57

본 문서는 개인적인 테스트와 elasticsearch.org 그리고 community 등을 참고해서 작성된 것이며,

정보 교환이 목적입니다.


잘못된 부분에 대해서는 지적 부탁 드립니다.

(예시 코드는 성능 및 보안 검증이 되지 않았습니다.)



[elasticsearch java api 리뷰]

원문 링크

http://www.elasticsearch.org/guide/reference/mapping/


이번 문서는 Java API에서도 제공하고 있는 mapping 관련 설정 값들 입니다.

자세한 설명은 원문의 Fields 와 Types 부분은 꼭 한번 씩 보시기 바랍니다.


[Mapping Template Sample]

    "mapping" : {

        "TYPE_NAME" : {

            "analyzer" : "standard",

            "index_analyzer" : "stadnard",

            "search_analyzer" : "standard",

            "_id" : {

                "index" : "not_analyzed",

                "store" : "yes",

                "path" : "FIELD_NAME"

            },

            "_type" : {

                "index" : "not_analyzed",

                "store" : "yes"

            },

            "_source" : {

                "enabled" : "false"

            },

            "_all" : {

                "enabled" : "false"

            },

            "_boost" : {

                "name" : "_boost",

                "null_value" : 1.0

            },

            "_parent" : {

                "type" : "PARENT_TYPE_NAME"

            },

            "_routing" : {

                "required" : true,

                "path" : "TYPE_NAME.FIELD_NAME"

            },

            "_timestamp" : {

                "enabled" : true,

                "path" : "DATE_FIELD_NAME",

                "format" : "dateOptionalTime"

            },

            "properties" : {

                "FIELD_NAME" : {

                    "type" : "string",

                    "index_name" : ,

                    "store" : ,

                    "index" : ,

                    "term_vector" : ,

                    "boost" : ,

                    "null_value" : ,

                    "omit_norms" : ,

                    "omit_term_freq_and_positions" : ,

                    "index_options" : ,

                    "analyzer" : ,

                    "index_analyzer" : ,

                    "search_analyzer" : ,

                    "include_in_all" : ,

                    "ignore_above" : ,

                    "position_offset_gap" : 

                },

                "FIELD_NAME" : {

                    "type" : "float, double, byte, short, integer, and long",

                    "index_name" : ,

                    "store" : ,

                    "index" : ,

                    "precision_step" : ,

                    "null_value" : ,

                    "boost" : ,

                    "include_in_all" : ,

                    "ignore_malformed" :

                },

                "FIELD_NAME" : {

                    "type" : "date",

                    "index_name" : ,

                    "format" : ,

                    "store" : ,

                    "index" : ,

                    "precision_step" : ,

                    "null_value" : ,

                    "boost" : ,

                    "include_in_all" : ,

                    "ignore_malformed" :

                },

                "FIELD_NAME" : {

                    "type" : "boolean",

                    "index_name" : ,

                    "store" : ,

                    "index" : ,

                    "null_value" : ,

                    "boost" : ,

                    "include_in_all" : ,

                },

                "FIELD_NAME" : {

                    "type" : "binary",

                    "index_name" : ,

                }

            }

        }

    }



[Fields & Core Type]

fields

_id

document 의 unique id 는 _uid (_id + _type) 이며, _id 는 색인 ID 로 사용될 수 있다.

기본적으로 색인되지 않고 저장 하지 않습니다.

_type

기본적으로 색인은 하지만 저장은 하지 않습니다.

_source

자동으로 field 생성을 허용할지 결정 합니다.

_all

하나 또는 더 많은 field 를 색인시 저장 할 것인지 결정을 합니다.

"simple1" : {"type" : "long", "include_in_all" : true},

           "simple2" : {"type" : "long", "include_in_all" : false}

   _analyzer (설정 하지 않아도 되는 field)

    색인 시 등록된 analyzer 또는 index_analyzer 를 사용 합니다.

    또한, 특정 field 를 지정 할 경우 해당 field 에 정의된 analyzer 를 사용하게 됩니다.

   _boost

    문서나 field 의 연관성을 향상시키기 위해 사용한다.

   _parent

    parent type 을 지시하는 child mapping 정의 입니다.

    blog type 과 blog_tag type 이 있을 경우 blog_tag 의 parent type 은 blog 가 됩니다.

_routing

색인 데이터에 대한 routing 관리를 위해서 사용 합니다.

routing field 는 store : yes, index : not_analyzed 로 설정이 되어야 합니다.

_index (설정 하지 않아도 되는 field)

index 가 소유한 문서를 store 합니다.

default false 로 저장 하지 않음.

_size (설정 하지 않아도 되는 field)

_source 에 의해서 자동으로 생성된 색인 field 의 수.

default disabled 입니다.

_timestamp

색인 시 문서의 timestamp 입니다.

기본 store : no, index : not_analyzed 이며,

설정 시 field 지정이 가능 합니다.

format 은 기본 dateOptionalTime. (http://www.elasticsearch.org/guide/reference/mapping/date-format/)

_ttl

색인 시 문서의 expiration date를 설정 합니다.

기본 disabled 입니다.

설정 시 ttl 이후 문서는 자동 삭제 됩니다.

core types

string type

index_name

array type 선언 시 사용되는 항목으로 array list 항목에 대한 개별 field 명으로 사용된다.

store

default no 이며, 저장에 대한 설정을 위해서 사용 된다.

yes 시 저장

index

검색 또는 색인 시 분석관련 설정을 위해서 사용 된다.

analyzed

검색과 색인 시 analyzer 를 이용해서 분석

not_analyzed

검색가능 하다는 의미

no

검색 불가능 하다는 의미

term_vector

기본 no 설정

no

yes

with_offsets

with_positions

with_positions_offsets

boost

기본 1.0

null_value

null value 시 기본 값은 아무것도 넣지 않으나 설정한 값이 있을 경우 등록 함.

omit_norms

기본 false 로 analyzed field 설정, true 일 경우 not_analyzed field 에서 설정

index_options

색인 옵션

docs

not_analyzed field

freqs

analyzed field

positions

analyzed field

analyzer

global 설정으로 검색과 색인 시 사용된다.

index_analyzer

색인 시에 사용된다.

search_analyzer

검색 시에 사용된다.

include_in_all

기본 true 로 설정 됨.

_all field 에 저장할 것인지 지정함.

ignore_above

지정한 크기 이상의 문자열을 무시 합니다.

position_offset_gap

                number type

                    type : "float, double, byte, short, integer, and long",

                    index_name

                    store

                    index

                    precision_step

                        number 의 term value 를 만들어 냅니다.

                        설정 값이 작을 수록 검색은 빠르게 이루어 집니다.

                        기본 값은 4이며, 32bits 는 4 정도, 64bits 는 6~8정도를 사용합니다.

                        0 은 disable 입니다.

                    null_value

                    boost

                    include_in_all

                    ignore_malformed

                        비정상적인 숫자를 무시 한다.

                        기본 false로 설정 되어 있기 때문에 true 설정 하는 것이 좋다.

                date type

                    index_name

                    format

                        http://www.elasticsearch.org/guide/reference/mapping/date-format.html

                    store

                    index

                    precision_step

                        number 의 term value 를 만들어 냅니다.

                        설정 값이 작을 수록 검색은 빠르게 이루어 집니다.

                        기본 값은 4이며, 32bits 는 4 정도, 64bits 는 6~8정도를 사용합니다.

                        0 은 disable 입니다.

                    null_value

                    boost

                    include_in_all

                    ignore_malformed

                        비정상적인 숫자를 무시 한다.

                        기본 false로 설정 되어 있기 때문에 true 설정 하는 것이 좋다.

                boolean type

                    index_name

                    store

                    index

                    null_value

                    boost

                    include_in_all

                binary type

                    index_name

: