id: elasticsearch
name: Elasticsearch
version: 1.0.0
description: "Elasticsearch (REST API) — log search and enrichment for security data: run queries, count and read documents, list indices, index a document, and delete by query. API-key authentication; stdlib-only, no extra Python dependencies. Works with Elastic Security indices."
changelog: "1.0.0 — Initial release: search, count, get document, index document, list indices, delete by query."
category: siem

# Per-instance configuration. Auth header 'Authorization: ApiKey <api_key>'.
config_schema:
  properties:
    url:
      type: string
      description: "Elasticsearch base URL (e.g. https://es.example.com:9200)"
    api_key:
      type: string
      description: "Elasticsearch API key (base64 id:key)"
      x-soar-sensitive: true
    insecure:
      type: boolean
      description: "Trust any TLS certificate (not secure)"
      default: false
  required:
    - url
    - api_key

commands:
  - id: search
    name: elasticsearch-search
    description: "Search an index. Provide a raw query DSL (query_json) or a simple query string."
    risk: read
    inputs_schema:
      properties:
        index: { type: string, description: "Index or index pattern (e.g. logs-*)" }
        query_json: { type: string, description: "Raw Elasticsearch query DSL as a JSON object (advanced)" }
        query_string: { type: string, description: "Simple query_string query (used if query_json is empty)" }
        size: { type: number, description: "Max hits (default 50)" }
      required: [index]
    outputs_schema: { properties: {} }
  - id: count
    name: elasticsearch-count
    description: "Count documents matching a query."
    risk: read
    inputs_schema:
      properties:
        index: { type: string, description: "Index or index pattern" }
        query_string: { type: string, description: "Optional simple query_string (default all)" }
      required: [index]
    outputs_schema: { properties: {} }
  - id: get_document
    name: elasticsearch-get-document
    description: "Get a single document by ID."
    risk: read
    inputs_schema:
      properties:
        index: { type: string, description: "Index name" }
        doc_id: { type: string, description: "Document ID" }
      required: [index, doc_id]
    outputs_schema: { properties: {} }
  - id: index_document
    name: elasticsearch-index-document
    description: "Index (create) a document."
    inputs_schema:
      properties:
        index: { type: string, description: "Index name" }
        document_json: { type: string, description: "Document body as a JSON object" }
        doc_id: { type: string, description: "Optional document ID (auto-generated if omitted)" }
      required: [index, document_json]
    outputs_schema: { properties: {} }
  - id: list_indices
    name: elasticsearch-list-indices
    description: "List indices."
    risk: read
    inputs_schema:
      properties: {}
      required: []
    outputs_schema: { properties: {} }
  - id: delete_by_query
    name: elasticsearch-delete-by-query
    description: "Delete documents matching a query."
    inputs_schema:
      properties:
        index: { type: string, description: "Index name" }
        query_json: { type: string, description: "Raw query DSL (JSON object) selecting documents to delete" }
      required: [index, query_json]
    outputs_schema: { properties: {} }

  - id: test_connection
    name: elasticsearch-test-connection
    description: "Verify connectivity and the API key (used by the Test button)."
    risk: read
    inputs_schema:
      properties: {}
      required: []
    outputs_schema: { properties: {} }
