Skip to the content.

Elasticsearch Agent Builder: Intent Classifier, Ingest & Query Pipeline - Make your data conversational!

Turn Telegram chat and voice messages into searchable knowledge using an n8n orchestration that leverages AWS Bedrock LLMs, Elasticsearch MCP, and the Elastic Agent Builder for custom function-calling tools and retrieval workflows.

This repository contains an architecture diagram and documentation for an automated system that connects Telegram > n8n workflow > AWS Bedrock (LLMs) > Elasticsearch, enabling both ingestion (indexing structured JSON) and conversational query flows.

Overview

Users send messages (text or voice) to a Telegram bot. An n8n workflow receives the message, optionally transcribes audio via a speech-to-text service, and builds a unified text payload. That payload is sent to a classifier agent (LLM hosted via AWS Bedrock) which returns a structured JSON with the detected intent, signals, and metadata (confidence, entities, etc.).

Based on the intent the workflow either:

Ingestion Flow:

  1. Routes to the ingestion flow: an ingestion agent prepares a JSON document based on the Elastic Common Schema, which is then indexed into Elasticsearch with the semantic_text field to activate Semantic search.

Search Flow:

  1. Routes to the query flow: an AI query agent consults Elasticsearch MCP Server, formats the natural language, and responds to the user in Telegram.

Low-confidence classifier outputs trigger an interactive clarification step in Telegram when the confidence is below the threshold.

End Goal

The system accepts voice or text input, processes it, queries Elasticsearch with your expense data, applies semantic retrieval, and generates a natural language response in the Telegram bot.

telegram_bot_messages

Architecture

Architecture diagram

Components

Low-confidence handling

Elasticsearch Agent Builder

elasticsearch_agent_builder_chat_interface

create_agents

agent_tools

tools_esql

Edge cases & considerations

How to run (high-level)

(For complete step-by-step experience, check my Tutorial)

This repo contains documentation, the architecture diagram, n8n_workflow_scaffold which you can import directly. For a working deployment, implement these parts:

Elasticsearch Index Mapping with semantic_text field enabled:

   {
  "mappings": {
    "properties": {
      "amount": {
        "type": "double"
      },
      "attachments": {
        "type": "nested",
        "properties": {
          "hash": {
            "type": "keyword"
          },
          "linked_expense_ids": {
            "type": "keyword"
          },
          "type": {
            "type": "keyword"
          },
          "url": {
            "type": "keyword"
          }
        }
      },
      "audio_hash": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "category": {
        "type": "keyword"
      },
      "chat_id": {
        "type": "keyword"
      },
      "currency": {
        "type": "keyword"
      },
      "merchant": {
        "type": "keyword"
      },
      "normalized_inr": {
        "type": "double"
      },
      "note": {
        "type": "text",
        "copy_to": [
          "semantic_all"
        ]
      },
      "payment_method": {
        "type": "keyword",
        "copy_to": [
          "semantic_all"
        ]
      },
      "raw_transcript": {
        "type": "text",
        "copy_to": [
          "semantic_all"
        ]
      },
      "segments": {
        "type": "nested",
        "properties": {
          "amount": {
            "type": "double"
          },
          "category": {
            "type": "keyword"
          },
          "end_ms": {
            "type": "integer"
          },
          "merchant": {
            "type": "keyword"
          },
          "payment_method": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "start_ms": {
            "type": "integer"
          },
          "text": {
            "type": "text",
            "copy_to": [
              "semantic_all"
            ]
          }
        }
      },
      "semantic_all": {
        "type": "semantic_text",
        "inference_id": "bedrock-embeddings",
        "model_settings": {
          "service": "amazonbedrock",
          "task_type": "text_embedding",
          "dimensions": 1024,
          "similarity": "cosine",
          "element_type": "float"
        }
      },
      "stt_confidence": {
        "type": "double"
      },
      "stt_model": {
        "type": "keyword"
      },
      "stt_provider": {
        "type": "keyword"
      },
      "ts": {
        "type": "date"
      },
      "user_id": {
        "type": "keyword"
      }
    }
  }
}

Sample data ingested and processed via semantic_text

   {
  "_index": "expenses",
  "_id": "224",
  "_version": 1,
  "_source": {
    "normalized_inr": 4500,
    "note": "Burger purchase",
    "amount": 4500,
    "user_id": "567876545",
    "merchant": "McDonald's",
    "currency": "INR",
    "category": "food",
    "raw_transcript": "Can you add my expense on McDonald's burger yesterday which is 25th of September which was Thursday and I paid via my credit card and I spent around 4500.",
    "payment_method": "credit_card",
    "chat_id": "45678456784567-iyn678",
    "ts": "2025-09-25T12:00:00+05:30"
  },
  "fields": {
    "normalized_inr": [
      4500
    ],
    "note": [
      "Burger purchase"
    ],
    "amount": [
      4500
    ],
    "semantic_all": [
      "Burger purchase",
      "credit_card",
      "Can you add my expense on McDonald's burger yesterday which is 25th of September which was Thursday and I paid via my credit card and I spent around 4500."
    ],
    "user_id": [
      "567876545"
    ],
    "merchant": [
      "McDonald's"
    ],
    "currency": [
      "INR"
    ],
    "category": [
      "food"
    ],
    "raw_transcript": [
      "Can you add my expense on McDonald's burger yesterday which is 25th of September which was Thursday and I paid via my credit card and I spent around 4500."
    ],
    "payment_method": [
      "credit_card"
    ],
    "chat_id": [
      "45678456784567-iyn678"
    ],
    "ts": [
      "2025-09-25T06:30:00.000Z"
    ]
  }
}

Sample data & Colab quickstart

License

This project will be licensed under the Apache License 2.0. See LICENSE.