version: '3.9'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.14.3
    container_name: elasticsearch8
    volumes:
      - elasticdata:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    restart: unless-stopped
    environment:
      - discovery.type=single-node
      - ELASTIC_PASSWORD=elastic
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
      #domyślna wartość to 500, zwiększenie eliminuje błędy przy usuwaniu procesów (błąd: Trying to create too many scroll contexts)
      - ES_SETTING_SEARCH_MAX__OPEN__SCROLL__CONTEXT=10000
      #domyślna wartość to 1000, zwiększamy w przypadku wystąpienia błędu: this action would add [2] shards, but this cluster currently has [1000]/[1000] maximum normal shards open
      - ES_SETTING_CLUSTER_MAX__SHARDS__PER__NODE=2000
    deploy:
        resources:
            limits:
              memory: 8G
    ulimits:
      memlock:
        soft: -1
        hard: -1
  kibana:
    image: docker.elastic.co/kibana/kibana:8.14.3
    container_name: kibana
    volumes:
      - kibanadata:/usr/share/kibana/data
    ports:
      - 5601:5601
    environment:
      - SERVERNAME=kibana
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
      - ELASTICSEARCH_USERNAME=kibana_user
      - ELASTICSEARCH_PASSWORD=kibana
      - xpack.security.enabled=false
      - NODE_OPTIONS="--max-old-space-size=1024"
    deploy:
        resources:
            limits:
              memory: 1G
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'",
        ]
      interval: 10s
      timeout: 10s
      retries: 120
    depends_on:
      - elasticsearch
    restart: unless-stopped
    logging:
        driver: none

volumes:
  elasticdata:
      driver: local
  kibanadata:
      driver: local
