# Search a document (/reference/api/documents/search-document)

```json
[
  {
    "method": "GET",
    "path": "/api/v1/documents/{id}/search",
    "operationId": "searchDocument",
    "tags": [
      "Documents"
    ],
    "summary": "Search a document",
    "x-required-scope": "documents:read",
    "security": [
      {
        "oauth": [
          "documents:read"
        ]
      },
      {
        "sessionCookie": []
      },
      {
        "secureSessionCookie": []
      }
    ],
    "responses": {
      "200": {
        "description": "Matches in reading order. truncated is true when more matches exist than limit.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/DocumentSearchResult"
            }
          }
        }
      },
      "409": {
        "description": "DOCUMENT_PREPARING: the document is still being prepared for reading. Search again after retryAfterMs.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "429": {
        "description": "Compute admission or usage is limited.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        },
        "headers": {
          "Retry-After": {
            "description": "Seconds until retry.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        }
      },
      "default": {
        "description": "Request failed. Inspect error.code and error.message.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "description": "Searches the same reading plan the reader uses, so each match is a sentence the reader can open at. A document never opened before is prepared first, as opening it would; that work is admitted against the user's compute limits, and this request does not wait for it."
  }
]
```

## Components

```json
{
  "#/components/schemas/DocumentSearchResult": {
    "type": "object",
    "properties": {
      "truncated": {
        "type": "boolean"
      },
      "data": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "ordinal": {
              "type": "integer"
            },
            "segmentKey": {
              "type": [
                "string",
                "null"
              ],
              "description": "Content identity of the sentence the match starts in. Pass it as at= on a reader URL to open there."
            },
            "snippet": {
              "type": "string"
            },
            "matchStart": {
              "type": "integer",
              "description": "Start of the match inside snippet."
            },
            "matchEnd": {
              "type": "integer",
              "description": "End of the match inside snippet, exclusive."
            },
            "page": {
              "type": [
                "integer",
                "null"
              ],
              "description": "The PDF page the match is on; null for other formats."
            },
            "webUrl": {
              "type": "string",
              "format": "uri",
              "description": "Opens the reader at this match."
            }
          },
          "required": [
            "ordinal",
            "segmentKey",
            "snippet",
            "matchStart",
            "matchEnd",
            "page",
            "webUrl"
          ]
        }
      }
    },
    "required": [
      "truncated",
      "data"
    ]
  },
  "#/components/schemas/Error": {
    "type": "object",
    "properties": {
      "error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "retryAfterMs": {
            "type": "number",
            "minimum": 0
          }
        },
        "required": [
          "code",
          "message"
        ]
      }
    },
    "required": [
      "error"
    ]
  }
}
```