Timeline management provides two operations on a TimelineStore: search and flush. Search queries timeline data through the search index of Tablestore, and flush completes the write requests that are still pending in the batch-write buffer.
Search
Timeline management builds its query feature on the Search API of the search index, which provides features such as fuzzy query and multi-condition query.
Search is supported only for a TimelineStore that has an IndexSchema configured.
When you configure the IndexSchema of a TimelineStore, note the following requirements for indexed fields:
Data types — Indexed fields support data types such as LONG, DOUBLE, BOOLEAN, KEYWORD, GEO_POINT, and TEXT.
Field properties — Field properties include Index, Store, and Array, as well as the tokenizer type. These properties have the same meanings as they do in the search index. For details, see Data types.
Fuzzy query — Configure the fields that you want to use for fuzzy query as the TEXT type, and set the required tokenizer type for these fields. For more information about tokenization, see Tokenization.
Search accepts two forms of input, and both forms calltimelineStore.search. To match a field against a value with a condition expression, pass aSearchParameter:
/**
* Search timeline by SearchParameter.
* */
SearchParameter searchParameter = new SearchParameter(
field("text").equals("fieldValue")
);
timelineStore.search(searchParameter);To pass a query object such as TermQuery and limit the number of results with setLimit, use a SearchQuery:
/**
* Search timeline by SearchQuery.
* */
TermQuery query = new TermQuery();
query.setFieldName("text");
query.setTerm(ColumnValue.fromString("fieldValue"));
SearchQuery searchQuery = new SearchQuery().setQuery(query).setLimit(10);
timelineStore.search(searchQuery);Batch write and flush
Timeline management builds batch write on DefaultTableStoreWriter in the Tablestore SDK. Write requests that are not sent yet remain pending in the buffer. Call flush to trigger the sending of these pending requests and then synchronously wait until all messages are written.
The following code sends the messages that are pending in the buffer and waits until all of them are stored:
/**
* Flush messages in buffer, and wait until all messages are stored.
* */
timelineStore.flush();