---
title: "Search"
method: POST
path: "/api/search-wrapper"
tags: ["Misc"]
---

# Search

`POST /api/search-wrapper`

An [elastic search](https://www.elastic.co/guide/en/elasticsearch/reference/current/) endpoint for Sefaria's data. Given a properly formated POST request this endpoint will return search results for appropriate Sefaria records.

## Request body

- SearchPOSTData
  - `aggs` string[] — List of fields to aggregate on. Common fields are `path` for the `text` type and `group` or `topics` for the `sheet` type
  - `field` string — The field you want to query. Common fields to query are `exact` or `naive_lemmatizer` for the `text` and `merged` indices. For querying the `sheet` index, commonly you'll query the `content` field
  - `filter_fields` unknown[] — Must be the same length as `filters`. Each entry specifies the field to apply the corresponding filter in `filters`. For queries of type `text` this has no effect since there's only one field to filter text queries on (`path`. this field is explained in `filters`). For `sheet` queries, the following fields can appear in `filter_fields`: `collections` (corresponds to the collections that the sheet is in), `topics_en` (corresponds to the topics for this sheet, translated into English), `topics_he` (corresponds to the topics for this sheet, translated into Hebrew).
    - unknown
  - `filters` unknown[] — A list of filters to filter results. These filters cannot include RegEx. Any RegEx characters will be escaped. Each filter is applied to the corresponding field in the `filter_fields` list. E.g. if filters is `["Passover", "Torah Talks"]` and `filter_fields` is `["topics_en", "collections"]` then the `"Passover"` filter will be applied to the `"topics_en"` field and the `"Torah Talks"` filter will be applied to the `"collections"` field. For `text` queries, filters always applies to the `path` field of documents. This essentially corresponds to the category path of the book in Sefaria's table of contents (there are some differences with regards to commentary paths). For `sheet` queries, filters can be applied to `collections`, `topics_en` or `topics_he`. These fields are explained in `filter_fields` param.
    - unknown
  - `query` string — Your search query.
  - `size` integer — For paginating results. The total number of results to return, starting from `start`
  - `slop` integer — The maximum distance between each query word in the resulting document. `0` means an exact match must be found
  - `sort_fields` string[] — List of fields to sort on. If `sort_method = 'score'` this list should have exactly one item. Common fields to sort on are `comp_date` (which list results from titles published chronologically), `order` (which list results based on Sefaria's table of contents structure), `pagesheetrank` (most relevant results based on the Sheet Rank algorithm), `dateCreated` (for sheet results returned chronologically), `views` (for sheet results based on popularity).
  - `sort_method` 'sort' | 'score' — How to sort results. If sort, the values are sorted according to `sort_fields`. If `score`, the value in `sort_fields` is multiplied with the default ElasticSearch score.
  - `sort_reverse` boolean — Whether or not to reverse the sort applied on `sort_fields`
  - `sort_score_missing` number, double — The number used in case there is a value missing in your `sort_field`
  - `source_proj` boolean — By default, the ElasticSearch document is not returned. Specifying `true` will return the entire document. Specifying a `str` or `list(str)` will perform a projection on the document for the specified fields
  - `type` 'text' | 'sheet' — The ElasticSearch index you want to query, and the results you expect to get back. `sheet` returns results from Sefaria's user generated source sheets, while `text` returns results from the library.

## Response `200`

Successful Response

- SearchResponse
  - `took` integer
  - `timed_out` boolean
  - `_shards` object
    - `total` integer
    - `successful` integer
    - `skipped` integer
    - `failed` integer
  - `hits` object
    - `total` integer
    - `max_score` number, double
    - `hits` object[]
      - `_index` string
      - `_type` string
      - `_id` string
      - `_score` number, double
      - `_source` object
        - `ref` string
        - `heRef` string
        - `version` string
        - `lang` string
        - `version_priority` integer
        - `titleVariants` string[]
        - `categories` string[]
        - `order` string
        - `path` string
        - `pagesheetrank` number, double
        - `comp_date` integer
        - `exact` string
        - `naive_lemmatizer` string
        - `hebrew_version_title` string
      - `highlight` object
        - `naive_lemmatizer` string[]
  - `aggregations` object
    - `path` object
      - `doc_count_error_upper_bound` integer
      - `sum_other_doc_count` integer
      - `buckets` object[]
        - `key` string
        - `doc_count` integer

---

[API](https://skmtc.net/sefaria/apis/sefaria-api.md) · [All operations](https://skmtc.net/sefaria/apis/sefaria-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/sefaria/sefaria-api/revisions/d29296717011/schema)
