Keywords

What are keywords and when to use them

Keywords can be used to mark special words or phrases that will be excluded from grammatical stemming. This is often used for product brands which are not supposed to be stemmed. It can be especially useful in non-english languages where stemming can be more aggressive.

Usage example

Let's say we have an index with the following documents:

  • What is your favourite book?
  • What books do you like?
  • Get a hotel using booking.com

If we issue request booking without keywords, this is the expected response:

{
  "searchText": "booking",
  "total": 3,
  "items": [
    {
      "name": "What is your favourite book?"
    },
    {
      "name": "What books do you like?"
    },
    {
      "name": "Get a hotel using booking.com"
    }
  ]
}

As we can see, the word booking is stemmed to book and all documents are returned. If we add keyword booking to the index, the response will be different:

{
  "searchText": "booking",
  "total": 1,
  "items": [
    {
      "name": "Get a hotel using booking.com"
    }
  ]
}

Managing keywords in console

Keywords can be managed in the console by selecting the document index and choosing the Keywords in menu: Keywords Console.

Important: to fully apply the keyword changes, you need to re-index your document index.

Managing keywords using API

Get all keywords in index

GET /indices/<indexId>/keywords

Response example:

[
  {
    "id": "ea68058d-7e02-4bab-8522-4d29d9587443",
    "keywordEntry": "booking",
    "createdAt": "2023-07-31T11:44:39.000Z"
  }
]

Add new keywords to the index

POST /indices/<indexId>/keywords

Request example:

[
  {
    "keywordEntry": "booking"
  },
  {
    "keywordEntry": "boeing"
  }
]

Delete keywords from the index

POST /indices/<indexId>/keywords/batchDelete

Request example

{
  "ids": [
    "1d398398-fb00-4b89-bc98-2a0f2326a99a",
    "859c29af-868b-47bf-91c4-03481be06628",
    "84d5ccf4-9309-4206-8fa1-d4f5f9d98900"
  ]
}

Important: to fully apply the keyword changes, you need to re-index your document index after each action