pkaramol
pkaramol

Reputation: 19322

Logstash: create url-friendly _id for documents

I am using the fingerprint plugin to create custom _id fields that should be base64 encoded:

  fingerprint {
    key => "somekey"
    base64encode => true
    method => "SHA512"
    source => [ "username" ]
    target =>  "[@metadata][custom_id]"
   }

   truncate {
    fields =>  "[@metadata][custom_id]"
    length_bytes => 20
   }

However, here is an example key that was created:

lStqstfpWw5OHe+B3FBi

The above is NOT url friendly therefore manipulation by id becomes cumbersome since it needs encoding/decoding.

Any suggestion to make the _id url friendly?

Upvotes: 1

Views: 71

Answers (1)

pkaramol
pkaramol

Reputation: 19322

Ended up doing this at some point, in conformance with RFC3548 and its guidelines on base64-urlfriendliness ...

mutate {
  gsub => [
    "[@metadata][custom_id]", "\+", "-",
    "[@metadata][custom_id]", "/", "_"
    ]
}

Upvotes: 1

Related Questions