Search
Search for documents matching a specific query in the given index.
This is the preferred route to perform search when an API key is required, as it allows for preflight requests to be cached. Caching preflight requests improves considerably the speed of the search.
Headers
-
Content-Type string Required
Payload content-type
Value is
application/json
.
Path parameters
-
indexUid string Required
Index Unique Identifier
Body Required
-
q string
Query string.
Default value is
""
. -
vector array
Query vector.
Default value is
null
. -
attributesToRetrieve array[string]
Array of attributes whose fields will be present in the returned documents. Defaults to the displayedAttributes list which contains by default all attributes found in the documents.
Default value is
["*"]
. -
attributesToHighlight array[string]
Array of attributes whose values will contain highlighted matching terms. Highlighted attributes are returned in
_formatted
response object.Default value is
[]
. -
highlightPreTag string
Specify the tag to put before the highlighted query terms.
Default value is
<em>
. -
highlightPostTag string
Specify the tag to put after the highlighted query terms.
Default value is
</em>
. -
attributesToCrop array[string]
Array of attributes whose values have to be cropped. Cropped attributes are returned in
_formatted
response object.Default value is
[]
. -
cropMarker string
Sets the crop marker to apply before and/or after cropped part selected within an attribute defined in
attributesToCrop
parameter.Default value is
…
. -
cropLength number
Sets the total number of words to keep for the cropped part of an attribute specified in the
attributesToCrop
parameter.Default value is
10
. -
showMatchesPosition boolean
Defines whether an
_matchesPosition
object that contains information about the matches should be returned or not.Default value is
false
. -
showRankingScore boolean
Defines whether a
_rankingScore
number representing the relevancy score of that document should be returned or not.Default value is
false
. -
showRankingScoreDetails boolean
Defines whether a
_rankingScoreDetails
object containing information about the score of that document for each ranking rule should be returned or not.Default value is
false
. -
matchingStrategy string
Defines which strategy to use to match the query terms within the documents as search results. Two different strategies are available,
last
andall
. By default, thelast
strategy is chosen.Default value is
last
. -
attributesToSearchOn array
Defines which
searchableAttributes
the query will search on.Default value is
["*"]
. - filter array[string] | string | array[array | string]
One of: Attribute(s) to filter on.
Can be made of 3 syntaxes
- Nested Array:
["something > 1", "genres=comedy", ["genres=horror", "title=batman"]]
- String:
"something > 1 AND genres=comedy AND (genres=horror OR title=batman)"
- Mixed:
["something > 1 AND genres=comedy", "genres=horror OR title=batman"]
_geoRadius({lat}, {lng}, {distance_in_meters}) and _geoBoundingBox([{lat, lng}], [{lat}, {lng}]) built-in filter rules can be used to filter documents within geo shapes.
Attribute(s) used in
filter
should be declared as filterable attributes. See Filtering and Faceted Search.Format of each should match the following pattern:
^[^:]+:[^:]+$
.Attribute(s) to filter on.
Can be made of 3 syntaxes
- Nested Array:
["something > 1", "genres=comedy", ["genres=horror", "title=batman"]]
- String:
"something > 1 AND genres=comedy AND (genres=horror OR title=batman)"
- Mixed:
["something > 1 AND genres=comedy", "genres=horror OR title=batman"]
_geoRadius({lat}, {lng}, {distance_in_meters}) and _geoBoundingBox([{lat, lng}], [{lat}, {lng}]) built-in filter rules can be used to filter documents within geo shapes.
Attribute(s) used in
filter
should be declared as filterable attributes. See Filtering and Faceted Search.Format should match the following pattern:
^[^:]+:[^:]+$
.Attribute(s) to filter on.
Can be made of 3 syntaxes
- Nested Array:
["something > 1", "genres=comedy", ["genres=horror", "title=batman"]]
- String:
"something > 1 AND genres=comedy AND (genres=horror OR title=batman)"
- Mixed:
["something > 1 AND genres=comedy", "genres=horror OR title=batman"]
_geoRadius({lat}, {lng}, {distance_in_meters}) and _geoBoundingBox([{lat, lng}], [{lat}, {lng}]) built-in filter rules can be used to filter documents within geo shapes.
Attribute(s) used in
filter
should be declared as filterable attributes. See Filtering and Faceted Search. - Nested Array:
-
facets array[string]
Array of attributes whose fields will be distributed as a facet. If you have set up filterableAttributes, you can retrieve the count of matching terms for each facets.Learn more about facet distribution in the dedicated guide
Default value is
[]
. -
offset number
Number of documents to skip.
Default value is
0
. -
limit number
Maximum number of documents returned.
Default value is
20
. -
page number
The specific search results page to fetch.
-
hitsPerPage number
Number of returned results per page.
-
sort array[string]
Fields on which you want to sort the results.
Attribute(s) used in
sort
should be declared as sortable attributes. See Sorting._geoPoint({lat}, {long}) built-in sort rule can be used to sort documents around a geo point.
curl \
-X POST https://example.meilisearch.com:7700/indexes/movies/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"q":"Harry","offset":0,"limit":20,"filter":"(genres = Horror AND genres = Mystery) OR release_date \u003e 523242000","facets":["genres","author"],"attributesToRetrieve":["title","overview"],"attributesToCrop":["overview"],"cropLength":20,"attributesToHighlight":["overview"],"showMatchesPosition":true,"showRankingScore":true,"wordsMatchingStrategy":"all","matchingStrategy":"all"}'
# Headers
Content-Type: application/json
# Payload
{
"q": "Harry",
"offset": 0,
"limit": 20,
"filter": "(genres = Horror AND genres = Mystery) OR release_date > 523242000",
"facets": [
"genres",
"author"
],
"attributesToRetrieve": [
"title",
"overview"
],
"attributesToCrop": [
"overview"
],
"cropLength": 20,
"attributesToHighlight": [
"overview"
],
"showMatchesPosition": true,
"showRankingScore": true,
"wordsMatchingStrategy": "all",
"matchingStrategy": "all"
}
{
"hits": [
{
"id": 25684,
"title": "American Ninja 5",
"poster": "https://image.tmdb.org/t/p/w1280/iuAQVI4mvjI83wnirpD8GVNRVuY.jpg",
"overview": "When a scientists daughter is kidnapped, American Ninja, attempts to find her, but this time he teams up with a youngster he has trained in the ways of the ninja.",
"release_date": 725846400,
"_formatted": {
"id": 25684,
"title": "American Ninja 5",
"poster": "https://image.tmdb.org/t/p/w1280/iuAQVI4mvjI83wnirpD8GVNRVuY.jpg",
"overview": "When a scientists daughter is kidnapped, American <em>Ninja</em>, attempts to find her, but this time he teams up with a youngster he has trained in the ways of the <em>ninja</em>.",
"release_date": 725846400
},
"_matchesPosition": {
"overview": [
{
"start": 49,
"length": 5
},
{
"start": 155,
"length": 5
}
]
}
}
],
"facetDistribution": {
"genres": {
"action": 273,
"animation": 118,
"adventure": 132,
"fantasy": 67,
"comedy": 475,
"mystery": 70,
"thriller": 217
}
},
"facetStats": {
"price": {
"min": 1,
"max": 4999.99
}
},
"limit": 0,
"offset": 0,
"estimatedTotalHits": 0,
"query": "string",
"processingTimeMs": 0
}
{
"message": "The Authorization header is missing. It must use the bearer authorization method.",
"code": "missing_authorization_header",
"type": "auth",
"link": "https://docs.meilisearch.com/errors#missing_authorization_header"
}