Skip to content

v1.16: Add sort parameter to /documents route #3318

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

Open
wants to merge 2 commits into
base: v1.16
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions reference/api/documents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Use `offset` and `limit` to browse through documents.
| **`fields`** | Array of strings/`null` | `*` | Document attributes to show (case-sensitive, comma-separated) |
| **`filter`** | String/Array of array of strings/`null` | N/A | Refine results based on attributes in the `filterableAttributes` list |
| **`retrieveVectors`** | Boolean | `false` | Return document vector data with search result |
| **`sort`** | `null` | A list of attributes written as an array or as a comma-separated string |

| **`ids`** | Array of primary keys | `null` | Return documents based on their primary keys |

<Note>
Expand Down Expand Up @@ -137,6 +139,7 @@ Using the query parameters `offset` and `limit`, you can browse through all your
| **`fields`** | `*` | Document attributes to show (case-sensitive, comma-separated) |
| **`filter`** | N/A | Refine results based on attributes in the `filterableAttributes` list |
| **`retrieveVectors`** | `false` | Return document vector data with search result |
| **`sort`** | `null` | A list of comma-separated attributes |
| **`ids`** | `null` | Return documents based on their primary keys |

### Response
Expand Down
8 changes: 8 additions & 0 deletions reference/errors/error_codes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ The [`limit`](/reference/api/documents#query-parameters) parameter is invalid. I

The [`offset`](/reference/api/documents#query-parameters) parameter is invalid. It should be an integer.

## `invalid_document_sort`

This error occurs if:

- The syntax for the [`sort`](/reference/api/documents#body) parameter is invalid
- The attribute used for sorting is not defined in the [`sortableAttributes`](/reference/api/settings#sortable-attributes) list or the `sort` ranking rule is missing from the settings
- A reserved keyword like `_geo`, `_geoDistance`, `_geoRadius`, or `_geoBoundingBox` is used as a filter

## `invalid_document_geo_field`

The provided `_geo` field of one or more documents is invalid. Meilisearch expects `_geo` to be an object with two fields, `lat` and `lng`, each containing geographic coordinates expressed as a string or floating point number. Read more about `_geo` and how to troubleshoot it in [our dedicated guide](/learn/filtering_and_sorting/geosearch).
Expand Down
2 changes: 1 addition & 1 deletion snippets/samples/code_samples_add_movies_json_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ file, _ := os.ReadFile("movies.json")
var movies interface{}
json.Unmarshal([]byte(file), &movies)

client.Index("movies").AddDocuments(&movies)
client.Index("movies").AddDocuments(&movies, nil)
```

```csharp C#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ documents := []map[string]interface{}{
"release_date": "2019-03-23",
},
}
client.Index("movies").AddDocuments(documents)
client.Index("movies").AddDocuments(documents, nil)
```

```csharp C#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ documents := []map[string]interface{}{
"genres": "comedy",
},
}
client.Index("movies").UpdateDocuments(documents)
client.Index("movies").UpdateDocuments(documents, nil)
```

```csharp C#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ client.index('games').update_filterable_attributes(['release_timestamp'])
```

```go Go
filterableAttributes := []string{"release_timestamp"}
filterableAttributes := []interface{}{"release_timestamp"}
client.Index("games").UpdateFilterableAttributes(&filterableAttributes)
```

Expand Down
2 changes: 1 addition & 1 deletion snippets/samples/code_samples_date_guide_index_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ byteValue, _ := io.ReadAll(jsonFile)
var games []map[string]interface{}
json.Unmarshal(byteValue, &games)

client.Index("games").AddDocuments(games)
client.Index("games").AddDocuments(games, nil)
```

```csharp C#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ client.index('products').update_filterable_attributes([
```

```go Go
filterableAttributes := []string{
filterableAttributes := []interface{}{
"product_id",
"sku",
"url",
Expand Down
1 change: 1 addition & 0 deletions snippets/samples/code_samples_facet_search_3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ client.index('books').facet_search('genres', 'c')
client.Index("books").FacetSearch(&meilisearch.FacetSearchRequest{
FacetQuery: "c",
FacetName: "genres",
ExhaustiveFacetCount: true
})
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ client.index('movie_ratings').update_filterable_attributes(['genres', 'rating',
```

```go Go
filterableAttributes := []string{
filterableAttributes := []interface{}{
"genres",
"rating",
"language",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ client.index('movies').update_filterable_attributes([
```

```go Go
resp, err := client.Index("movies").UpdateFilterableAttributes(&[]string{
resp, err := client.Index("movies").UpdateFilterableAttributes(&[]interface{}{
"director",
"genres",
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ client.index('restaurants').update_filterable_attributes(['_geo'])
```

```go Go
filterableAttributes := []string{
filterableAttributes := []interface{}{
"_geo",
}
client.Index("restaurants").UpdateFilterableAttributes(&filterableAttributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func main() {
var movies []map[string]interface{}
json.Unmarshal(byteValue, &movies)

_, err := client.Index("movies").AddDocuments(movies)
_, err := client.Index("movies").AddDocuments(movies, nil)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -192,7 +192,7 @@ namespace Meilisearch_demo
```text Rust
// In your .toml file:
[dependencies]
meilisearch-sdk = "0.29.0"
meilisearch-sdk = "0.29.1"
# futures: because we want to block on futures
futures = "0.3"
# serde: required if you are going to use documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ byteValue, _ := io.ReadAll(jsonFile)
var meteorites []map[string]interface{}
json.Unmarshal(byteValue, &meteorites)

client.Index("meteorites").AddDocuments(meteorites)
client.Index("meteorites").AddDocuments(meteorites, nil)
```

```csharp C#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ documents := []map[string]interface{}{
{ "id": 5, "title": "Moana" },
{ "id": 6, "title": "Philadelphia" },
}
client.Index("movies").AddDocuments(documents)
client.Index("movies").AddDocuments(documents, nil)
```

```csharp C#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ documents := []map[string]interface{}{
"price": 5.00,
},
}
client.Index("books").AddDocuments(documents, "reference_number")
refrenceNumber := "reference_number"
client.Index("books").AddDocuments(documents, &refrenceNumber)
```

```csharp C#
Expand Down
6 changes: 6 additions & 0 deletions snippets/samples/code_samples_typo_tolerance_guide_5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ $client->index('movies')->updateTypoTolerance([
'disableOnNumbers' => true
]);
```

```go Go
client.Index("movies").UpdateTypoTolerance(&meilisearch.TypoTolerance{
DisableOnNumbers: true
})
```
</CodeGroup>
22 changes: 21 additions & 1 deletion snippets/samples/code_samples_update_filterable_attributes_1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,29 @@ client.index('movies').update_filterable_attributes([
```

```go Go
filterableAttributes := []string{
filterableAttributes := []interface{}{
"genres",
"director",
AttributeRule{
AttributePatterns: []string{"tag"}
Features: AttributeFeatures{
FacetSearch: false,
Filter: FilterFeatures{
Equality: true,
Comparison: false,
}
}
},
map[string]interface{}{
"attributePatterns": []interface{}{"year"}
"features": map[string]interface{}{
"facetSearch": false,
"filter": map[string]interface{}{
"equality": true,
"comparison": true,
}
}
}
}
client.Index("movies").UpdateFilterableAttributes(&filterableAttributes)
```
Expand Down