# Can ELSER generate Elasticsearch aggregation queries from natural-language input?

**URL:** <https://discuss.elastic.co/t/can-elser-generate-elasticsearch-aggregation-queries-from-natural-language-input/382962>\
**Category:** Elasticsearch\
**Created:** [October 24, 2025, 6:10pm UTC](https://discuss.elastic.co/t/can-elser-generate-elasticsearch-aggregation-queries-from-natural-language-input/382962 "2025-10-24T18:10:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohan\_Kumar\_Reddy\_Ak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohan_kumar_reddy_ak/32/145499_2.png) [@Mohan\_Kumar\_Reddy\_Ak](https://discuss.elastic.co/u/Mohan_Kumar_Reddy_Ak)\
**Post date:** [October 24, 2025, 6:10pm UTC](https://discuss.elastic.co/t/can-elser-generate-elasticsearch-aggregation-queries-from-natural-language-input/382962/1 "2025-10-24T18:10:53Z")

</div>

Hi team,

I’m exploring a hybrid setup where **LLMs (like GPT-4 or GPT-5)** convert natural-language questions into **Elasticsearch DSL queries** — including aggregations such as `avg`, `terms`, and `date_histogram`.

However, I’m facing a key issue:

> The LLMs often generate **inaccurate or incomplete queries** — for example, using the wrong field names, missing `.keyword` suffixes, or mismatching numeric vs. keyword fields — which causes query failures or incorrect results.

I’m already using **ELSER** for semantic retrieval (`text_expansion` queries), and I’m wondering if ELSER could help **bridge the gap** for natural-language analytics, e.g., by:

- Providing better context or embeddings for LLMs to ground queries on actual index fields

- Helping interpret the _semantic meaning_ of text fields before forming aggregations

- Or being integrated into the LLM prompt to guide query formation more accurately

So my questions are:

1. Can ELSER itself help generate or validate **aggregation queries** based on natural language?

2. Is there a recommended approach to **combine ELSER with LLMs** to improve the accuracy of NLP-to-Elasticsearch query generation (especially for analytics use cases)?

3. Are there best practices for grounding LLMs on the **actual index mapping** so that generated DSL aligns with field types and naming conventions?

Any guidance or examples would be greatly appreciated.

Thanks!
