Killlist in plain indexes

When using plain indexes there is a problem generated by the need of having the data in the index as fresh as possible.

In this case one or more secondary (also know as delta) indexes are used to capture the modified data between the time the main index was created and and current time. The modified data can mean new, updated or deleted documents. The search becomes a search over the main index and the delta index. This works with no obstacle when you just add new documents to the delta index, but when it comes to updated or deleted documents there remains the following issue.

If a document is present in both main and delta indexes it can cause issues at searching as the engine will see two versions of a document and won't know how to pick the right one. So the delta needs to tell somehow to the search that there are deleted documents in the main index that should be forgotten. Here comes kill lists.

Index kill-list

Index can maintain a list of document ids that can be used to suppress records in other indexes. This feature is available for plain indexes using database sources or plain indexes using XML sources. In case of database sources, the source needs to provide an additional query defined by sql_query_killlist. It will store in the index a list of documents that can be used by the server to remove documents from other plain indexes.

This query is expected to return a number of 1-column rows, each containing just the document ID.

In many cases the query is a union between a query that gets a list of updated documents and a list of deleted documents, e.g.:

    sql_query_killlist = \
        SELECT id FROM documents WHERE updated_ts>=@last_reindex UNION \
        SELECT id FROM documents_deleted WHERE deleted_ts>=@last_reindex

Removing documents in a plain index

A plain index can contain a directive called killlist_target that will tell the server it can provide a list of document ids that should be removed from certain existing indexes. The index can use either it's document ids as the source for this list or provide a separate list.

killlist_target

Sets the index(es) that the kill-list will be applied to. Optional, default value is empty.

When you use plain_indexes you often need to maintain not a single index, but a set of them to be able to add/update/delete new documents sooner (read delta_index_updates). In order to suppress matches in the previous (main) index that were updated or deleted in the next (delta) index you need to:

  1. Create a kill-list in the delta index using sql_query_killlist
  2. Specify main index as killlist_target in delta index settings:
‹›
  • CONFIG
CONFIG
📋
index products {
  killlist_target = main:kl

  path = products
  source = src_base
}

When killlist_target is specified, kill-list is applied to all the indexes listed in it on searchd startup. If any of the indexes from killlist_target are rotated, kill-list is reapplied to these indexes. When kill-list is applied, indexes that were affected save these changes to disk.

killlist_target has 3 modes of operation:

  1. killlist_target = main:kl. Document ids from the kill-list of the delta index are suppressed in the main index (see sql_query_killlist).
  2. killlist_target = main:id. All document ids from delta index are suppressed in the main index. Kill-list is ignored.
  3. killlist_target = main. Both document ids from delta index and its kill-list are suppressed in the main index.

Multiple targets can be specified separated by comma like

killlist_target = index_one:kl,index_two:kl

You can change killlist_target settings for an index without reindexing it by using ALTER.

But since the 'old' main index has already written the changes to disk, the documents that were deleted in it will remain deleted even if it is no longer in the killlist_target of the delta index.

‹›
  • SQL
  • HTTP
📋
ALTER TABLE delta KILLLIST_TARGET='new_main_index:kl'