'array'에 해당되는 글 6건

  1. 2022.03.14 [Shell] Bash String Replacement.
  2. 2021.10.27 [Postman] Set Array Variable.
  3. 2020.04.20 [Bash] Bash function, array parameters, str replace 등
  4. 2017.04.18 [Java] Array Value 존재 유무 확인하기
  5. 2017.01.19 [Lucene] Multi-value fields and the inverted index
  6. 2013.04.16 [elasticsearch] Mapping - Array/Object/Nested Type

[Shell] Bash String Replacement.

ITWeb/개발일반 2022. 3. 14. 12:14

docker-compose.yml 내 .env 를 이용한 활용이 안되는 경우 아래 처럼 그냥 string replacement 를 통해서 처리 할 수도 있습니다.

bash 에서  array, loop, replacement 에 대한 예제로 작성해 둡니다.

 

SERVICE_NAME='{{SERVICE_NAME}}=escs'
VERSION='{{VERSION}}=8.0.0'
CONTAINER_NAME='{{CONTAINER_NAME}}=escs-c'

DOCKER_VAR=( $SERVICE_NAME $VERSION $CONTAINER_NAME )

for var in "${DOCKER_VAR[@]}"; do
    kvs=($(echo $var | tr "=" "\n"))
    # linux
    sed -i "s/${kvs[0]}/${kvs[1]}/g" docker-compose.yml
    # osx
    sed -i '' "s/${kvs[0]}/${kvs[1]}/g" docker-compose.yml
done

 

:

[Postman] Set Array Variable.

ITWeb/개발일반 2021. 10. 27. 12:36

참고문서)

https://learning.postman.com/docs/sending-requests/variables/

 

Pre-request Script

pm.environment.set("KEYWORDS", "삼성", "전자", "삼성전자")

 

Body

{
  "query": {
    "terms": {
      "keywords": [
        "{{KEYWORDS}}"
      ]
    }
  }
}

 Array 로 설정을 해야 할 일이 있어서 또 기억 못할까봐 기록해 봅니다.

:

[Bash] Bash function, array parameters, str replace 등

ITWeb/개발일반 2020. 4. 20. 11:18

bash script 에서 function 사용은 호출 위치 보다 위에 function 선언이 되어 있어야 합니다.

#!/usr/bin/env bash

function 함수명() {
...
}

## 예제

#!/usr/bin/env bash

function helloWorld() {
  echo 'Hello World!!'
}

helloWorld

 

function  에 다중 array paramters 를 넘기는 예제는 아래와 같습니다.

#!/usr/bin/env bash

function deployElasticStack() {
  local instances=($1)
  local targets=($2)

  for instance in ${instances[@]}
  do

    local hostIpUser=($(echo $instance | tr ":" "\n"))

    for target in ${targets[@]}
    do
...중략...
    done
  done
}

selfHost=$(hostname -I|cut -f1 -d ' ')

instanceArr=("xxx.xxx.xxx.xxx:ubuntu" "xxx.xxx.xxx.xxx:ec2-user" "xxx.xxx.xxx.xxx:ubuntu")
metricbeatArr=("xxx.xxx.xxx.xxx" "xxx.xxx.xxx.xxx" "xxx.xxx.xxx.xxx")

deployElasticStack "${instanceArr[*]}" "${metricbeatArr[*]}" "$selfHost" "metricbeat"

 

해당 장비의 IP 정보를 가져 오는 예제는 아래와 같습니다.

$ hostname -I

$ hostname -I|cut -f1 -d ' '

$ ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}'

 

file 내 특정 문자열을 치환 하는 예제는 아래와 같습니다.

$ sed -i "s/소스문자열/치환문자열/g" configuration.yml

# osx 에서는 아래와 같이 합니다.
$ sed -i "" "s/소스문자열/치환문자열/g" configuration.yml

 

:

[Java] Array Value 존재 유무 확인하기

ITWeb/개발일반 2017. 4. 18. 10:38

생각 나지 않을때가 많아서 퍼왔습니다.


Originanl Source)

http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/


public static boolean useList(String[] arr, String targetValue) {

  return Arrays.asList(arr).contains(targetValue);

}


public static boolean useSet(String[] arr, String targetValue) {

  Set<String> set = new HashSet<String>(Arrays.asList(arr));

  return set.contains(targetValue);

}


public static boolean useLoop(String[] arr, String targetValue) {

  for(String s: arr){

    if(s.equals(targetValue))

      return true;

  }

  return false;

}


public static boolean useArraysBinarySearch(String[] arr, String targetValue) { 

  int a =  Arrays.binarySearch(arr, targetValue);

  if(a > 0)

    return true;

  else

    return false;

}


binary search 가 제일 성능이 좋습니다.

단, 위 코드에서 빠진게 있다면 Arrays.sort(arr) 를 먼저 하고 하셔야 된다는 것입니다.


Arrays.sort(arr);

int a = Arrays.binarySearch(arr, targetValue);

:

[Lucene] Multi-value fields and the inverted index

ITWeb/검색일반 2017. 1. 19. 18:41
아주 기초적인 것도 잊어버리는 것 같아 기록해 봅니다.

Multi-value fields and the inverted index

The fact that all field types support multi-value fields out of the box is a consequence of the origins of Lucene. Lucene was designed to be a full text search engine. In order to be able to search for individual words within a big block of text, Lucene tokenizes the text into individual terms, and adds each term to the inverted index separately.

This means that even a simple text field must be able to support multiple values by default. When other datatypes were added, such as numbers and dates, they used the same data structure as strings, and so got multi-values for free.


이 글은 아래 elasticsearch 에서 퍼왔습니다.


[문서]

https://www.elastic.co/guide/en/elasticsearch/reference/2.4/array.html

:

[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", ....}

        ......

    }

}



: