Skip to content

update documents.md #1630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 9, 2022
10 changes: 0 additions & 10 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,6 @@ add_movies_json_1: |-
-X POST 'http://127.0.0.1:7700/indexes/movies/documents'\
-H 'Content-Type: application/json' \
--data-binary @movies.json
documents_guide_add_movie_1: |-
curl \
-X POST `http://localhost:7700/indexes/movies/documents` \
-H 'Content-Type: application/json' \
--data-binary '[
{
"movie_id": "123sq178",
"title": "Amelie Poulain"
}
]'
getting_started_add_documents_md: |-
```bash
curl \
Expand Down
1 change: 0 additions & 1 deletion .vuepress/public/sample-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ settings_guide_distinct_1: |-
settings_guide_searchable_1: |-
settings_guide_displayed_1: |-
settings_guide_sortable_1: |-
documents_guide_add_movie_1: |-
getting_started_add_documents_md: |-
getting_started_search_md: |-
getting_started_check_task_status: |-
Expand Down
10 changes: 8 additions & 2 deletions learn/advanced/known_limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ This guide covers hard limits that cannot be altered. Meilisearch also has some

## Maximum number of query words

**Limitation:** The maximum number of terms taken into account for each [search query](/reference/api/search.md#query-q) is 10. **If a search query includes more than 10 words, all words after the 10th will be ignored.**
**Limitation:** The maximum number of terms taken into account for each [search query](/reference/api/search.md#query-q) is 10. If a search query includes more than 10 words, all words after the 10th will be ignored.

**Explanation:** Queries with many search terms can lead to long response times. This goes against our goal of providing a [fast search-as-you-type experience](/learn/what_is_meilisearch/philosophy.md#front-facing-search).

## Maximum number of document fields

**Limitation:** Documents have a soft maximum of 1000 fields.

**Explanation:** There is no limit on how many fields a document can have. However, documents with more than 1000 fields may cause the [ranking rules](/learn/core_concepts/relevancy.md#ranking-rules) to stop working, leading to undefined behavior.

## Maximum number of words per attribute

**Limitation:** Meilisearch can index a maximum of **65535 positions per attribute**. Any words exceeding the 65535 position limit will be silently ignored.
**Limitation:** Meilisearch can index a maximum of 65535 positions per attribute. Any words exceeding the 65535 position limit will be silently ignored.

**Explanation:** This limit is enforced for relevancy reasons. The more words there are in a given attribute, the less relevant the search queries will be.

Expand Down
135 changes: 51 additions & 84 deletions learn/core_concepts/documents.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Documents

A **document** is an object composed of one or more **fields**. Each field consists of an **attribute** and its associated **value**.

Documents function as **containers for organizing data**, and are the basic building blocks of a Meilisearch database. To search for a document, it must first be added to an [index][indexes].
A document is an object composed of one or more fields. Each field consists of an **attribute** and its associated **value**. Documents function as containers for organizing data, and are the basic building blocks of a Meilisearch database. To search for a document, you must first add it to an [index](/learn/core_concepts/indexes.md).

## Structure

Expand All @@ -11,28 +9,64 @@ Documents function as **containers for organizing data**, and are the basic buil
### Important terms

- **Document**: an object which contains data in the form of one or more fields
- **[Field][fields]**: a set of two data items that are linked together: an **attribute** and a **value**
- **Attribute**: the first part of a field. Acts as a name or description for its associated value.
- **[Field](#fields)**: a set of two data items that are linked together: an attribute and a value
- **Attribute**: the first part of a field. Acts as a name or description for its associated value
- **Value**: the second part of a field, consisting of data of any valid JSON type
- **[Primary Field][primary-field]**: A special field that is mandatory in all documents. It contains the primary key and document identifier.
- **[Primary Key][primary-key]**: the attribute of the primary field. **All documents in the same index must possess the same primary key.** Its associated value is the document identifier.
- **[Document Identifier][document-id]**: the value of the primary field. **Every document in a given index must have a unique identifier**.
- **[Primary Field](#primary-field)**: a special field that is mandatory in all documents. It contains the primary key and document identifier

## Fields

A field is a set of two data items linked together: an attribute and a value. Documents are made up of fields.

An attribute functions a bit like a variable in most programming languages, i.e., it is a name that allows you to store, access, and describe some data. That data is the attribute's value. In the case of strings, a value **[can contain at most 65535 positions](/learn/advanced/known_limitations.md#maximum-number-of-words-per-attribute)**. Words exceeding the 65535 position limit will be ignored.

Every field has a data type dictated by its value. Every value must be a valid [JSON data type](https://www.w3schools.com/js/js_json_datatypes.asp).

If a field contains an object, Meilisearch flattens it during indexation using dot notation and brings the object's keys and values to the root level of the document itself. This flattened object is only an intermediary representation—you will get the original structure upon search. You can read more about this in our [dedicated guide](/learn/advanced/datatypes.md#objects).

With [ranking rules](/learn/core_concepts/relevancy.md#ranking-rules), you can decide what fields are more relevant than others. For example, you may decide recent movies should be more relevant than older ones. You can also configure how Meilisearch handles certain fields at an [index level](/learn/configuration/settings.md) in the settings.

### Displayed and searchable fields

By default, all fields in a document are both displayed and searchable. Displayed fields are contained in each matching document, while searchable fields are searched for matching query words.

You can modify this behavior using the [update settings endpoint](/reference/api/settings.md#update-settings), or the respective update endpoints for [displayed attributes](/reference/api/displayed_attributes.md#update-displayed-attributes), and [searchable attributes](/reference/api/searchable_attributes.md#update-searchable-attributes) so that a field is:

- Searchable but not displayed
- Displayed but not searchable
- Neither displayed nor searchable

In the latter case, the field will be completely ignored during search. However, it will still be [stored](/learn/configuration/displayed_searchable_attributes.md#data-storing) in the document.

## Primary field

The primary field is a special field that must be present in all documents. Its attribute is the [primary key](/learn/core_concepts/primary_key.md#primary-key-2) and its value is the [document id](/learn/core_concepts/primary_key.md#document-id). If you try to [index a document](/learn/getting_started/quick_start.md#add-documents) that's missing a primary key or possessing the wrong primary key for a given index, it will cause an error and no documents will be added.

To learn more, refer to the [primary key explanation](/learn/core_concepts/primary_key.md).

## Upload

By default, Meilisearch limits the size of all payloads—and therefore document uploads—to 100MB. You can [change the payload size limit](/learn/configuration/instance_options.md#payload-limit-size) at runtime using the `http-payload-size-limit` option.

Meilisearch uses a lot of RAM when indexing documents. Be aware of your [RAM availability](/resources/faq.md#what-are-the-recommended-requirements-for-hosting-a-meilisearch-instance) as you increase your batch size as this could cause Meilisearch to crash.

When using the [add new documents endpoint](/reference/api/documents.md#add-or-update-documents), all documents must be sent in an array even if there is only one document.

### Dataset format

You can provide your dataset in the following formats:
Meilisearch accepts datasets in the following formats:

- [JSON](#json)
- [NDJSON](#ndjson)
- [CSV](#csv)

#### JSON

Documents represented as JSON objects are key-value pairs enclosed by curly brackets. As such, [any rule that applies to formatting JSON objects](https://www.w3schools.com/js/js_json_objects.asp) also applies to formatting Meilisearch documents. For example, **an attribute must be a string**, while **a value must be a valid [JSON data type](https://www.w3schools.com/js/js_json_datatypes.asp)**.
Documents represented as JSON objects are key-value pairs enclosed by curly brackets. As such, [any rule that applies to formatting JSON objects](https://www.w3schools.com/js/js_json_objects.asp) also applies to formatting Meilisearch documents. For example, an attribute must be a string, while a value must be a valid [JSON data type](https://www.w3schools.com/js/js_json_datatypes.asp).

Meilisearch will only accept JSON documents when it receives the `application/json` content-type header.

As an example, let's say you are creating an **[index][indexes]** that contains information about movies. A sample document might look like this:
As an example, let's say you are creating an index that contains information about movies. A sample document might look like this:

```json
{
Expand All @@ -47,9 +81,11 @@ As an example, let's say you are creating an **[index][indexes]** that contains
}
```

In the above example, `"id"`, `"title"`, `"genres"`, `"release-year"`, and `"cast"` are **attributes**.
Each attribute must be associated with a **value**, e.g. `"Kung Fu Panda"` is the value of `"title"`.
At minimum, the document must contain one field with the **[primary key][primary-key]** attribute and a unique **[document id][document-id]** as its value. Above, that's: `"id": 1564`.
In the above example:

- `"id"`, `"title"`, `"genres"`, `"release-year"`, and `"cast"` are attributes
- Each attribute is associated with a value, e.g. `"Kung Fu Panda"` is the value of `"title"`
- The document contains a field with the primary key attribute and a unique document id as its value: `"id": "1564saqw12ss"`

#### NDJSON

Expand Down Expand Up @@ -82,75 +118,6 @@ The above JSON document would look like this in CSV:

Since CSV does not support arrays or nested objects, `cast` cannot be converted to CSV.

::: tip
::: note
If you don't specify the data type for an attribute, it will default to `:string`.
:::

### Limitations and requirements

Documents have a **soft maximum of 1000 fields**; beyond that the [ranking rules](/learn/core_concepts/relevancy.md#ranking-rules) may no longer be effective, leading to undefined behavior.

Additionally, every document must have at minimum one field containing the **[primary key][primary-key]** and a **[unique id][document-id]**.

If you try to [index a document](/learn/getting_started/quick_start.md#add-documents) that's incorrectly formatted, missing a primary key, or possessing the [wrong primary key for a given index](/learn/core_concepts/indexes.md#primary-key), it will cause an error and no documents will be added.

## Fields

A field is a set of two data items linked together: an attribute and a value. Documents are made up of fields.

An attribute functions a bit like a variable in most programming languages, i.e. it is a name that allows you to store, access, and describe some data. That data is the attribute's **value**.

Every field has a [data type](/learn/advanced/datatypes.md) dictated by its value. Every value must be a valid [JSON data type](https://www.w3schools.com/js/js_json_datatypes.asp).

If a field contains an object, you can refer directly to its internal properties using dot notation: `attributeA.objectKeyA`. Dot notation also works with nested objects: `attributeA.objectKeyA.objectKeyB`. This syntax is supported across Meilisearch, including index settings and search parameters.

Take note that, in the case of strings, a value **[can contain at most 65535 positions](/learn/advanced/known_limitations.md#maximum-number-of-words-per-attribute). Words exceeding the 65535 position limit will be ignored.**

You can also apply [ranking rules](/learn/core_concepts/relevancy.md#ranking-rules) to some fields. For example, you may decide recent movies should be more relevant than older ones.

If you would like to adjust how a field gets handled by Meilisearch, you can do so in the [settings](/learn/configuration/settings.md).

### Field properties

A field may also possess **[field properties](/learn/configuration/displayed_searchable_attributes.md)**. Field properties determine the characteristics and behavior of the data added to that field.

At this time, there are two field properties: [searchable](/learn/configuration/displayed_searchable_attributes.md#searchable-fields) and [displayed](/learn/configuration/displayed_searchable_attributes.md#displayed-fields). A field can have one, both, or neither of these properties. **By default, all fields in a document are both displayed and searchable.**

To clarify, a field may be:

- Searchable but not displayed
- Displayed but not searchable
- Both displayed and searchable (default)
- Neither displayed nor searchable

In the latter case, the field will be completely ignored when a search is performed. However, it will still be [stored](/learn/configuration/displayed_searchable_attributes.md#data-storing) in the document.

## Primary field

The primary field is a special field that must be present in all documents. Its attribute is the [primary key](/learn/core_concepts/primary_key.md#primary-key-2) and its value is the [document id](/learn/core_concepts/primary_key.md#document-id).

To learn more, refer to the [primary key explanation](/learn/core_concepts/primary_key.md).

## Upload

By default, Meilisearch limits the size of all payloads—and therefore document uploads—to 100MB.

To upload more documents in one go, it is possible to [change the payload size limit](/learn/configuration/instance_options.md#payload-limit-size) at runtime using the `http-payload-size-limit` option.

```bash
./meilisearch --http-payload-size-limit=1048576000
```

The above code sets the payload limit to 1GB, instead of the 100MB default.

**Meilisearch uses a lot of RAM when indexing documents**. Be aware of your [RAM availability](/resources/faq.md#what-are-the-recommended-requirements-for-hosting-a-meilisearch-instance) as you increase the size of your batch as this could cause Meilisearch to crash.

When using the [route to add new documents](/reference/api/documents.md#add-or-update-documents), all documents must be sent in an array **even if there is only one document**.

<CodeSamples id="documents_guide_add_movie_1" />

[primary-field]: /learn/core_concepts/documents.md#primary-field
[primary-key]: /learn/core_concepts/primary_key.md#primary-key-2
[document-id]: /learn/core_concepts/primary_key.md#document-id
[fields]: /learn/core_concepts/documents.md#fields
[indexes]: /learn/core_concepts/indexes.md
4 changes: 4 additions & 0 deletions learn/getting_started/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ Open a new terminal window and run the following command:

Meilisearch stores data in the form of discrete records, called [documents](/learn/core_concepts/documents.md). Documents are grouped into collections, called [indexes](/learn/core_concepts/indexes.md).

::: note
Currently, Meilisearch only supports [JSON, CSV, and NDJSON formats](/learn/core_concepts/documents.md#dataset-format).
:::

The previous command added documents from `movies.json` to a new index called `movies`. After adding documents, you should receive a response like this:

```json
Expand Down