Home > Back-end >  How Elasticsearch generate the unique _id value?
How Elasticsearch generate the unique _id value?

Time:10-29

I'm asking simply out of my favor to the look of its result string and am wondering if the algorithm has some kind of library so that I can use in my own code (C#).

CodePudding user response:

See the answer to this question in the Elasticsearch discuss.

You can find the source code to the method linked there here.

Elasticsearch is written in Java, so you won't be able to import this method into your c# project.

If you don't need the specific optimizations that the Elasticsearch-Team implemented in this method, you can use the build in UUID generator of .NET. Or you can look for other UUID libraries on nuget.

If you just like the format of the Elasticsearch IDs you can also base64 encode your GUIDs/UUIDs to get similar looking IDs:

Guid g = Guid.NewGuid();
var base64GUID =  System.Convert.ToBase64String(g.ToByteArray());
  • Related