> For the complete documentation index, see [llms.txt](https://developer.emporix.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.emporix.io/api-references/readme/api-reference-33/search.md). Agents can also search and read this documentation through its [MCP server](https://developer.emporix.io/~gitbook/mcp).

# Search

## Searching documents

> !\[Preview]\(<https://res.cloudinary.com/saas-ag/image/upload/v1752824268/emporix/icons/preview\\_api1.png)\\>
> \
> {% hint style="danger" %}\
> This functionality is in preview mode - some of the features may not be fully operational yet.\
> {% endhint %}\
> \
> Searches documents of one type. The \`search.search\_read\` scope is required.\
> \
> For a direct search, the body names an index and supplies queries, a filter, or both. A list of queries matches when any query matches. An \`and\` group matches when every query matches. An \`or\` group matches when any query matches. Filters narrow the matches. The response is a JSON array of matching documents. When \`fields\` is omitted, each document also includes \`\_score\`.\
> \
> When the body contains \`searchQueryId\`, the request runs a saved search. \`query\` is required. The saved search supplies the index, the filters, and the query shape. \`query\` replaces the text of every search term. A saved search that contains only filters keeps those filters.\
> \
> When the \`X-Total-Count\` request header is \`true\`, the response includes the \`X-Total-Count\` header with the number of matching documents. The response body stays an array.\
> \
> Filter and sort fields must be indexed. For a direct search, that is the index named by \`index\`. For a saved search, that is the index stored on the saved search.\
> \
> A \`TEXT\` or \`PHRASE\` query can set \`analyzer\` to the field's analyzer or to one of its additional analyzers. When \`analyzer\` is omitted, the query uses the field's \`analyzer\`.\
> \
> \*\*Additional permissions requirements\*\*:\
> \
> \| Type | Scope requirements |\
> \| --- | --- |\
> \| \`Custom Schema Type\` | \`schema.custominstance\_read\`, \`custom.{type}\_read\`, or \`custom.{type}\_read\_own\` |\
> \| \`customer\` | \`customer.customer\_read\` or \`customer.customer\_read\_own\` |\
> \| \`legal-entity\` | \`customermanagement.legalentity\_read\` or \`customermanagement.legalentity\_read\_own\` |\
> \
> A caller without one of those scopes receives \`403 Forbidden\`.\
> \
> For \`customer\` and \`legal-entity\`, the scopes also limit which documents are returned:\
> \
> \* The unrestricted read scope, \`customer.customer\_read\` or \`customermanagement.legalentity\_read\`, returns every document.\
> \* A restricted read scope, such as \`customer.customer\_read--DE#AT\`, returns only documents whose \`restriction\` (customer) or \`restrictions\` (legal entity) contains one of the listed values. A restricted scope with no values returns \`403 Forbidden\`.\
> \* The own-read scope returns only the caller's own customer or the caller's own legal entity. When the access token does not identify that customer or legal entity, the request returns \`403 Forbidden\`.\
> \
> When a caller has both a restricted scope and the own-read scope, a document must match both.

```json
{"openapi":"3.0.0","info":{"title":"Search Service","version":"0.0.1"},"servers":[{"url":"https://api.emporix.io"}],"security":[{"OAuth2":["search.search_read"]}],"components":{"securitySchemes":{"OAuth2":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"https://api.emporix.io/oauth/token","scopes":{"search.search_read":"Needed to search documents, to read saved searches, and to read search indexes and index jobs.","search.search_manage":"Needed to create, update, and delete saved searches and search indexes.","schema.custominstance_read":"Needed to read every custom entity instance. When this scope is absent, `custom.{type}_read` or `custom.{type}_read_own` can still allow the search.","customer.customer_read":"Needed to search every customer. A restricted form such as `customer.customer_read--DE#AT` returns only customers whose `restriction` matches one of the listed values.","customer.customer_read_own":"Needed to search only the caller's own customer.","customermanagement.legalentity_read":"Needed to search every legal entity. A restricted form such as `customermanagement.legalentity_read--DE#AT` returns only legal entities whose `restrictions` contain one of the listed values.","customermanagement.legalentity_read_own":"Needed to search only the caller's own legal entity."}}}}},"parameters":{"query_pageNumber":{"name":"pageNumber","in":"query","description":"Page number to be retrieved. The number of the first page is 1.\n","schema":{"default":1,"minimum":1,"type":"integer"}},"query_pageSize":{"name":"pageSize","in":"query","description":"Number of items to be retrieved per page.","schema":{"default":60,"minimum":1,"maximum":2000,"type":"integer"}},"query_sort":{"name":"sort","in":"query","description":"List of properties used to sort the results, separated by commas. The order of properties indicates their priority in sorting.\n\nPossible values:\n\n* `{fieldName}`\n* `{fieldName}:ASC`\n* `{fieldName}:DESC`\n\nWhen the direction is omitted, the field is sorted in ascending order.\n\nFor the localized `name` field, the language can be included as `name.{language}`. When the language is omitted, the service uses the language from `Accept-Language`.\n\nWhen `sort` is omitted, results are ordered by search relevance.","schema":{"type":"string"}},"query_fields":{"name":"fields","in":"query","description":"Comma-separated list of fields to return. When the parameter is omitted, the stored document is returned.\n\n`id` selects the document identifier. `_score` selects the relevance score.","schema":{"type":"string"}},"header_Accept-Language":{"name":"Accept-Language","in":"header","required":false,"schema":{"type":"string"},"description":"List of language codes acceptable for the response.\n\n* If the header is set to a language or a list of languages, the service returns the first requested language that has a translation. Localized fields are maps with that language code as the key.\n* If the header is set to `*`, localized fields are retrieved as maps of translations, where the keys are language codes and values are the fields in their respective languages.\n* If the header is empty, localized fields are retrieved as maps containing a single translation, where the key is a language code and the value is the field in the specified language. The endpoint assumes that localized fields are to be retrieved in the tenant's default language defined in the Configuration Service.\n* If none of the requested languages has a translation, the localized fields are omitted from the response.\n"},"header_X-Total-Count":{"name":"X-Total-Count","in":"header","required":false,"description":"Flag indicating whether the total count of retrieved items should be returned.","schema":{"default":false,"type":"boolean"}}},"requestBodies":{"search_POST":{"required":true,"content":{"application/json":{"schema":{"description":"A direct search or a saved search. When `searchQueryId` is present, the service runs the saved search and ignores the other properties.","anyOf":[{"$ref":"#/components/schemas/SearchRequest"},{"$ref":"#/components/schemas/SavedSearchCall"}]}}}}},"schemas":{"SearchRequest":{"type":"object","description":"Search criteria. Provide `queries`, `filters`, or both. `index` is always required. Unknown properties are ignored. Use `SavedSearchCall` instead when the body contains `searchQueryId`.\n\nA list of queries matches when any query matches. An `and` group matches when every query matches. An `or` group matches when any query matches. Filters narrow those matches and do not change the score.","properties":{"queries":{"description":"Queries to match. Use an array as shorthand for an `or` group, or an `and` group, an `or` group, or one query.\n\n`name` is localized. The search uses the field path as sent. It does not expand `name` with the `Accept-Language` value.","oneOf":[{"type":"array","items":{"$ref":"#/components/schemas/QueryNode"}},{"$ref":"#/components/schemas/QueryNode"}]},"filters":{"$ref":"#/components/schemas/FilterNode"},"index":{"type":"string","description":"Name of the index to query."}},"required":["index"],"anyOf":[{"required":["queries"]},{"required":["filters"]}]},"QueryNode":{"type":"object","description":"One query node. A node is an `and` group, an `or` group, or one query. Do not combine those forms in the same object.","properties":{"and":{"type":"array","description":"Every child must match.","items":{"$ref":"#/components/schemas/QueryNode"}},"or":{"type":"array","description":"Any child must match.","items":{"$ref":"#/components/schemas/QueryNode"}},"type":{"$ref":"#/components/schemas/SearchType"},"query":{"type":"string","description":"Text or pattern to match."},"field":{"type":"string","description":"Document field to match. `id` is stored as `_id`. A field inside `itemFields` uses its full path, such as `addresses.city`. Conditions on one list joined by `and` must match the same item. The list path itself cannot be searched."},"boost":{"type":"number","minimum":0,"exclusiveMinimum":true,"default":1,"description":"Score multiplier for matches on this field. The default is 1."},"fuzzy":{"$ref":"#/components/schemas/Fuzzy"},"analyzer":{"type":"string","description":"Optional analyzer for this clause. Allowed only when `type` is `TEXT` or `PHRASE`.\n\nThe value is the field's `analyzer`, or one name from that field's `additionalAnalyzers`. The name is not case-sensitive. When omitted, the query uses the field's `analyzer`."}}},"SearchType":{"type":"string","description":"Match mode.\n\n* `TEXT` matches the query tokens.\n* `PHRASE` matches the query as adjacent words in order.\n* `AUTOCOMPLETE` matches the index field's autocomplete mode. `PREFIX` matches the start of a word. `NGRAM` matches a character sequence inside a word.\n* `WILDCARD` matches a pattern. `*` matches any number of characters. `?` matches one character. Fuzzy matching is not supported.","enum":["TEXT","PHRASE","AUTOCOMPLETE","WILDCARD"]},"Fuzzy":{"type":"object","description":"Edit-distance matching. Supported only when `type` is `TEXT` and `enabled` is `true`.","properties":{"enabled":{"type":"boolean","description":"When `true`, matches that are one or two edits from the query are included."},"maxEdits":{"type":"integer","description":"Maximum edit distance. Required when `enabled` is `true`. Allowed values are 1 and 2.","enum":[1,2]}}},"FilterNode":{"type":"object","description":"One filter node. A node is an `and` group, an `or` group, or a comparison. Do not combine those forms in the same object.\n\nComparison fields must be indexed on the index named by `index`.","properties":{"and":{"type":"array","minItems":1,"description":"Every child must match. The group must not be empty.","items":{"$ref":"#/components/schemas/FilterNode"}},"or":{"type":"array","minItems":1,"description":"At least one child must match. The group must not be empty.","items":{"$ref":"#/components/schemas/FilterNode"}},"field":{"type":"string","description":"Document field to compare. `id` is stored as `_id`. A field inside `itemFields` uses its full path, such as `addresses.city`. Conditions on one list joined by `and` must match the same item. A lone `NEQ`, `NOT_IN`, or `EXISTS` `false` on a list excludes the document when any item matches the value. A document with no items in that list matches. The same operator joined by `and` with another condition on that list still applies to one item. The list path itself cannot be searched."},"operator":{"$ref":"#/components/schemas/FilterOperator"},"value":{"description":"Comparison value. The shape depends on `operator`.\n\n* `EQ`, `NEQ`, `GT`, `GTE`, `LT`, and `LTE` require one value.\n* `BETWEEN` requires an array of two values. The range is inclusive.\n* `IN` and `NOT_IN` require a non-empty array.\n* `EXISTS` requires a boolean. `true` matches documents where the field is present. `false` matches documents where the field is absent.\n* `CONTAINS` requires a non-blank string. The field must have `text: true` in the index."}}},"FilterOperator":{"type":"string","description":"Comparison applied to `field` and `value`.\n\n`CONTAINS` performs a case- and diacritic-insensitive substring match. The service wraps the value in `*` and escapes `\\`, `*`, and `?` within it. Spaces remain part of the value.","enum":["EQ","NEQ","GT","GTE","LT","LTE","BETWEEN","IN","NOT_IN","EXISTS","CONTAINS"]},"SavedSearchCall":{"type":"object","description":"Runs one saved search. Use this shape when `searchQueryId` is present. The saved search supplies the index, the filters, and the query shape. `query` replaces the text of every search term. A saved search that contains only filters keeps those filters.","properties":{"query":{"type":"string","minLength":1,"description":"Text applied to every search term in the saved search. The value must not be blank."},"searchQueryId":{"type":"string","description":"Id of the saved search for this type."}},"required":["query","searchQueryId"]},"SearchHit":{"type":"object","description":"A matching document. Stored fields are returned with their API names. The identifier is `id`.\n\nThe `name` is localized. Other stored fields are returned as they are stored. When `fields` limits the response, the response includes the requested fields and `id`.","properties":{"id":{"type":"string","description":"Document identifier."},"name":{"type":"object","additionalProperties":{"type":"string"},"description":"Localized name. A specific `Accept-Language` value keeps one language. `*` keeps every stored language."},"_score":{"type":"number","description":"Search relevance score. Included when `fields` is omitted, or when `fields` lists `_score`."}},"additionalProperties":true},"ErrorMessage":{"type":"object","description":"Error returned for a failed request.","properties":{"code":{"type":"integer","description":"HTTP status code."},"status":{"type":"string","description":"HTTP status code as text."},"message":{"type":"string","description":"Explanation of the failure."},"details":{"type":"array","description":"Field-level or scope-level messages, when the failure has more than one part.","items":{"type":"object","properties":{"message":{"type":"string","description":"One part of the failure."}}}}}},"ErrorMessageFault":{"type":"object","description":"Authorization error returned by the API gateway.","properties":{"fault":{"type":"object","properties":{"faultstring":{"type":"string","description":"Authorization failure."},"detail":{"type":"object","properties":{"errorcode":{"type":"string","description":"Gateway error code."}}}}}}}},"responses":{"401_resp_common":{"description":"The authorization token is invalid or has expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessageFault"}}}},"500_resp_common":{"description":"A server-side error occurred.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}}}},"paths":{"/search/{tenant}/search/{type}":{"post":{"summary":"Searching documents","operationId":"POST-search-tenant-type","tags":["Search"],"description":"![Preview](https://res.cloudinary.com/saas-ag/image/upload/v1752824268/emporix/icons/preview_api1.png)\n\n{% hint style=\"danger\" %}\nThis functionality is in preview mode - some of the features may not be fully operational yet.\n{% endhint %}\n\nSearches documents of one type. The `search.search_read` scope is required.\n\nFor a direct search, the body names an index and supplies queries, a filter, or both. A list of queries matches when any query matches. An `and` group matches when every query matches. An `or` group matches when any query matches. Filters narrow the matches. The response is a JSON array of matching documents. When `fields` is omitted, each document also includes `_score`.\n\nWhen the body contains `searchQueryId`, the request runs a saved search. `query` is required. The saved search supplies the index, the filters, and the query shape. `query` replaces the text of every search term. A saved search that contains only filters keeps those filters.\n\nWhen the `X-Total-Count` request header is `true`, the response includes the `X-Total-Count` header with the number of matching documents. The response body stays an array.\n\nFilter and sort fields must be indexed. For a direct search, that is the index named by `index`. For a saved search, that is the index stored on the saved search.\n\nA `TEXT` or `PHRASE` query can set `analyzer` to the field's analyzer or to one of its additional analyzers. When `analyzer` is omitted, the query uses the field's `analyzer`.\n\n**Additional permissions requirements**:\n\n| Type | Scope requirements |\n| --- | --- |\n| `Custom Schema Type` | `schema.custominstance_read`, `custom.{type}_read`, or `custom.{type}_read_own` |\n| `customer` | `customer.customer_read` or `customer.customer_read_own` |\n| `legal-entity` | `customermanagement.legalentity_read` or `customermanagement.legalentity_read_own` |\n\nA caller without one of those scopes receives `403 Forbidden`.\n\nFor `customer` and `legal-entity`, the scopes also limit which documents are returned:\n\n* The unrestricted read scope, `customer.customer_read` or `customermanagement.legalentity_read`, returns every document.\n* A restricted read scope, such as `customer.customer_read--DE#AT`, returns only documents whose `restriction` (customer) or `restrictions` (legal entity) contains one of the listed values. A restricted scope with no values returns `403 Forbidden`.\n* The own-read scope returns only the caller's own customer or the caller's own legal entity. When the access token does not identify that customer or legal entity, the request returns `403 Forbidden`.\n\nWhen a caller has both a restricted scope and the own-read scope, a document must match both.","parameters":[{"$ref":"#/components/parameters/query_pageNumber"},{"$ref":"#/components/parameters/query_pageSize"},{"$ref":"#/components/parameters/query_sort"},{"$ref":"#/components/parameters/query_fields"},{"$ref":"#/components/parameters/header_Accept-Language"},{"$ref":"#/components/parameters/header_X-Total-Count"}],"requestBody":{"$ref":"#/components/requestBodies/search_POST"},"responses":{"200":{"description":"The search succeeded. The body is the current page of matching documents.","headers":{"X-Total-Count":{"description":"Number of matching documents. Present only when the request `X-Total-Count` header is `true`.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/SearchHit"}}}}},"400":{"description":"The request is invalid, or a filter or sort field is not indexed.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"401":{"$ref":"#/components/responses/401_resp_common"},"403":{"description":"The access token does not include the required `search.search_read` scope, or a scope required to read the documents.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"404":{"description":"No saved search with this id exists for the tenant and type. Returned when the body contains `searchQueryId`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"500":{"$ref":"#/components/responses/500_resp_common"},"502":{"description":"For a type other than `customer` or `legal-entity`, the Schema Service could not confirm that the type is a custom entity.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developer.emporix.io/api-references/readme/api-reference-33/search.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
