快速入门
在本快速入门指南中,我们将安装 Quickwit,创建一个索引,添加文档,最后执行搜索查询。本指南中使用的所有 Quickwit 命令都在 CLI 参考文档 中进行了记录。

使用 Quickwit 安装程序安装 Quickwit
Quickwit 安装程序会自动为您的环境选择正确的二进制归档文件,然后在您的工作目录中下载并解压它。 此方法仅适用于 某些操作系统/架构,并且您还需要安装一些 外部依赖项。
curl -L https://install.quickwit.io | sh
cd ./quickwit-v*/
./quickwit --version
现在您可以根据您的环境将这个可执行文件目录移动到合适的位置,并可能将其添加到您的 PATH
环境变量中。
使用 Quickwit 的 Docker 镜像
您还可以在隔离的 Docker 容器中拉取和运行 Quickwit 二进制文件。
# Create first the data directory.
mkdir qwdata
docker run --rm quickwit/quickwit --version
如果您使用的是基于 Apple Silicon 的 macOS 系统,您可能需要指定平台。您也可以安全地忽略 jemalloc 的警告。
docker run --rm --platform linux/amd64 quickwit/quickwit --version
Start Quickwit server
- CLI
- Docker
./quickwit run
docker run --rm -v $(pwd)/qwdata:/quickwit/qwdata -p 127.0.0.1:7280:7280 quickwit/quickwit run
提示:您可以使用环境变量 RUST_LOG
来控制 Quickwit 的详细程度。
通过访问 UI 地址 http://localhost:7280 或使用 cURL 发送简单的 GET 请求来检查其是否正常工作:
curl http://localhost:7280/api/v1/version
创建您的第一个索引
在向 Quickwit 添加文档之前,您需要使用一个 YAML 配置文件创建一个索引。此配置文件特别允许您定义如何将输入文档映射到索引字段以及这些字段是否应该被存储和索引。请参阅 索引配置文档。
让我们创建一个配置为接收 Stackoverflow 帖子(问题和答案)的索引。
# First, download the stackoverflow dataset config from Quickwit repository.
curl -o stackoverflow-index-config.yaml https://raw.githubusercontent.com/quickwit-oss/quickwit/main/config/tutorials/stackoverflow/index-config.yaml
索引配置定义了三个字段:title
、body
和 creationDate
。title
和 body
是 索引化和分词 的,并且它们也被用作默认搜索字段,这意味着如果您的查询不针对特定字段,它们将用于搜索。creationDate
作为每条记录的时间戳。没有更多的显式字段定义,因为我们使用默认的动态 模式:未声明的字段仍然会被索引,默认情况下启用了快速字段以支持聚合查询,并且使用 raw
分词器处理文本。
以下是完整的配置:
#
# Index config file for stackoverflow dataset.
#
version: 0.7
index_id: stackoverflow
doc_mapping:
field_mappings:
- name: title
type: text
tokenizer: default
record: position
stored: true
- name: body
type: text
tokenizer: default
record: position
stored: true
- name: creationDate
type: datetime
fast: true
input_formats:
- rfc3339
fast_precision: seconds
timestamp_field: creationDate
search_settings:
default_search_fields: [title, body]
indexing_settings:
commit_timeout_secs: 30
现在我们可以使用以下命令创建索引:
- CLI
- CURL
./quickwit index create --index-config ./stackoverflow-index-config.yaml
curl -XPOST http://127.0.0.1:7280/api/v1/indexes --header "content-type: application/yaml" --data-binary @./stackoverflow-index-config.yaml
检查是否已创建目录 ./qwdata/indexes/stackoverflow
,Quickwit 将在此处写入索引文件和包含 索引元数据 的 metastore.json
文件。
现在您已经准备好填充索引了。
让我们添加一些文档
Quickwit 可以从许多 来源 索引数据。我们将使用新行分隔的 JSON NDJSON 数据集作为我们的数据源。 让我们下载 一批 Stackoverflow 帖子(10,000条) 的 NDJSON 格式并对其进行索引。
# Download the first 10_000 Stackoverflow posts articles.
curl -O https://quickwit-datasets-public.s3.amazonaws.com/stackoverflow.posts.transformed-10000.json
- CLI
- CURL
# Index our 10k documents.
./quickwit index ingest --index stackoverflow --input-path stackoverflow.posts.transformed-10000.json --force
# Index our 10k documents.
curl -XPOST "http://127.0.0.1:7280/api/v1/stackoverflow/ingest?commit=force" --data-binary @stackoverflow.posts.transformed-10000.json
一旦 ingest
命令完成,您就可以开始使用以下 search
命令查询数据:
- CLI
- CURL
./quickwit index search --index stackoverflow --query "search AND engine"
curl "http://127.0.0.1:7280/api/v1/stackoverflow/search?query=search+AND+engine"
它应该返回 10 条结果。现在您已经准备好使用搜索 API 进行操作了。
执行搜索查询
让我们从对字段 title
的查询开始:title:search AND engine
:
curl "http://127.0.0.1:7280/api/v1/stackoverflow/search?query=title:search+AND+engine"
相同的请求可以用 JSON 查询表达:
curl -XPOST "http://localhost:7280/api/v1/stackoverflow/search" -H 'Content-Type: application/json' -d '{
"query": "title:search AND engine"
}'
这种格式更冗长,但它允许您使用更多高级功能,例如聚合。以下查询查找此数据集中问题中最常用的标签:
curl -XPOST "http://localhost:7280/api/v1/stackoverflow/search" -H 'Content-Type: application/json' -d '{
"query": "type:question",
"max_hits": 0,
"aggs": {
"foo": {
"terms":{
"field":"tags",
"size": 10
}
}
}
}'
在尝试不同的查询时,请查看服务器日志以了解发生了什么。
不要忘记正确编码查询参数以避免出现错误请求(状态码 400)。
清理
让我们通过删除索引来做一些清理工作:
- CLI
- REST
./quickwit index delete --index stackoverflow
curl -XDELETE http://127.0.0.1:7280/api/v1/indexes/stackoverflow
恭喜!您可以继续以下教程来探索 Quickwit 的所有特性。
TLDR
在 Quickwit 的安装目录中运行以下命令。
curl -o stackoverflow-index-config.yaml https://raw.githubusercontent.com/quickwit-oss/quickwit/main/config/tutorials/stackoverflow/index-config.yaml
./quickwit index create --index-config ./stackoverflow-index-config.yaml
curl -O https://quickwit-datasets-public.s3.amazonaws.com/stackoverflow.posts.transformed-10000.json
./quickwit index ingest --index stackoverflow --input-path ./stackoverflow.posts.transformed-10000.json --force
./quickwit index search --index stackoverflow --query "search AND engine"
./quickwit index delete --index stackoverflow
下一步教程
- [使用时间戳修剪在日志上进行搜索]/get-started/tutorials/tutorial-hdfs-logs)
- 在 AWS S3 上设置分布式搜索