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

Updating related field does not trigger update. #25

Open
1cgonza opened this issue Jan 14, 2023 · 3 comments
Open

Updating related field does not trigger update. #25

1cgonza opened this issue Jan 14, 2023 · 3 comments

Comments

@1cgonza
Copy link

1cgonza commented Jan 14, 2023

Not so much of an issue but a question or feature request:

If I have a M2O or M2M field and update the values in those collections, the changes are not reflected on the collection I am indexing.

Following your example, a simplified config with "products" as the indexed collection with a M2O field called "category":

"collections": {
	"products": {
		"fields": ["title", "category.title"]
	}
}

If I go to the collection holding the categories and change the "title", those changes do not trigger an update on all the indexes that relate to it.

Is it possible to keep them on sync?

BTW, thanks for the extension, great job!

@donni106
Copy link

i have a many to one relation location.identifier which works fine. i can change the selected value in directus edit page overlay, click on save (closing overlay for location selection) and clicking on save for the main object.
it is instantly updated in my index.
how is your process of updating a value?

another question according many to many relations. were you able to index them? i have tags and i am not able to index them, tried it with tags and with tags.tags_id.name but nothing lands in meilisearch documents :(

@donni106
Copy link

another question according many to many relations. were you able to index them? i have tags and i am not able to index them, tried it with tags and with tags.tags_id.name but nothing lands in meilisearch documents :(

I have figured it out through reverse engineering in the extension's code 😮
You need to use:

- tags.tags_id.name
- tags.0.tags_id.name
- tags.1.tags_id.name
- tags.2.tags_id.name

Unfortunately, this means hardcoding the number of expected or indexed relations. This needs to be addressed in the extension, but at least it works!

@donni106
Copy link

donni106 commented Apr 3, 2024

I was able to sync tags as array with using a .searchsyncrc.cjs instead of .yml to use transform this way:

collections: {
  profiles: {
    filter: {
      ...
    },
    fields: [
      ...
      'tags.tags_id.name',
    ],
    transform: (item, { flattenObject }) => {
      return {
        ...flattenObject(item),
        tags: item.tags?.map((tag) => tag.tags_id?.name)?.filter(Boolean)
      };
    }
  }
}

=> in Meilisearch:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants