From 0e18a498610f826068ad2adf7308585c07f08657 Mon Sep 17 00:00:00 2001 From: Steve Perkins Date: Mon, 13 Feb 2023 20:44:06 -0500 Subject: [PATCH] wip docker-compose setup --- go.mod | 2 +- go.sum | 1 + search/docker-compose.yml | 33 +++++++++++++------------- search/main.go | 2 +- storage/elasticsearch/elasticsearch.go | 21 +++++++++------- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index 2917985..3ff8e5a 100644 --- a/go.mod +++ b/go.mod @@ -83,4 +83,4 @@ require ( golang.org/x/text v0.3.7 // indirect ) -replace github.com/nbd-wtf/go-nostr => /Users/steve/opc/go-nostr +replace github.com/nbd-wtf/go-nostr => ../go-nostr diff --git a/go.sum b/go.sum index e3f3e48..90bd150 100644 --- a/go.sum +++ b/go.sum @@ -371,6 +371,7 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/stereosteve/go-nostr v0.13.1/go.mod h1:qFFTIxh15H5GGN0WsBI/P73DteqsevnhSEW/yk8nEf4= github.com/stevelacy/daz v0.1.4 h1:ugmff/D7D764wZjXSgSryEINE/bi+Xddllw3JQQGbWk= github.com/stevelacy/daz v0.1.4/go.mod h1:AbK6DzjiIL15r4bQtcFvOBAvDGMXoh+uIG26NRUugt0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/search/docker-compose.yml b/search/docker-compose.yml index 40479cb..66f20a8 100644 --- a/search/docker-compose.yml +++ b/search/docker-compose.yml @@ -1,20 +1,23 @@ version: "3.8" services: - # relay: - # build: - # context: ../ - # dockerfile: ./basic/Dockerfile - # environment: - # PORT: 2700 - # POSTGRESQL_DATABASE: postgres://nostr:nostr@postgres:5432/nostr?sslmode=disable - # depends_on: - # postgres: - # condition: service_healthy - # ports: - # - 2700:2700 - # command: "./basic/relayer-basic" - + relay: + image: golang + # build: + # context: ../ + # dockerfile: ./basic/Dockerfile + environment: + PORT: 2700 + ES_URL: http://elasticsearch:9200 + depends_on: + elasticsearch: + condition: service_healthy + ports: + - 2700:2700 + volumes: + - ./nostres:/bin/relay + command: "/bin/relay" + elasticsearch: container_name: elasticsearch image: docker.elastic.co/elasticsearch/elasticsearch:8.6.0 @@ -39,5 +42,3 @@ services: interval: 10s timeout: 5s retries: 5 - - diff --git a/search/main.go b/search/main.go index 1688e3e..14dce89 100644 --- a/search/main.go +++ b/search/main.go @@ -15,7 +15,7 @@ type Relay struct { } func (r *Relay) Name() string { - return "BasicRelay" + return "SearchRelay" } func (r *Relay) Storage() relayer.Storage { diff --git a/storage/elasticsearch/elasticsearch.go b/storage/elasticsearch/elasticsearch.go index 9953603..3d8a4d1 100644 --- a/storage/elasticsearch/elasticsearch.go +++ b/storage/elasticsearch/elasticsearch.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "log" + "os" "strings" "time" @@ -52,19 +53,18 @@ type ElasticsearchStorage struct { } func (ess *ElasticsearchStorage) Init() error { - es, err := elasticsearch.NewDefaultClient() + cfg := elasticsearch.Config{} + if x := os.Getenv("ES_URL"); x != "" { + cfg.Addresses = strings.Split(x, ",") + } + es, err := elasticsearch.NewClient(cfg) if err != nil { return err } - // log.Println(elasticsearch.Version) - // log.Println(es.Info()) - // todo: config + // todo: config + mapping settings ess.indexName = "test3" - // todo: don't delete index every time - // es.Indices.Delete([]string{ess.indexName}) - res, err := es.Indices.Create(ess.indexName, es.Indices.Create.WithBody(strings.NewReader(indexMapping))) if err != nil { return err @@ -139,7 +139,12 @@ func (ess *ElasticsearchStorage) SaveEvent(event *nostr.Event) error { } // post processing: index for FTS - // this could also possibly do custom indexing for kind=0. + // some ideas: + // - index kind=0 fields a set of dedicated mapped fields + // (or use a separate index for profiles with a dedicated mapping) + // - if it's valid JSON just index the "values" and not the keys + // - more content introspection: language detection + // - denormalization... attach profile + ranking signals to events if event.Kind != 4 { ie.ContentSearch = event.Content }