Index: primaryKey as an index setting #127
Replies: 6 comments 2 replies
-
It is documented at two different places mostly because it has connexion with both documents and indexes. Every document has the same One of the reason why it is was not added in the settings is because The use of the Every subroute of the settings have a GET/POST/DELETE method. With the exception of the Because MeiliSearch is schemaless, we do not explicitly ask for a Should a The index and documents on the other hand must be understood by the user to be able to set up a MeiliSearch. So I think it is easier to introduce the primaryKey in the index, or during documentation addition, than in the settings. Now, one thing that is possible, is that the primaryKey are badly explained in the documentation. Do we know other users for whom this was an issue to understand? |
Beta Was this translation helpful? Give feedback.
-
@bidoubiwa thanks for your answer! When I mention that the For example. Let's imagine I send a request to update documents: I can specify a Which makes me think... I should have a specific route to get/set a Adding it to the general settings route can indeed create some conflicts, which I still can't reflect on as clearly as I would like. But I'm glad this can start a discussion about it! :) But if you try to update your settings by modifying the primaryKey, it seems normal to me that you get an error. And if you don't modify it while you try to update your settings, that shouldn't be an issue to handle it in MeiliSearch core (if the primaryKey you specified is the same than the one already set, you can ignore it) |
Beta Was this translation helpful? Give feedback.
-
This is a valid point. Having so many possibilities is more confusing than helping. Also the fact that it will not raise an error if it is ignored during document addition but will raise an error if you try to update the primary key in the index when it already exists make the behavior not consistent. I would suggest also to remove the query parameter from the document addition route. If this is what you're suggesting. However, I still prefer the update of the primary key being in the index routes and not the settings route. For a reminder, this is the behavior on the index route: On index creation$ curl \
-X POST 'http://localhost:7700/indexes' \
--data '{
"uid": "movies",
"primaryKey": "movie_id"
}' primaryKey is optional in this route. Index update (which will return an error if a primary key already exists)$ curl \
-X PUT 'http://localhost:7700/indexes/movie_review' \
--data '{
"primaryKey" : "movie_review_id"
}' Returns:
This behavior already describes what you're are suggesting in the settings route. I'm not sure I understand what you dislike about this? |
Beta Was this translation helpful? Give feedback.
-
(sorry for the delay) I completely agree with @bidoubiwa on both points:
|
Beta Was this translation helpful? Give feedback.
-
Slightly tangential to this discussion here, but I'm curious why can the primaryKey not have any spaces in it? |
Beta Was this translation helpful? Give feedback.
-
Hello @simar7 If you are talking about the |
Beta Was this translation helpful? Give feedback.
-
Every index needs a
primaryKey
. It can be set at index creation or when you start indexing documents. It can also be infered from your first document. TheprimaryKey
can only be set once, and can't be updated afterwards.But that is the only specific behavior that makes it any different to any other index settings. Is there a reason to handle the Index
primaryKey
in a different way than all the other index settings? Also, shouldn't we add it to the GET/indexes/:index_uid/settings
?There are three weird behaviours for this choice:
Beta Was this translation helpful? Give feedback.
All reactions