SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fix(filer.meta.tail): include extended metadata in Elasticsearch docs (#9200)
Chris Lu749430dcebf1
diff --git a/weed/command/filer_meta_tail_elastic.go b/weed/command/filer_meta_tail_elastic.goindex 308520612b..f11bc50980 100644--- a/weed/command/filer_meta_tail_elastic.go+++ b/weed/command/filer_meta_tail_elastic.go@@ -4,7 +4,9 @@ package commandimport ("context"+ "encoding/base64""strings"+ "unicode/utf8"jsoniter "github.com/json-iterator/go"elastic "github.com/olivere/elastic/v7"@@ -13,16 +15,17 @@ import ()type EsDocument struct {- Dir string `json:"dir,omitempty"`- Name string `json:"name,omitempty"`- IsDirectory bool `json:"isDir,omitempty"`- Size uint64 `json:"size,omitempty"`- Uid uint32 `json:"uid,omitempty"`- Gid uint32 `json:"gid,omitempty"`- UserName string `json:"userName,omitempty"`- Crtime int64 `json:"crtime,omitempty"`- Mtime int64 `json:"mtime,omitempty"`- Mime string `json:"mime,omitempty"`+ Dir string `json:"dir,omitempty"`+ Name string `json:"name,omitempty"`+ IsDirectory bool `json:"isDir,omitempty"`+ Size uint64 `json:"size,omitempty"`+ Uid uint32 `json:"uid,omitempty"`+ Gid uint32 `json:"gid,omitempty"`+ UserName string `json:"userName,omitempty"`+ Crtime int64 `json:"crtime,omitempty"`+ Mtime int64 `json:"mtime,omitempty"`+ Mime string `json:"mime,omitempty"`+ Extended map[string]string `json:"extended,omitempty"`}func toEsEntry(event *filer_pb.EventNotification) (*EsDocument, string) {@@ -40,10 +43,31 @@ func toEsEntry(event *filer_pb.EventNotification) (*EsDocument, string) {Crtime: entry.Attributes.Crtime,Mtime: entry.Attributes.Mtime,Mime: entry.Attributes.Mime,+ Extended: toExtendedStrings(entry.Extended),}return esEntry, id}+// toExtendedStrings converts the xattr map (e.g. S3 user metadata like+// X-Amz-Meta-*) to string values so Elasticsearch indexes them as text+// instead of base64-encoding the raw bytes. Non-UTF-8 values are prefixed+// with "base64:" so consumers can distinguish encoded bytes from plain+// strings that happen to look like base64.+func toExtendedStrings(extended map[string][]byte) map[string]string {+ if len(extended) == 0 {+ return nil+ }+ result := make(map[string]string, len(extended))+ for k, v := range extended {+ if utf8.Valid(v) {+ result[k] = string(v)+ } else {+ result[k] = "base64:" + base64.StdEncoding.EncodeToString(v)+ }+ }+ return result+}+func sendToElasticSearchFunc(servers string, esIndex string) (func(resp *filer_pb.SubscribeMetadataResponse) error, error) {options := []elastic.ClientOptionFunc{}options = append(options, elastic.SetURL(strings.Split(servers, ",")...))