in java/core/src/main/java/com/aliyun/openservices/tablestore/agent/util/TablestoreHelper.java [834:863]
public static void createSearchIndexIfNotExist(
SyncClient client,
String tableName,
String searchIndexName,
List<FieldSchema> schemas,
List<String> routingFields
) {
ListSearchIndexRequest listSearchIndexRequest = new ListSearchIndexRequest();
listSearchIndexRequest.setTableName(tableName);
ListSearchIndexResponse listSearchIndexResponse = client.listSearchIndex(listSearchIndexRequest);
for (SearchIndexInfo indexInfo : listSearchIndexResponse.getIndexInfos()) {
if (indexInfo.getIndexName().equals(searchIndexName)) {
log.warn("search index already exist, tableName:{}, searchIndexName:{}", tableName, searchIndexName);
return;
}
}
CreateSearchIndexRequest request = new CreateSearchIndexRequest();
request.setTableName(tableName);
request.setIndexName(searchIndexName);
IndexSchema indexSchema = new IndexSchema();
indexSchema.setFieldSchemas(schemas);
if (routingFields != null && !routingFields.isEmpty()) {
IndexSetting indexSetting = new IndexSetting();
indexSetting.setRoutingFields(routingFields);
indexSchema.setIndexSetting(indexSetting);
}
request.setIndexSchema(indexSchema);
client.createSearchIndex(request);
log.info("create search index:{}, tableName:{}", searchIndexName, tableName);
}