Sobes.tech
Middle+

Is there experience working with Elasticsearch as a database (not for logs)?

sobes.tech AI

Answer from AI

Yes, Elasticsearch can be used as a database for storing and searching structured data, not just for logs. In this case, it acts as a distributed full-text search engine with analytics capabilities.

The work experience includes:

  • Indexing documents with arbitrary JSON structure
  • Using powerful DSL for queries (filters, aggregations)
  • Configuring mappings for optimal storage and search
  • Ensuring cluster scalability and fault tolerance

Example of usage in Go with the official client:

import (
    "context"
    "github.com/elastic/go-elasticsearch/v8"
    "strings"
    "fmt"
)

func main() {
    es, _ := elasticsearch.NewDefaultClient()
    doc := `{"user":"john","age":30}`
    res, err := es.Index(
        "users",
        strings.NewReader(doc),
        es.Index.WithDocumentID("1"),
        es.Index.WithContext(context.Background()),
    )
    if err != nil {
        panic(err)
    }
    defer res.Body.Close()
    fmt.Println(res)
}

Elasticsearch is suitable for applications requiring fast search and analytics but does not replace traditional relational databases for transactional tasks.