Skip to content

Commit 4f61eea

Browse files
committed
doc: new article Elasticsearch AI Assistants
1 parent cdb631e commit 4f61eea

File tree

9 files changed

+173
-7
lines changed

9 files changed

+173
-7
lines changed

docs/blog.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# Blog
2-
Welcome to explore DocKit! :rocket::rocket::rocket: the blog section will provide you usefully skills and tips to use DocKit and some knowledge share about [Elasticsearch](https://www.elastic.co/), [OpenSearch](https://opensearch.org/), and more to come.
32

3+
Welcome to explore DocKit! :rocket::rocket::rocket: the blog section will provide you usefully skills and tips to use
4+
DocKit and some knowledge share about [Elasticsearch](https://www.elastic.co/), [OpenSearch](https://opensearch.org/),
5+
and more to come.
46

57
## [Introduction to Elasticsearch Desktop Client - DocKit](/blog/elasticsearch-desktop-client.md)
6-
Are you searching for the best Elasticsearch desktop client to streamline your development data management? Look no further! In this comprehensive guide, we will introduce you to DocKit, a top-tier Elasticsearch desktop client designed to enhance your workflow and boost productivity. Whether you're a seasoned developer or just starting out, finding the right tool can make all the difference.
78

9+
Are you searching for the best Elasticsearch desktop client to streamline your development data management? Look no
10+
further! In this comprehensive guide, we will introduce you to DocKit, a top-tier Elasticsearch desktop client designed
11+
to enhance your workflow and boost productivity. Whether you're a seasoned developer or just starting out, finding the
12+
right tool can make all the difference.
13+
14+
## [Automate Elasticsearch Query Writing with AI Assistants - DocKit](/blog/elasticsearch-ai-assistant.md)
15+
16+
Discover how to use AI and large language models to generate complex Elasticsearch queries automatically. Boost
17+
productivity with an AI assistant for Elasticsearch.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: Automate Elasticsearch Query Writing with AI Assistants
3+
description: Discover how to use AI and large language models to generate complex Elasticsearch queries automatically. Boost productivity with an AI assistant for Elasticsearch.
4+
head:
5+
- - meta
6+
- name: keywords
7+
content: Elasticsearch AI assistant, automate Elasticsearch queries, AI-powered Elasticsearch queries, Elasticsearch query assistant, AI for data search, Elasticsearch automation tools
8+
---
9+
10+
# Automate Elasticsearch Query Writing with AI Assistants
11+
Elasticsearch is widely used and performs well in the search engine industry, however, we all know that writing Elasticsearch queries is a painful thing even for experienced DBA, unlike SQL, there are too many terminologies and reserved keywords to memorize, and the query JSON can be surprisingly long and complex based on your business context. With the popularity of AI technologies nowadays, how can it help/empower the writing of Elasticsearch DSL query experiences?
12+
13+
We all know that AI is pretty good for generating text-based content, and Elasticsearch query is also a special type of text with several disciplines. Can we just open the ChatGPT to let it generate the queries for you? The answer is yes and no.
14+
15+
Well, LLM products like ChatGPT can definitely generate Elasticsearch queries for you, but it does not mean that can meet your requirements. And in most cases, you can not directly use the query generated by ChatGPT, except for some very simple queries like the query to list all indices, ChatGPT can give you the correct one that meets your need: `GET _cat/indices`
16+
17+
Why? Because LLM lacks the context of your Elasticsearch server's context, if you like ChatGPT to generate a query for the index you recently working on, ChatGPT at least needs to know the index name, and to meet the specific query conditions, index mapping also becomes prerequisite of the correct query. Some engineers may say " That's fine I can cat the mapping and copy both index name & index mapping for the ChatGPT together with my query expectations represented by natural language". That's also my thoughts and I tried that before, but soon I got tired from copying and pasting those contexts and gave up on using them. Life back to the suffering and pain again just like before ChatGPT Birth。
18+
19+
## Are there any tools available?
20+
21+
Yes, there is, today, I will work through with you How to level up your user experience of Elasticsearch queries by [DocKit](https://github.com/geek-fun/dockit) - an AI-empowered NoSQL GUI desktop client, open-source and cross-platform support for Mac, windows, and Linux.
22+
23+
DocKit supports integrating OpenAI and DeepSeek with your own API keys, the architecture is as follows:
24+
25+
![DocKit AI assistant archetecture](/dockit-ai-flow.png)
26+
27+
Here is the flow of how it works:
28+
29+
1. When you establish a connection to open a new editor tab in DocKit, it will try to fetch the indices and related mappings for the target Elasticsearch/OpenSearch, the mapping info will cached on the memory for later use.
30+
2. when you ask an AI assistant to generate queries or any Elasticsearch/OpenSearch-related questions, DocKit will help you to ingest the index name and mapping info automatically into the conversation context, hence the LLM knows what the natural language against index and index mapping looks like, it will help you get more accurate quires compare to directly ask the LLM.
31+
3. DocKit won't send any data inside an index unless you explicitly provide it in conversation messages, your data is still kept safe and private.
32+
4. Unless you configure and enable the AI assistant and send questions to it, even your index name and mapping info won't be exposed to LLM.
33+
34+
## Let's try it out
35+
36+
You may question the performance of the above solution, let's use an example to have a quick look! Here is a sample data you can use and quickly ingest some sample data(you can also use your existing index as well) [sample-stocks](https://github.com/Blankll/elasticsearch-learn) run the script `./samples/stocks/ingest.sh` and follow the prompt to input related server info to ingest sample data.
37+
38+
The ingested sample data is structured as below:
39+
40+
```json
41+
{
42+
"mappings": {
43+
"dynamic": false,
44+
"properties": {
45+
"close": { "type": "float" },
46+
"date": { "type": "date" },
47+
"high": { "type": "float" },
48+
"low": { "type": "float" },
49+
"name": { "type": "keyword" },
50+
"open": { "type": "float" },
51+
"volume": { "type": "long" }
52+
}
53+
}
54+
}
55+
```
56+
57+
Before use start ask questions in DocKit AI Assistant, you need to config the proper keys for it. DocKit currently supports keys from OpenAI or DeepSeek. step into `settings` -> `[OpenAI|DeepSeek]` -> input model and API Key -> click `Save & Enable`, then you can enjoy the AI Assistant!
58+
59+
![DocKit AI assistant config](/ai-config.png)
60+
61+
### Send prompt to DocKit AI Assistant
62+
63+
Once you configured the API key and related information, you can open a new connection, in the connection code editor, click the right-side logo to open AI Assistant.
64+
65+
![DocKit AI assistant config](/dockit-ai-assistant-question.png)
66+
67+
Open the AI Assistant, input your requirement in natural language(in this case: Return the first 30 names of all the different stock names), and click the send button, DocKit will ingest the selected index context together with your questions.
68+
69+
Then you can get contexture-related queries, which gives you more accurate and smooth experiences compared to copying & pasting a bunch of context information to LLM across different apps, DocKit did it for you.
70+
71+
This is just a very basic example, we encourage you to explore more possibilities by yourself, and we are actively working on enriching the functionalities including MCP support. If you are interested, feel free to raise questions/feature requests or contribute to the project [DocKit](https://github.com/geek-fun/dockit)

docs/public/ai-config.png

572 KB
Loading
1.04 MB
Loading

docs/public/dockit-ai-flow.png

5.19 MB
Loading

docs/zh/blog.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# 博客
2-
欢迎探索 DocKit!:rocket::rocket::rocket: 博客部分将为您提供使用 DocKit 的有用技巧和提示,并分享一些关于 [Elasticsearch](https://www.elastic.co/)[OpenSearch](https://opensearch.org/) 等的知识。
2+
3+
欢迎探索 DocKit!:rocket::rocket::rocket: 博客部分将为您提供使用 DocKit
4+
的有用技巧和提示,并分享一些关于 [Elasticsearch](https://www.elastic.co/)[OpenSearch](https://opensearch.org/) 等的知识。
35

46
## [Elasticsearch 桌面客户端介绍 - DocKit](/zh/blog/elasticsearch-desktop-client.md)
5-
您是否在寻找佳的 Elasticsearch 桌面客户端来简化您的开发数据管理?DocKit就是!在这篇综合指南中,我们将向您介绍 DocKit,这是一款顶级的 Elasticsearch 桌面客户端,旨在提升您的工作流程和生产力。无论您是经验丰富的开发人员还是刚刚起步,找到合适的工具都能带来巨大的不同。
7+
8+
您是否在寻找佳的 Elasticsearch 桌面客户端来简化您的开发数据管理?DocKit就是!在这篇综合指南中,我们将向您介绍
9+
DocKit,这是一款顶级的 Elasticsearch 桌面客户端,旨在提升您的工作流程和生产力。无论您是经验丰富的开发人员还是刚刚起步,找到合适的工具都能带来巨大的不同。
10+
11+
## [使用 DeepSeek 和 OpenAI 等大模型来生成 Elasticsearch 查询](/zh/blog/elasticsearch-ai-assistant.md)
12+
13+
了解如何利用 AI 和大语言模型自动生成复杂的 Elasticsearch 查询。通过 Elasticsearch AI 助手提升工作效率。
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: 使用 DeepSeek 和 OpenAI 等大模型来生成 Elasticsearch 查询
3+
description: 了解如何利用 AI 和大语言模型自动生成复杂的 Elasticsearch 查询。通过 Elasticsearch AI 助手提升工作效率。
4+
head:
5+
- - meta
6+
- name: keywords
7+
content: Elasticsearch AI 助手, AI 自动生成 Elasticsearch 查询, AI 驱动的 Elasticsearch 查询, Elasticsearch 查询助手, AI 数据检索, Elasticsearch 自动化工具
8+
---
9+
10+
# 使用 DeepSeek 和 OpenAI 等大模型来生成 Elasticsearch 查询
11+
12+
Elasticsearch 在搜索引擎行业被广泛使用,并且性能优异。然而众所周知,即使是有经验的数据库工程师,编写 Elasticsearch 的查询也是一件令人头疼的事。与 SQL 不同,Elasticsearch Query DSL 中有太多术语和保留关键字需要记忆,其查询 的JSON语句通常冗长复杂,而且往往还依赖于你的业务上下文。
13+
14+
如今,随着 AI 大模型技术的普及,它是否能改善或增强我们编写 Elasticsearch DSL 查询的体验呢?
15+
16+
我们都知道,AI 在生成基于文本的内容方面非常擅长,而 Elasticsearch 查询本质上也是一种结构化文本,符合一定的规则。那么我们是否可以直接打开 ChatGPT 来生成这些查询?答案是:也可以,也不可以。
17+
18+
像 ChatGPT 这样的 LLM 产品确实可以帮你生成 Elasticsearch 查询,但这并不意味着它就能满足你的需求。大多数情况下,你无法直接使用 ChatGPT 生成的查询。除了像列出所有索引( `GET _cat/indices`)这样的简单查询,ChatGPT 生成的查询语句在更多时候都无法直接使用。
19+
20+
为什么呢?因为 ChatGPT 缺少 Elasticsearch 服务的上下文信息。比如你想让 ChatGPT 为你最近使用的某个索引生成查询语句,它至少需要知道索引名称,如果你还要求具体的查询条件,那就还需要提供索引的 mapping。可能会有工程师说:“那没关系啊,我可以自己把 mapping 和索引名都粘贴给 ChatGPT,再加上我用自然语言描述的查询需求。”我也是这么想的,也确实这么尝试过,但很快我就厌倦了不断复制粘贴上下文的过程,最后还是放弃了。于是一切又回到了 ChatGPT 诞生之前的痛苦状态。
21+
22+
那有没有更好的解决方案呢?
23+
24+
答案是:有!今天介绍一款可以显著提升你编写 Elasticsearch 查询体验的工具——[DocKit](https://github.com/geek-fun/dockit),一个 大模型 加持的 NoSQL 桌面 GUI 客户端。它是开源的,并且跨平台支持 Mac、Windows 和 Linux。
25+
26+
DocKit 支持集成 OpenAI 和 DeepSeek,只需配置你的 API Key。整体架构如下图所示:
27+
28+
![DocKit AI assistant 整体架构](/dockit-ai-flow.png)
29+
30+
以下是它的工作流程:
31+
32+
1. 当你建立一个连接并打开一个新的编辑器页面时,DocKit 会尝试自动获取目标 Elasticsearch/OpenSearch 的索引和相关 mapping 信息,并将这些 mapping 缓存在内存中供后续使用。
33+
2. 当你向 AI 助手提出查询生成请求或其他与 Elasticsearch/OpenSearch 相关的问题时,DocKit 会自动将索引名和 mapping 信息注入到对话上下文中,让大语言模型了解查询要针对的索引结构,从而生成更精确的查询语句,比直接去问 LLM 要好得多。
34+
3. 除非你在对话中明确提供,DocKit 不会发送索引中的实际数据,你的数据依旧安全私密。
35+
4. 除非你启用了 AI 助手并主动与其交互,否则索引名和 mapping 信息也不会在网络中发送。
36+
37+
## 让我们试试看!
38+
39+
你可能对这个方案的效果持怀疑态度,那我们用一个示例快速看一下吧!可以使用这份示例数据,也可以直接使用你已有的索引:[sample-stocks](https://github.com/Blankll/elasticsearch-learn)。运行脚本 `./samples/stocks/ingest.sh`,按提示输入你的服务器信息即可快速导入示例数据。
40+
41+
导入后的数据结构如下所示:
42+
43+
```json
44+
{
45+
"mappings": {
46+
"dynamic": false,
47+
"properties": {
48+
"close": { "type": "float" },
49+
"date": { "type": "date" },
50+
"high": { "type": "float" },
51+
"low": { "type": "float" },
52+
"name": { "type": "keyword" },
53+
"open": { "type": "float" },
54+
"volume": { "type": "long" }
55+
}
56+
}
57+
}
58+
```
59+
60+
在你开始向 DocKit 的 AI 助手提问前,需要配置好 API Key。DocKit 当前支持 OpenAI 和 DeepSeek。进入设置页面:`Settings` -> `[OpenAI|DeepSeek]` -> 输入模型名称和 API Key -> 点击 `Save & Enable`,这样你就可以启用 AI 助手功能了!
61+
62+
![DocKit AI助手配置](/ai-config.png)
63+
64+
### 向 DocKit AI 助手发送提问
65+
66+
配置完毕后,打开一个新的连接,在代码编辑器中点击右侧的 AI 图标打开 AI 助手:
67+
![DocKit AI助手提问界面](/dockit-ai-assistant-question.png)
68+
69+
在打开的 AI 助手中,输入你的自然语言需求(例如:“返回所有不同股票名称的前 30 个名称”),点击发送按钮,DocKit 会自动将当前索引的上下文与问题一起发送给 AI 助手。
70+
71+
这样你就能获得基于实际上下文的查询语句,整体体验要比自己复制粘贴上下文到 LLM 的方式更高效、更顺畅,DocKit 为你做了这部分的繁重工作。
72+
73+
这只是一个非常基础的示例,我们鼓励你自己去探索更多可能性。我们也在积极扩展更多功能(如 MCP 支持)。如果你感兴趣,欢迎在 [DocKit 项目](https://github.com/geek-fun/dockit) 上提交问题、功能请求,或直接参与贡献!
74+
75+
---
76+
77+
你是否已经尝试过在项目中引入 AI 工具来简化查询编写? 欢迎交流!

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dockit-site",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)