From Query Migration to AI: What's Possible with Elastic?
See how ES|QL tools and Elastic Agent Builder help AI agents run evidence-backed investigations. Then watch our webinar on migrating CQL to ES|QL.
For most of its history, an investigation has meant a person writing queries. You form a hypothesis, write a search, read the result, refine it, and repeat. The skill sits in the analyst's head, and the queries are just the means of getting an answer out of the data.
That model is starting to change. Teams are now asking a different question: what if the queries themselves became tools that an AI agent can use to investigate for you? The answer depends less on the model than on what you give it to work with.
The problem with a plausible answer
Anyone who has tried an AI assistant in an incident knows the risk. The answer sounds right, but you can't tell whether it's grounded in your data.
Elastic Observability Labs examined this in a September 2026 post on AI root cause analysis with ES|QL tools in Agent Builder. The scenario is a cascading failure. A recent deploy and a second failing service both look like the cause, and they happen in the same minute.
In the author's tests, the default Elastic AI Agent found the right origin. But across three runs it described a different mechanism for the deployment each time, and one failure-rate figure had no visible query behind it. The author also reports that the figure came from dividing failures by successes instead of by total requests.
An answer like that points in the right direction, but you can't verify it, so you can't rely on it during an incident.
What changed: purpose-built tools, each answering one question
The fix in the article wasn't a bigger model. It was a small set of custom ES|QL tools, each built to answer one specific question:
- Failure shapes groups error traces by the set of services involved. This tells you whether you're looking at one incident or several failures that happen to coincide.
- Version split compares failure rates between two service versions. This tests whether a deploy is responsible.
- Evidence sample returns document IDs, so every claim can be checked against the source data.
The agent's instructions required it to list candidate causes, test each one against something that could refute it, cite a trace ID and document ID for every root cause claim, and list unresolved questions as gaps.
Elastic's example results, from a single demo run and not a benchmark:
- The version split showed failure rates of 27.2% and 28.2% across roughly 3,700 requests per version. That ruled out the deployment as the cause.
- Failure shapes showed 2,043 traces involving the three checkout-related services and 1,324 involving only search-api, with no overlap. That separated the coincident failure from the real one.
- The investigation took 11 tool calls and 72 seconds.
The numbers matter less than the pattern. Each conclusion came with a query you could run yourself.
Where ES|QL fits in
None of this works without a query layer that's structured enough to turn into tools. This is where ES|QL comes in.
Elastic's engineers have said they see ES|QL as the future of how AI agents, applications, and humans will talk to Elastic. Elastic Agent Builder puts that into practice: it lets you create custom tools from ES|QL queries and expose the agents you build to other applications.
Think of it as layers:
- Data in Elasticsearch.
- Queries written in ES|QL, each answering a clear question.
- Tools built from those queries, with descriptions that say what decision each one supports.
- Agents that choose among the tools, show their evidence, and flag what they couldn't determine.
The article makes a point worth remembering: tool descriptions shape when an agent calls a tool, so each tool should state the decision it supports. Writing a good tool takes the same discipline as writing a good query.
What you need to try this
The setup in the article requires Elasticsearch and Kibana 9.5, either self-managed or on Elastic Cloud, plus a generative AI connector. Agent Builder is model-agnostic, so you can bring your own provider. The article also provides a companion notebook so you can reproduce the demo.
Check Elastic's documentation for the current availability of each feature on your deployment type before planning around it.
What it means for your query workflows
If you want agents to investigate with your data, the quality of your query layer sets the ceiling. A few practical consequences:
- Consistent queries make better tools. Logic spread across several languages has to be rebuilt before an agent can use it.
- Structured data makes better evidence. The article's demo got more out of the agent by adding a structured upstream.service field to error logs, which let it reconstruct the call chain.
- Verifiability is a design goal. Returning document IDs and citing trace IDs let a reader check each claim directly.
Teams that modernize their query workflows now are building the foundation for this, whether or not they plan to deploy agents soon.
Watch the recording: Migrate to ES|QL and Build AI-Powered Investigations
For teams with CQL workflows, migration is where this starts. In our webinar, we cover:
- Why organizations are consolidating query workflows
- How to migrate alert rules, dashboard panels, and scheduled searches from CQL to ES|QL
- Common migration challenges, including row limits, multivalued fields, and date-math differences
- How LOOKUP JOIN supports enrichment workflows
- How migrated queries can become reusable tools in Elastic Agent Builder
- A demo of an AI agent using those tools to evaluate potential causes and ground its conclusions in Elastic data
If you want to see how migrated queries can become investigation tools, the recording is a good place to start.
FAQs
What is an AI-powered investigation in Elastic?
It's an investigation where an AI agent uses tools to query your Elastic data, test possible causes, and report findings. Elastic Agent Builder lets you create those tools from ES|QL queries.
Why do AI agents need purpose-built tools?
In Elastic's example, a default agent reached a plausible answer but changed its explanation between runs and gave a figure with no visible query. Purpose-built ES|QL tools let each claim be checked against the data.
What are ES|QL tools in Elastic Agent Builder?
They are custom tools defined by an ES|QL query. Agents can call them to answer specific questions, such as comparing failure rates between two versions.
What does the setup in Elastic's example require?
Elasticsearch and Kibana 9.5 (self-managed or Elastic Cloud) and a generative AI connector, according to the article.
Do I need to migrate my queries to ES|QL first?
To build ES|QL tools, you need ES|QL queries. Teams with workflows in another language, such as CQL, would convert them first. That conversion was the focus of our webinar, and the recording walks through it.

