본문 바로가기
WIKI 기술 지식 베이스

join() function

원문 보기 위키 갱신

출처: 문서

본문

join() 함수

join() 함수는 리스트의 요소들을 연결하여 문자열을 형성해요. 이 함수는 리스트 타입의 값을 가진 리스트나 맵의 키를 나타내는 JSON 포인터를 받아서, 구분자를 사용하여 리스트들을 문자열로 연결해요. 기본 구분자는 쉼표(,)예요.

매개변수

join 함수는 다음 매개변수를 받아요:

  • delimiter (string, optional): 요소 사이에 배치되는 문자열이에요. 예: ,, |, ; . 기본값은 ,이에요.
  • pointer (required): 이벤트의 리스트로 확인되는 JSON 포인터예요.

반환값

join 함수는 다음 값을 반환해요:

  • string: 모든 요소가 지정된 delimiter를 사용하여 연결된 문자열이에요.

빠른 예시

  • join("-", /labels)는 labels: ["prod","api","us"]에 대해 "prod-api-us"를 반환해요.
  • join(" | ", /authors)는 authors: ["Ada","Linus","Grace"]에 대해 "Ada | Linus | Grace"를 반환해요.

파이프라인에서 join() 사용하기

value_expression을 지원하는 프로세서 내에서 join()을 사용할 수 있어요. 예를 들어, add_entries 프로세서에서요:

processor:
  - add_entries:
      entries:
        - key: labels_csv
          value_expression: join(" | ", /labels)

{% include copy.html %}

예시

다음 파이프라인은 http 소스를 사용하여 JSON 이벤트를 수집해요. 그런 다음 add_entries와 join()을 사용하여 labels_csv와 authors_pipe라는 두 개의 새 필드를 만들어요:

join-demo:
  source:
    http:
      path: /events
      ssl: false
  processor:
    - add_entries:
        entries:
          - key: labels_csv
            value_expression: join(/labels) # Comma is used by default
          - key: authors_pipe
            value_expression: join(" | ", /authors)
  sink:
    - opensearch:
        hosts: ["https://opensearch:9200"]
        index: join-demo-%{yyyy.MM.dd}
        username: admin
        password: admin_password
        index_type: custom
        insecure: true  # set to true for self-signed local clusters

{% include copy.html %}

다음 명령을 사용하여 파이프라인을 테스트할 수 있어요:

curl "http://localhost:2021/events" \
   -H "Content-Type: application/json" \
   -d '[
    {"message":"hello","labels":["prod","api","us"],"authors":["Ada","Linus","Grace"]},
    {"message":"world","labels":["stage","etl"],"authors":["Marie","Alan"]}
  ]'

{% include copy.html %}

OpenSearch에 저장된 문서에는 다음 정보가 포함되어 있어요:

{
  ...
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "join-demo-2025.11.06",
        "_id": "aGFyWZoBjfY5UoR7NC36",
        "_score": 1,
        "_source": {
          "message": "hello",
          "labels": [
            "prod",
            "api",
            "us"
          ],
          "authors": [
            "Ada",
            "Linus",
            "Grace"
          ],
          "labels_csv": "prod,api,us",
          "authors_pipe": "Ada | Linus | Grace"
        }
      },
      {
        "_index": "join-demo-2025.11.06",
        "_id": "aWFyWZoBjfY5UoR7NC36",
        "_score": 1,
        "_source": {
          "message": "world",
          "labels": [
            "stage",
            "etl"
          ],
          "authors": [
            "Marie",
            "Alan"
          ],
          "labels_csv": "stage,etl",
          "authors_pipe": "Marie | Alan"
        }
      }
    ]
  }
}

{% include copy.html %}

더 알아보기 (Learn more)