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

Algolia index objectID is undefined #13

Closed
bcartier opened this issue Dec 9, 2021 · 6 comments
Closed

Algolia index objectID is undefined #13

bcartier opened this issue Dec 9, 2021 · 6 comments

Comments

@bcartier
Copy link

bcartier commented Dec 9, 2021

When running the CLI command to reindex, the first record in the Algolia index is being updated over and over again for every Item in the Collection. I think it's because the ObjectID is set as "undefined", so Algolia is finding an existing record with that ObjectID and updating it, rather than adding a new record.

I was originally just configuring search-sync using a json file, passing just Item fields. In this case, I think Algolia was auto-generating the ObjectID. Since it was always "undefined", I tried using a js-based config file so I could pass the item.id as the Algolia ObjectID - no difference.

SearchSync v1.0.2
Directus 9.2.1

@dimitrov-adrian
Copy link
Owner

What is the name of the Primary Key field?

@bcartier
Copy link
Author

bcartier commented Dec 10, 2021

I rolled back to how I had it configured when is was working for me (using a json config file). Basically, from what I now understand, the extension determines the primary key of the configured collection, and passes that value to Algolia as the objectID. This no longer happens. I wonder if something changed in the latest versions of Directus that changes how you determine the primary key for a collection. Maybe this line on create-indexer.js (line 69) no longer works?

const pk = schema.collections[collection].primary;

In my use case, the primary key of the collection I'm trying to index is "id"

@dimitrov-adrian
Copy link
Owner

Doesn't looks as there, at least with my tests it get correct primary key name, and pass correctly to the request. I also make different tests with algolia with different primary key names, and all seems to works for me, so cannot reproduce.

Anyway, I'll continue to dig on it.

@bcartier
Copy link
Author

Thanks for looking into it. Maybe there's something wrong in my configuration? Here is my config where I have a collection named "naics_2017_examples_en", and it has text fields "example" and "exceptions". The "naics" field is a o2m relationship field (and populates the index with the foreign key):

{
	"server": {
		"type": "algolia",
	    "appId": "*********",
	    "key": "********************"
	},
	"batchLimit": 100,
	"reindexOnStart": false,
	"collections": {
	
		"naics_2017_examples_en": {
		
			"indexName": "naics_2017_examples_en_test",
	

			"filter": {
				"status": "published"
			},
			"fields": ["example",  "exceptions", "naics"]
		}
	}
}

.... and here is the Algolia index. This one index entry gets overwritten for every item in the collection when I run "npx directus extension:searchsync index" (the exceptions field is supposed to be blank in this example):

{
  "example": "fruit cocktail, canned, manufacturing",
  "exceptions": "",
  "naics": "311420",
  "objectID": "undefined"
}

@dimitrov-adrian
Copy link
Owner

I think it should be fixed now. The issue indeed was with the missing id field passing to algolia indexer when using filter fields.

Thanks for all the report!

@bcartier
Copy link
Author

Thanks so much for your help!

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