数据摄入 API
在这篇教程中,我们将介绍如何使用 Ingest API 向 Quickwit 发送数据。
要跟随这篇教程,您需要有一个本地的 Quickwit 实例正在运行。
要启动它,请在终端中运行 ./quickwit run
。
Create an index(创建索引)
首先,我们 创建一个无模式的索引。
# Create the index config file.
cat << EOF > stackoverflow-schemaless-config.yaml
version: 0.7
index_id: stackoverflow-schemaless
doc_mapping:
mode: dynamic
indexing_settings:
commit_timeout_secs: 30
EOF
# Use the CLI to create the index...
./quickwit index create --index-config stackoverflow-schemaless-config.yaml
# Or with cURL.
curl -XPOST -H 'Content-Type: application/yaml' 'http://localhost:7280/api/v1/indexes' --data-binary @stackoverflow-schemaless-config.yaml
Ingest data(摄取数据)
让我们先下载 StackOverflow 数据集的一个样本。
# Download the first 10_000 Stackoverflow posts articles.
curl -O https://quickwit-datasets-public.s3.amazonaws.com/stackoverflow.posts.transformed-10000.json
您可以使用命令行界面或 cURL 来发送数据。命令行界面对于发送几 GB 的数据更为方便,因为当 Ingest 队列已满时,Quickwit 可能会返回 429
响应。在这种情况下,Quickwit 命令行界面将自动重试发送。
# Ingest the first 10_000 Stackoverflow posts articles with the CLI...
./quickwit index ingest --index stackoverflow-schemaless --input-path stackoverflow.posts.transformed-10000.json --force
# OR with cURL.
curl -XPOST -H 'Content-Type: application/json' 'http://localhost:7280/api/v1/stackoverflow-schemaless/ingest?commit=force' --data-binary @stackoverflow.posts.transformed-10000.json
Execute search queries(执行搜索查询)
现在您可以对索引进行搜索了。
curl 'http://localhost:7280/api/v1/stackoverflow-schemaless/search?query=body:python'
Tear down resources(清理资源:可选)
curl -XDELETE 'http://localhost:7280/api/v1/indexes/stackoverflow-schemaless'
至此完成了教程。现在您可以继续阅读下一教程,了解如何从 Kafka 发送数据。