﻿---
title: Generate, customize, and learn about ES|QL queries
description: Elastic Agent Builder can help you learn about and use the Elasticsearch Query Language (ES|QL) to accomplish goals across Elastic Security. If you use...
url: https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9588/solutions/security/ai/generate-customize-learn-about-esorql-queries
products:
  - Elastic Cloud Serverless
  - Elastic Documentation
  - Elastic Security
applies_to:
  - Serverless Security projects: Generally available
  - Elastic Stack: Generally available
---

# Generate, customize, and learn about ES|QL queries
[Elastic Agent Builder](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9588/solutions/security/ai/agent-builder/agent-builder) can help you learn about and use the Elasticsearch Query Language (ES|QL) to accomplish goals across Elastic Security.
If you use AI Assistant, refer to [Use AI Assistant (deprecated)](#esql-queries-ai-assistant).

## Use Elastic Agent Builder for ES|QL

<applies-to>
  - Serverless Security projects: Generally available
  - Elastic Stack: Generally available since 9.4
</applies-to>

Chat with the [Elastic AI Agent](/elastic/docs-content/pull/9588/explore-analyze/ai-features/agent-builder/builtin-agents-reference#elastic-ai-agent) to:
- **Learn ES|QL**: Ask for examples, explanations of complex queries, and best practices.
- **Write new queries**: Describe what you want to find, and the agent generates a matching query. For example: "Write a query to identify documents with `curl.exe` usage and calculate the sum of `destination.bytes`" or "What query would return all user logins to [a host] in the last six hours?"
- **Run queries against your data**: The agent can run the queries it writes and summarize the results, so you can iterate without leaving the conversation.
- **Optimize existing queries**: Paste a query and ask for improvements, refactoring, a general assessment, or better performance with large data sets.
- **Customize queries for your environment**: Ask the agent to adapt a query to your indices and field names.
- **Troubleshoot**: Ask the agent to explain errors or unexpected results.

For hypothesis-driven hunts that run iterative ES|QL queries, use the `threat-hunting` skill. Refer to [Threat hunting](/elastic/docs-content/pull/9588/solutions/security/ai/agent-builder/skills-use-cases#threat-hunting).

## Use AI Assistant (deprecated)

<applies-to>
  - Serverless Security projects: Deprecated
  - Elastic Stack: Planned for deprecation
  - Elastic Stack: Generally available from 9.0 to 9.5
</applies-to>

Elastic AI Assistant can help you learn about and leverage the Elasticsearch Query Language (ES|QL) in many ways, including:
- **Education and training**: AI Assistant can serve as a powerful ES|QL learning tool. Ask it for examples, explanations of complex queries, and best practices.
- **Writing new queries**: Prompt AI Assistant to provide a query that accomplishes a particular task, and it will generate a query matching your description. For example: "Write a query to identify documents with `curl.exe` usage and calculate the sum of `destination.bytes`" or "What query would return all user logins to [a host] in the last six hours?"
- **Providing feedback to optimize existing queries**: Send AI Assistant a query you want to work on and ask it for improvements, refactoring, a general assessment, or to optimize the query’s performance with large data sets.
- **Customizing queries for your environment**: Since each environment is unique, you may need to customize queries that you used in other contexts. AI Assistant can suggest necessary modifications based on contextual information you provide.
- **Troubleshooting**: Having trouble with a query or getting unexpected results? Ask AI Assistant to help you troubleshoot.

In these ways and others, AI Assistant can enable you to make use of ES|QL's advanced search capabilities to accomplish goals across Elastic Security.