Getting Started: Search by Tenant or Knowledge Base
You can isolate and search data by tenant or by knowledge base without maintaining a separate index for each one. This example uses one Collection (a dataset with a unified field definition) to manage two tenants. The tenants map to two Slices (business data partitions), tenant-a and tenant-b, and you specify the tenant through _slice when you write and query data. In this example, the Slice names are tenant IDs. You can also name a Slice after another business identifier, such as a knowledge base. Selecting a data scope by business identifier is called namespace mode (exact), which is the default mode; Step 3 describes when to use other query scopes.
Applications access data through the Collection name and the business Slice name. A Slice limits the data scope; it is not an account permission boundary. Your application must still verify tenant identities and authorize access.
To complete your first search, you only need to create a Collection → write data → query the data. The following sections mark three tasks as optional: pre-creating Backings (the underlying indexes that store your documents), registering Slices in advance, and warming up the cache. Before you onboard tenants in batches, pre-create Backings and register Slices. If first-query latency matters to you, warm up the cache first.
Prepare an instance
You need an available Agent engine instance. If you have not created one, first complete Create an Agent engine instance. Run the requests in this topic in Kibana Dev Tools. The account that you use needs Collection management and data read and write permissions. For more information, see Collection permissions.
Step 1: Create a collection
Create the Collection knowledge-chunks to define fields such as the tenant identifier, title, body, and vector in one place. You can use the sample vectors as-is for a trial. When you connect a real workload, make sure that the vector dimensions and the similarity metric match your model.
PUT /_slice_collection/knowledge-chunks
{
"max_slices_per_shard": 200,
"settings": {
"index.number_of_shards": 2,
"index.number_of_replicas": 2
},
"mappings": {
"properties": {
"tenant_id": { "type": "keyword" },
"document_id": { "type": "keyword" },
"title": { "type": "text" },
"content": { "type": "text" },
"category": { "type": "keyword" },
"updated_at": { "type": "date" },
"embedding": {
"type": "dense_vector",
"dims": 4,
"index": true,
"similarity": "cosine",
"index_options": {
"type": "bbq_disk"
}
}
}
}
}Verify that the response returns acknowledged: true, which indicates that the Collection configuration is created.
The system stores documents in Backings (underlying indexes), and one Backing can hold multiple Slices. max_slices_per_shard controls how many new Slices each Backing accepts. A smaller value makes new Slices start using other Backings sooner. This parameter does not limit the number of documents in a single Slice. For capacity calculations, see How capacity parameters take effect.
Pre-create Backings (optional, recommended)
You can skip this step for a first trial because the system creates Backings on demand. Before you onboard tenants in batches or import data, prepare 5 Backings. Pre-creating Backings reduces the wait for index creation during the first write and spreads the data of new tenants across multiple underlying indexes, which helps distribute read and write loads:
PUT /_slice_collection/knowledge-chunks/backings?count=5Verify that the response returns acknowledged: true and that backings lists 5 names. Running the request again checks and completes the same set of indexes; existing data is not redistributed as a result. In a production environment, adjust the count based on your data volume and shard resources. For the parameters and allocation rules, see Pre-create Backings.
Register slices in advance (optional)
By default, a Slice is registered automatically on the first write. Registering the business partitions in advance when you onboard tenants removes the registration wait from the first business write:
PUT /_slice_collection/knowledge-chunks/slices
{
"slices": ["tenant-a", "tenant-b"]
}Verify that the top-level errors is false and that each items[].result is created or noop. created means a new registration, and noop means the Slice already exists and needs no change. If an item is failed, resolve its error before you write data.
Step 2: Write data
Do not passrefreshfor regular writes, and do not call_refreshin application code. These operations can significantly increase the overhead of data publication, object storage reads, and query node refreshes. Use refresh=wait_for only at an infrequent synchronization point, and review Applicable conditions and costs first.
Bulk write
Use one Bulk request to write two documents for each tenant. The two tenants use the same _id values but different document content. This verifies that _idonly needs to be unique within the same Slice. Documents that share an ID across different Slices do not overwrite each other.
POST /_bulk
{ "index": { "_index": "knowledge-chunks", "_id": "chunk-1001", "_slice": "tenant-a" } }
{ "tenant_id": "tenant-a", "document_id": "doc-refund-policy", "title": "Refund and return policy", "content": "You can request a refund for a duplicate purchase within seven days after the order is completed.", "category": "after-sales", "updated_at": "2026-07-30T10:00:00Z", "embedding": [0.82, 0.10, 0.05, 0.03] }
{ "index": { "_index": "knowledge-chunks", "_id": "chunk-1001", "_slice": "tenant-b" } }
{ "tenant_id": "tenant-b", "document_id": "doc-shipping-status", "title": "Track shipping status", "content": "Open the shipping information on the order details page to view the latest delivery status.", "category": "shipping", "updated_at": "2026-07-30T10:01:00Z", "embedding": [0.12, 0.78, 0.06, 0.04] }
{ "index": { "_index": "knowledge-chunks", "_id": "chunk-1002", "_slice": "tenant-a" } }
{ "tenant_id": "tenant-a", "document_id": "doc-change-address", "title": "Change the shipping address", "content": "Before the order is shipped, you can change the shipping address on the order details page.", "category": "orders", "updated_at": "2026-07-30T10:02:00Z", "embedding": [0.75, 0.16, 0.06, 0.03] }
{ "index": { "_index": "knowledge-chunks", "_id": "chunk-1002", "_slice": "tenant-b" } }
{ "tenant_id": "tenant-b", "document_id": "doc-invoice", "title": "Request electronic invoicing", "content": "After the order is completed, you can request electronic invoicing on the invoice management page.", "category": "billing", "updated_at": "2026-07-30T10:03:00Z", "embedding": [0.18, 0.70, 0.08, 0.04] }Bulk uses the NDJSON format. Each operation and each document occupies one line, and the request body must end with a newline character. In a Bulk request, _slice is part of the action metadata; in single-document and query requests, it is a URL query parameter. Verify that the top-level errors in the response is false. If some operations fail, inspect the errors in items one by one and resolve them before you continue.
The _index value in a write response may be an underlying index name that matches .sc-*. The _routing value in a read or query response may be a system-generated internal Slice identifier (slice_uid) that differs from the business Slice name you passed. This is expected. Keep using business names such as knowledge-chunks and tenant-a in subsequent requests. Do not treat these internal values as the Collection name or the _slice parameter, and do not parse their format.
Verify writes by ID (optional)
GET reads data in real time by default, so you normally do not need to wait for a search refresh. Read chunk-1001 from each tenant:
GET /knowledge-chunks/_doc/chunk-1001?_slice=tenant-aGET /knowledge-chunks/_doc/chunk-1001?_slice=tenant-bThe found field should be true in both responses, and the titles should be "Refund and return policy" and "Track shipping status". This confirms that documents with the same ID are stored separately in the two Slices. For the read behavior when the primary shard is unavailable, see Verify a write by ID.
Step 3: Query data within a tenant
After the write succeeds, wait about 5 seconds for the automatic background refresh to make the data searchable, and then run the warm-up or the query. If the results do not include the new data yet, use the real-time GET request in Verify writes by ID (Step 2) to confirm that the document exists. Then wait for one more automatic refresh cycle and retry. The actual time until data becomes searchable also depends on the load; 5 seconds is not a completion deadline.
Warm up the Slice to query (optional, recommended)
A warm-up reduces the wait for cold data to load from object storage during the first query. The next query targets tenant-a, so you can first load its searchable data into the query node cache for subsequent queries to reuse. This example waits synchronously so that the result is easy to observe:
POST /knowledge-chunks/_warm_slice?_slice=tenant-a&wait_for_completion=true&timeout=60sVerify that the request succeeds and _shards.failed is 0. This example has already written data, so _shards.total=0 is unexpected. If you do see that value, first confirm that the query shards are available, use an actual query to confirm that the data is searchable, and then retry the warm-up as needed. If a timeout or shard failure occurs, inspect the error before you retry. A warm-up covers only the data that is already searchable at that time and does not include data added later.
In a production environment, warm up data asynchronously in advance at predictable access points, such as when a user selects a knowledge base, and control the concurrency. Subsequent queries then reuse the cache, so you do not need to wait for a warm-up on every query. An asynchronous ACCEPTED response only means that the request is submitted. For how to determine the result, see Determine the result of an asynchronous warm-up.
Run a vector search
Query only the documents in tenant-a and return the fields used for business display and scope verification:
POST /knowledge-chunks/_search?_slice=tenant-a
{
"knn": {
"field": "embedding",
"query_vector": [0.80, 0.12, 0.05, 0.03],
"k": 10,
"num_candidates": 100
},
"_source": ["tenant_id", "document_id", "title", "content"]
}Verify that timed_out is false and _shards.failed is 0. The results should include "Refund and return policy" and "Change the shipping address", and the tenant_id of every result should be tenant-a. After you change _slice in the URL to tenant-b, the results should be "Track shipping status" and "Request electronic invoicing". The two tenants use the same document IDs, so verify the scope by the tenant field and the title instead of comparing IDs only.
tenant_id is a regular field used for display and verification; the actual query scope is determined by _slice. Namespace mode requires an explicit scope by default, and omitting _slice returns an error. Do not use _slice=_all for regular business queries. For the applicable conditions of multi-Slice and full-data queries, see Specify the query scope. A regular search does not need to retrieve vector values; the server performs the KNN calculation.
What to do next
Batch tenant onboarding, capacity, and lifecycle management: Collection management.
Single-document writes, bulk reads, and query development: Read and write data.
Vector search quality: Tune vector search results.
Before you go live, review Limits and configure monitoring and permissions as described in Collection permissions.
Cluster selection after offline clustering is complete: Automatically select candidate clusters.