Hi, I insert docs by using import?action=create bu...
# community-help
b
Hi, I insert docs by using import?action=create but when I index a new document it doesn't continue the id number sequentially but starts from lower. Is there any way to set the id number?
k
The ID will be sequential. Are you able to show a small reproduction of the issue?
b
I use Typesense v27.0.0. I just add docs with import?action=create and when I index a new doc the id starts with a lower number. For example, I import docs with ids [235,236,237..]. When I index a new it starts from id = 10.
k
Are you saying some docs have their own IDs and some have missing IDs?
b
all the docs that I import have ids
when I index a new one it hasn't
k
If you are going to insert a new document without an ID then it will use an auto genrator counter for giving it an ID. That has no knowledge about previous IDs of documents since IDs can be alphanumeric.
b
If the last imported doc has id: 26. When I index a new one it should have 27
Yes but the auto generator starts from 10 instead of 26
k
Yeah that's how it is, you can't mix documents with and without IDs to have same sequence. We don't support that.
b
So in order to set the auto generator to start from 26 should I have to index 16 more docs?
Is there any other way? The generator. starts at 10 and my last doc id is 225
k
Generator begins at zero. Maybe there were some earlier docs that were indexed without ID and deleted.
Either generate IDs for all docs or don't. Cannot mix those two modes.
b
I'm referring to initial typesense doc id
that is always number not special doc id
"id" key in doc
k
I don't fully follow what you are saying but don't depend on IDs generated by Typesense for internal use.
As long as you have an id field in the document Typesense will only use to that as identifier
b
When you index a new doc, it gets an auto generated id in "id" key
If you import doc the id key should start from the id of the latest inserted doc
k
Please share an example that shows the problem, it's much easier.
ID already does start from latest inserted doc. But if you delete docs we can't decrease IDs to account for that. It will keep increasing.
b
I insert this doc: {"name": "test", "id": "12"} by using import?action=create. Then i index a new doc ({"name": "test"}) (without import?action=create - normal POST). The new doc get's id eg. 5 instead of 13.
k
Yeah that's what I'm saying. You can't mix those modes.
b
So the only way to sync id generator is to create eg. 12 docs
?
k
Always send a document ID.
Why do some docs have missing IDs?
b
Why should I send id if its auto generated
?
k
Why do you send "12" in the example above then?
b
Because I migrate data from one cluster to another. I can't change the ids because they are saved in my db also
k
Yeah if you send IDs you have to send always. That's what I've been trying to say. What you want to do is not possible.
b
So i need to create 12 docs and delete them in order to sync the id generator.
It would be very useful if we can set it after importing docs in a feature version of typesense.
k
I don't see us being able to support this.