본문 바로가기

리눅스

[리눅스] Elasticsearch REST APIs

반응형

Elasticsearch REST APIs

cURL(command)

클러스터 정보 표시(cluster info)

curl -s -k -u elastic:'elastic1!' https://localhost:9200 | jq
$ curl -s -k -u elastic:'elastic1!' https://localhost:9200 | jq
{
  "name": "node-1",
  "cluster_name": "my-application",
  "cluster_uuid": "IcZQ4wjTR1e9Hym9T8RdQg",
  "version": {
    "number": "8.6.2",
    "build_flavor": "default",
    "build_type": "deb",
    "build_hash": "2d58d0f136141f03239816a4e360a8d17b6d8f29",
    "build_date": "2023-02-13T09:35:20.314882762Z",
    "build_snapshot": false,
    "lucene_version": "9.4.2",
    "minimum_wire_compatibility_version": "7.17.0",
    "minimum_index_compatibility_version": "7.0.0"
  },
  "tagline": "You Know, for Search"
}

클러스터 상태 표시(cluster health)

curl -s -k -u elastic:'elastic1!' https://localhost:9200/_cluster/health | jq
$ curl -s -k -u elastic:'elastic1!' https://localhost:9200/_cluster/health | jq
{
  "cluster_name": "my-application",
  "status": "yellow",
  "timed_out": false,
  "number_of_nodes": 1,
  "number_of_data_nodes": 1,
  "active_primary_shards": 21,
  "active_shards": 21,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 1,
  "delayed_unassigned_shards": 0,
  "number_of_pending_tasks": 0,
  "number_of_in_flight_fetch": 0,
  "task_max_waiting_in_queue_millis": 0,
  "active_shards_percent_as_number": 95.45454545454545
}

인덱스 생성

샤드 및 복제본 수 기본값(shards[pri] : 1, replicas[rep] : 1)

curl -s -k -u elastic:'elastic1!' -XPUT "https://localhost:9200/my-index-000001?pretty"
$ curl -s -k -u elastic:'elastic1!' -XPUT "https://localhost:9200/my-index-000001?pretty"
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "my-index-000001"
}

(or)

샤드 및 복제본 수 지정(shards[pri] : 3, replicas[rep] : 2)

curl -s -k -u elastic:'elastic1!' -XPUT "https://localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index": {
      "number_of_shards": 3,
      "number_of_replicas": 2
    }
  }
}
'
$ curl -s -k -u elastic:'elastic1!' -XPUT "https://localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index": {
      "number_of_shards": 3,
      "number_of_replicas": 2
    }
  }
}
'
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "my-index-000001"
}

생성한 인덱스 확인

curl -s -k -u elastic:'elastic1!' https://localhost:9200/_cat/indices?v
curl -s -k -u elastic:'elastic1!' https://localhost:9200/_cat/indices?v | grep my-index-000001
$ curl -s -k -u elastic:'elastic1!' https://localhost:9200/_cat/indices?v | grep my-index-000001
yellow open   my-index-000001   WfZYAcGCRButmeBq8ZnQYA   1   1          0            0       225b           225b
$ curl -s -k -u elastic:'elastic1!' https://localhost:9200/_cat/indices?v | grep my-index-000001
yellow open   my-index-000001   T-MCo0mbRXWVUbWSUTqKTg   3   2          0            0       675b           675b

Console(웹 콘솔)

Home > Management > Dev Tools

 

참고URL

- REST APIs : https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html

- Index APIs : https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html

 

728x90
반응형