You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@SuppressWarnings("unchecked")
@PostConstruct
private void initMeiLiSearch() {
Class<? extends MeiLiSearchService<T>> cla = (Class<? extends MeiLiSearchService<T>>) this.getClass();
Type type = cla.getGenericSuperclass();
if (type instanceof ParameterizedType) {
clazz = (Class<T>) ((ParameterizedType) type).getActualTypeArguments()[0];
MSIndex msIndex = clazz.getAnnotation(MSIndex.class);
String uid = msIndex.uid();
String primaryKey = msIndex.primaryKey();
if (StringUtils.isEmpty(uid)) {
uid = clazz.getSimpleName();
}
****Client client = MeiLiSearchHelper.getInstance().getMeiLiClient();
Index[] indexs = client.getIndexes().getResults();
boolean uidFlg = false;
String primaryKeyOld = null;
Index oldIndex = null;
if (ArrayUtils.isNotEmpty(indexs)) {
for (Index index : indexs) {
if (StringUtils.equals(uid, index.getUid())) {
uidFlg = true;
primaryKeyOld = index.getPrimaryKey();
oldIndex=index;
break;
}
}**
if (uidFlg && StringUtils.notEquals(primaryKeyOld, primaryKey)) {
TaskInfo taskInfo = oldIndex.deleteAllDocuments();
client.updateIndex(uid, primaryKey);
}
}**
if (BooleanUtils.isFalse(uidFlg)) {
client.createIndex(uid, primaryKey);
}
index = client.getIndex(uid);
logger.info("index==>{}", GsonUtils.toJson(index));
}
}
The above is the code I wrote to obtain the new entity document through generics. I obtained the primary key setting through notification annotations, and I checked whether the UID was the same. If they were the same, I judged the previous primary key ID field and then modified the index's primary key field at different times. However, it did not take effect after the first startup until the ID was successfully displayed during the second startup. This issue can be fixed
The text was updated successfully, but these errors were encountered:
Can explain me (with words) what you try exactly to do with Meilisearch here (not meilisearch-java)? I don't understand why you have to modify the primary key
The above is the code I wrote to obtain the new entity document through generics. I obtained the primary key setting through notification annotations, and I checked whether the UID was the same. If they were the same, I judged the previous primary key ID field and then modified the index's primary key field at different times. However, it did not take effect after the first startup until the ID was successfully displayed during the second startup. This issue can be fixed
The text was updated successfully, but these errors were encountered: