Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is an asynchronous issue with updating the index in meisearch #767

Open
LyingDoc opened this issue Aug 25, 2024 · 1 comment
Open
Labels
needs more info This issue needs a minimal complete and verifiable example

Comments

@LyingDoc
Copy link

@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

@curquiza
Copy link
Member

curquiza commented Oct 3, 2024

Hello @LyingDoc

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

@curquiza curquiza added the needs more info This issue needs a minimal complete and verifiable example label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue needs a minimal complete and verifiable example
Projects
None yet
Development

No branches or pull requests

2 participants