Queries

Search Query can be used to describe different ways on how data on your index can be queried.

For example, you can configure multiple queries that access the data in different ways:

  • Query which is used to display only products on sale, as it uses filter to search for items that have a non zero discount;

  • Query that sorts all of the products by discount size, by default;

  • Query that is used in a quick search box, which omits all facets and filters to speed up quick autocomplete queries;

  • Query that always filters out alcoholic beverages from the results.

Search query consists of these main parts:

  • description - human-readable query title that will help you to differentiate between the purposes of the different queries;

  • configuration - detailed description on how your index data is queried. Can be viewed here;

  • queryKey - is used to reference this query when executing it as a Public Query.

  • debugMode - can be set to true to return detailed errors with Public Query responses. Should be always set to false in when used in your production environment;

Search Query vs Public Query

Search Query describes how data in your Search Index should be queried: what fields to include in the search, what to boost and what filters include.

Public Query is an execution of a Search Query, which is usually done by your e-shop or website users.

Public Query allows extending Search Query configuration, like changing page number and page size, sorting parameters and adding filters.

Create Search Query

API Reference: Create Search Query

A new query in Index can only be created by Organization or Project administrators.

To create a query, issue a POST request for a selected index:

{
  "description": "Document search query description",
  "configuration": {
    "queryFields": { "name": 5 },
    "selectFields": ["id", "name"],
    "matchType": "all"
  },
  "debugMode": false
}

The response will include the data of your search query, along with id (to use it when performing CRUD actions with your query) and queryKey (to execute your query as a public request):

{
  "id": "ab12c0d1-0df0-295a-a1b2-e720f23ffed5",
  "description": "Document search query description",
  "configuration": {
    "queryFields": { "name": 5 },
    "selectFields": ["id", "name"],
    "matchType": "all"
  },
  "createdAt": "2022-07-01T13:38:09.000Z",
  "updatedAt": "2022-07-02T11:98:06.000Z",
  "queryKey": "ax2q422v8f7z",
  "debugMode": false
}

Update Search Query

API Reference: Update Search Query

To update a query, issue a PUT request for a selected index with query id you want to update in the parameters:

{
  "description": "Updated document search query description",
  "configuration": {
    "queryFields": { "name": 5 },
    "selectFields": ["id", "name"],
    "matchType": "all"
  },
  "debugMode": true
}

List Queries

API Reference: List Search Queries

List queries for a selected index. You can apply pagination query parameters: page and perPage.

The response will include a list of queries in the chosen index.

Get Query

API Reference: Get Single Search Query

The response will include query data, with its id and queryKey:

{
  "id": "ab12c0d1-0df0-295a-a1b2-e720f23ffed5",
  "description": "Document search query description",
  "configuration": {
    "queryFields": { "title": 5 },
    "selectFields": ["id", "title"],
    "matchType": "all"
  },
  "createdAt": "2022-07-01T13:38:09.000Z",
  "updatedAt": "2022-07-02T11:98:06.000Z",
  "queryKey": "ax2q422v8f7z",
  "debugMode": false
}

Delete Query

API Reference: Delete Search Query

Delete selected query by its id. This is a hard delete operation and is irreversible.

Test Query

API Reference: Test Search Query

You can test how Search Query behaves without actually

To use the Test endpoint, you need to include both Search Query and Public Query configuration in the same HTTP POST request:

{
  "searchQuery": {
    "description": "test search query",
    "configuration": {
      "queryFields": { "name": 5 },
      "selectFields": ["id", "name"],
      "matchType": "all",
      "filters": { "tags": ["TV", "Electronics"] }
    },
    "debugMode": true
  },
  "publicQuery": {
    "searchText": "Mobile phone",
    "limit": 15
  }
}

The response will include the public query execution result:

{
  "searchText": "Mobile phone",
  "total": 200,
  "items": [{}, {}, {}],
  "limit": 15
}

Configuration

Full query configuration options can be viewed here.

Suggestion Queries

Suggestion (autocomplete) query configuration differs from a regular search query and is described here.