-
Notifications
You must be signed in to change notification settings - Fork 15
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
getOrCreateIndex method #2
Comments
In go it does not seem very relevant to me since the client is divided into sub-clients who take an index themselves. The main client does not take any index. |
You're right, I update the issue! Thanks |
I really don't like the idea to compare the error message string. Would be nice to have a type of reason code or something. |
What do you suggest to not to check the message? 🙂 |
Meilisearch should have a way to check the existence of an index. then, you just have to create a method |
I agree with @ppamorim about comparing error messages, seems really unreliable. Also, as for now, it seems that the possibilities of providing a method like this are:
None of those options seem to be reliable or sustainable in my opinion. The problem is that if we do not provide a method like this one, every SDK user is forced to check in it's own code every time if the index exists, which is clearly not ideal Can I request your POV @Kerollmops ? |
I prefer the one-call way proposed by @curquiza instead of the two-calls way proposed by @shokme as this is prone to races. A user can run multiple clients at the same time that which asks if the index exists or not, all the clients will see that the index doesn't exist and tries to create it at the same time. All the clients that were trying to create the index except the one that succeeded will return an error. However, the error reporting story of MeiliSearch is not that good, we must introduce error codes as I already explained to @ppamorim. A unique code that helps SDKs understand the reported error without having to do text comparison (which isn't a reliable solution). The documentation website will understand this unique code and redirect the user to the appropriate page. In conclusion, I think that we should rely on string comparison as this is the safest and less race condition prone solution we have. We will improve the error reporting of the engine and you can track that in the related issue. |
I'm building this method in the javascript library and I have a question about the primaryKey key. The primary Key is set only once, either by inference either manually by the user. With this in mind, imagine the following scenario: Scenario 1: existing index without no primary keyI have an index Then, I call this method the following way.
The primary key that is given here is useless because your method does not use this parameter unless the index does not exists. Scenario 2: existing index existing primary keyI have an index Then, I call this method the following way.
The primary key that is given here is useless as the primary key already exists and can not be changed and for reason in scenario 1. PropositionTaken the following parameters into account:
I suggest creating a second parameter which would be a call in javascript would look like this await meili.getOrCreateIndex("uid", {
"primaryKey": "newId"
}) |
But, I think (I'm not sure) I understood your suggestion in your conclusion. You want as definition: def get_or_create_index(index_uid, options = nil) and as usage: client.get_or_create_index('uid', {'primaryKey': 'id'}) Right? I like this kind of idea, but I would improve your idea with this goal: staying consistent with the Look at the usage in JS: // Create an index
const index = await client.createIndex({ uid: 'books' })
// Create an index and give the primary-key
const index = await client.createIndex({ uid: 'books', primaryKey: 'book_id' }) => the For the ruby: # Create an index
client.create_index('books')
# Create an index and give the primary-key
client.create_index({uid: 'books', primaryKey: 'book_id'}) => the For the PHP: same behavior than ruby. For the python, it's a little bit different... It does not have the same logic than the others 😞 # Create an index
client.create_index(uid='books')
# Create an index and give the primary-key
client.create_index(uid='books', primary_key='book_id')
This is not possible here... A solution is:
client.create_index(uid='indexUID', options={ primaryKey: 'id' })
client.get_or_create_index(uid='indexUID', options={ primaryKey: 'id' })
Need your opinion/approvalWhat do you think guys about:
Outdated, see the comment below. |
I really like your suggestion of staying consistent. I'm not against breaking the python. The first parameter is still UID which is the most important. |
After discussing with @bidoubiwa, here are the final solution we thought about: For all the SDKs, the createIndex(uid as string, options as object) Same for the new getOrCreateIndex(uid as string, options as object) The pros:
The cons:
@eskombro and @bidoubiwa I need your approval on it 🚀 |
I really like the idea of encouraging consistence and coherence between all SDKs and between this two different but close methods. |
We are thinking about creating a
getOrCreateIndex
method.Description
This method returns an
Index
object. It checks if the index already exists and if it's not, it creates the index.How
By trying to create the index, and catching the exception. In every situation, only one HTTP call is done.
An example in ruby:
(In ruby the
index
method is the equivalent ofgetIndex
in other SDKs, and this method does not do any HTTP call)This example is out of the MeiliSearch library. Of course, this method must be included in the client class.
Tests
This method must be tested:
Steps
Do it in:
Removed from the to-do list:
Feedback
Don't hesitate to suggest other ideas to implement the method, or if I forgot any tests 🙂
The text was updated successfully, but these errors were encountered: