Search

Configuration

Config structs, YAML examples, and option helpers for Search

YAML Configuration Example

config.yaml
extensions:
  search:
    driver: "elasticsearch"           # "inmemory", "elasticsearch", "meilisearch", "typesense"
    url: "http://localhost:9200"
    hosts:                             # alternative to url for multi-node clusters
      - "http://node1:9200"
      - "http://node2:9200"
    username: "elastic"
    password: "changeme"
    apiKey: ""                         # used by Typesense

    # Connection settings
    maxConnections: 10
    maxIdleConnections: 5
    connectTimeout: "5s"
    requestTimeout: "30s"
    keepAlive: "30s"

    # Retry settings
    maxRetries: 3
    retryBackoff: "100ms"
    retryOnTimeout: true

    # Search defaults
    defaultLimit: 20
    maxLimit: 100
    defaultMinScore: 0.0
    enableHighlight: true
    enableFacets: true

    # Performance
    bulkSize: 1000
    flushInterval: "1s"
    enableCompression: false

    # TLS
    enableTLS: false
    tlsCertFile: ""
    tlsKeyFile: ""
    tlsCAFile: ""
    insecureSkipVerify: false

    # Observability
    enableMetrics: true
    enableTracing: true

The extension loads config from extensions.search first, falling back to search.

Programmatic Configuration

ext := search.NewExtension(
    search.WithDriver("meilisearch"),
    search.WithURL("http://localhost:7700"),
    search.WithAPIKey("masterKey"),
    search.WithDefaultLimit(25),
)

Or provide a complete config:

ext := search.NewExtensionWithConfig(search.Config{
    Driver:   "elasticsearch",
    Hosts:    []string{"http://node1:9200", "http://node2:9200"},
    Username: "elastic",
    Password: "changeme",
})

Config Struct Reference

Config

Source: config.go

FieldTypeDefaultDescription
Driverstring"inmemory"Search backend
URLstring""Connection URL
Hosts[]stringnilMultiple host URLs (Elasticsearch, Typesense)
Usernamestring""Basic auth username
Passwordstring""Basic auth password
APIKeystring""API key (Typesense)
MaxConnectionsint10Maximum connections in pool
MaxIdleConnectionsint5Maximum idle connections
ConnectTimeouttime.Duration5sConnection timeout
RequestTimeouttime.Duration30sRequest timeout
KeepAlivetime.Duration30sConnection keepalive
MaxRetriesint3Max retry attempts
RetryBackofftime.Duration100msInitial retry backoff
RetryOnTimeoutbooltrueRetry on timeout errors
DefaultLimitint20Default search results limit
MaxLimitint100Maximum allowed search results limit
DefaultMinScorefloat640.0Minimum relevance score
EnableHighlightbooltrueEnable result highlighting
EnableFacetsbooltrueEnable faceted search
BulkSizeint1000Bulk indexing batch size
FlushIntervaltime.Duration1sBulk flush interval
EnableCompressionboolfalseEnable request compression
EnableTLSboolfalseEnable TLS
TLSCertFilestring""TLS certificate file
TLSKeyFilestring""TLS key file
TLSCAFilestring""TLS CA file
InsecureSkipVerifyboolfalseSkip TLS verification
EnableMetricsbooltrueEnable metrics
EnableTracingbooltrueEnable tracing
RequireConfigboolfalseFail if config missing from ConfigManager

Validation

Config.Validate() checks:

  • Driver is one of inmemory, elasticsearch, meilisearch, typesense
  • Elasticsearch requires URL or Hosts
  • Meilisearch requires URL
  • Typesense requires URL or Hosts, plus APIKey

Option Helpers

FunctionDescription
WithDriver(driver)Set the search backend driver
WithURL(url)Set the connection URL
WithHosts(hosts...)Set multiple host URLs
WithAuth(username, password)Set basic auth credentials
WithAPIKey(apiKey)Set API key (Typesense)
WithMaxConnections(max)Set connection pool size
WithTimeout(timeout)Set request timeout
WithDefaultLimit(limit)Set default results limit
WithMaxLimit(limit)Set maximum results limit
WithTLS(certFile, keyFile, caFile)Enable TLS with certificates
WithMetrics(enable)Toggle metrics collection
WithTracing(enable)Toggle distributed tracing
WithRequireConfig(require)Require config from ConfigManager
WithConfig(config)Provide a complete config struct

How is this guide?

On this page