5

Elastic search ids that are generated by the system look like this.

"_id": "AU9HiR3lEVul15o3bNYl"

What format is that? Also does anyone know of a library to generate ids like that?

Donny V.
  • 22,248
  • 13
  • 65
  • 79

2 Answers2

5

Before v1.4.0 elasticsearch was using UUID-based ids. These ids were Base64 encoded version of a Version 4.0-compatible UUID as defined by RFC4122. In order to encode the ids an URL-safe Base64 encoding was used (see section 4 of RFC3548) and the last two "=" signs were removed (because Base64 encoding of 16 bytes would always generate two "=" at the end).

Unfortunately, completely random ids were less then ideal from performance perspective. So, starting with version 1.4.0 elasticsearch switched to time-based ids. The new id format is essentially a version of flake ids except it is using 6 (not 8) bytes for timestamp and 3 (not 2) bytes for the sequence number.

The id in the question AU9HiR3lEVul15o3bNYl looks like a time-base id that was generated somewhere in the middle of Aug 2015.

imotov
  • 28,277
  • 3
  • 90
  • 82
  • External link under "flake ids" is long gone, but archived: http://web.archive.org/web/20141124212354/http://www.boundary.com/blog/2012/01/flake-a-decentralized-k-ordered-unique-id-generator-in-erlang/ – dipnlik Mar 31 '20 at 12:49
1

Autogenerated IDs are 22 character long, URL-safe, Base64-encoded string universally unique identifiers, or UUIDs, although it looks like your ID is 20 characters.

Some more .NET info here I think, looks like Guid.NewGuid will work. What is the string length of a GUID?

Community
  • 1
  • 1
CJW
  • 332
  • 1
  • 14
  • I thought that format looked familiar but could not place it. – Donny V. Sep 02 '15 at 19:32
  • I see they chopped off the last 2 '==' to save space. Apparently when guids are turned into base64 it always adds 2 '==' to the end. http://madskristensen.net/post/A-shorter-and-URL-friendly-GUID – Donny V. Sep 02 '15 at 20:02