Releases: elastic/go-elasticsearch
9.0.0
- The client now requires Go 1.23 or later.
New
- This release introduces an optional package for the
TypedAPI
namedesdsl
.
It provides a domain-specific language (DSL) for building Elasticsearch queries in Go.
The DSL is designed to simplify query construction, making it easier to build complex queries without writing raw JSON.
// create index
{
// delete index if exists
if existsRes, err := es.Indices.Exists("test").IsSuccess(context.Background()); err != nil {
log.Println(err)
return
} else if existsRes {
if ok, _ := es.Indices.Delete("test").IsSuccess(context.Background()); !ok {
log.Fatalf("Error deleting index: %v\n", err)
}
log.Println("Index deleted:", "test")
} else {
log.Println("Index does not exist:", "test")
}
mappings := esdsl.NewTypeMapping().
AddProperty("name", esdsl.NewTextProperty()).
AddProperty("age", esdsl.NewIntegerNumberProperty())
createRes, err := es.Indices.Create("test").Mappings(mappings).Do(context.Background())
if err != nil {
log.Println(err)
return
}
log.Printf("Index created: %#v\n", createRes)
}
// index document
{
documents := []Document{
{"Alice", 30},
{"Bob", 25},
{"Charlie", 35},
}
bulk := es.Bulk().Index("test")
for _, document := range documents {
err := bulk.IndexOp(types.IndexOperation{}, document)
if err != nil {
log.Println("Error indexing document:", err)
}
}
bulkRes, err := bulk.Refresh(refresh.Waitfor).Do(context.Background())
if err != nil {
log.Println(err)
return
}
if bulkRes.Errors {
log.Println("Some documents failed to index")
for _, item := range bulkRes.Items {
for operationType, responseItem := range item {
if responseItem.Error != nil {
log.Println("Operation:", operationType)
log.Println("Response:", responseItem)
}
}
}
}
indexedDocs := 0
for _, item := range bulkRes.Items {
for _, responseItem := range item {
if responseItem.Error == nil {
indexedDocs++
}
}
}
log.Println("Documents indexed:", indexedDocs)
}
// calculate median age
{
searchRes, err := es.Search().
Index("test").
Size(0).
AddAggregation("median_age", esdsl.NewPercentilesAggregation().Field("age").Percents(50)).
Do(context.Background())
if err != nil {
log.Println(err)
return
}
if agg, ok := searchRes.Aggregations["median_age"].(*types.TDigestPercentilesAggregate); ok {
if val, ok := agg.Values.(map[string]interface{})["50.0"]; ok {
log.Println("Median age:", val)
}
}
}
// search documents
{
matchRes, err := es.Search().
Index("test").
Query(esdsl.NewBoolQuery().
Must(esdsl.NewMatchQuery("name", "Alice")).
Filter(esdsl.NewNumberRangeQuery("age").Gte(20).Lte(40))).
Sort(esdsl.NewSortOptions().AddSortOption("age", esdsl.NewFieldSort(sortorder.Asc))).
Size(10).
Do(context.Background())
if err != nil {
log.Println(err)
return
}
if matchRes.Hits.Total.Value > 0 {
for _, hit := range matchRes.Hits.Hits {
doc := Document{}
err := json.Unmarshal(hit.Source_, &doc)
if err != nil {
log.Println("Error unmarshalling document:", err)
continue
}
log.Printf("Document ID: %s, Name: %s, Age: %d\n", *hit.Id_, doc.Name, doc.Age)
}
} else {
log.Println("No documents found")
}
}
API
- Updated APIs to 9.0.0
Typed API
- Update APIs to 9.0.0 (52c473e)
8.18.0
- Update
elastictransport
to8.7.0
. - Thanks to @zaneli, the
TypedClient
can now be used in theBulkIndexer
.
New
- This release adds a
BaseClient
constructor with no attached APIs, allowing it to be used purely as a transport layer instead of a full-featured API client.
baseClient, err := elasticsearch.NewBaseClient(elasticsearch.Config{
Addresses: []string{
"http://localhost:9200",
},
})
if err != nil {
log.Println(err)
return
}
res, err := esapi.InfoRequest{
Pretty: false,
Human: false,
ErrorTrace: false,
FilterPath: nil,
Header: nil,
Instrument: baseClient.InstrumentationEnabled(),
}.Do(context.Background(), baseClient)
if err != nil {
log.Println(err)
return
}
defer res.Body.Close()
if res.IsError() {
log.Println("Error response:", res)
return
}
var infoMap map[string]interface{}
if err := json.NewDecoder(res.Body).Decode(&infoMap); err != nil {
log.Println("Error parsing response:", err)
return
}
log.Printf("Elasticsearch version esapi: %s\n", infoMap["version"].(map[string]interface{})["number"])
typedRes, err := info.New(baseClient).Do(context.Background())
if err != nil {
log.Println(err)
return
}
log.Printf("Elasticsearch version typedapi: %s\n", typedRes.Version.Int)
API
- Updated APIs to 8.18.0
Typed API
- Update APIs to 8.18.0 (f6a370d)
v8.17.1
v8.17.0
- Expose BulkIndexer total flushed bytes metric #914 thanks to @aureleoules
API
Updated APIs to 8.17.0
Typed API
Update APIs to latest elasticsearch-specification 8.17
v8.16.0
API
InferenceStreamInference
DocumentationQueryRulesTest
DocumentationIngest.DeleteIPLocationDatabase
DocumentationIngest.GetIPLocationDatabase
DocumentationIngest.PutIPLocationDatabase
Documentation
Typed API
Update APIs to latest elasticsearch-specification 8.16
8.15.0
API
- API is generated from the Elasticsearch 8.15.0 specification.
Typed API
Update APIs to latest elasticsearch-specification 8.15
8.14.0
API
New APIs:
- ConnectorUpdateActiveFiltering Documentation
- ConnectorUpdateFilteringValidation Documentation
- TextStructureFindFieldStructure Documentation
- TextStructureFindMessageStructure Documentation
Typed API
New APIs:
- UpdateTrainedModelDeployment Documentation
Transport
- Fixed a deadlock in the connection pool elastic/elastic-transport-go#20
8.13.1
Typed API
Update APIs to latest elasticsearch-specification 8.13
Fixes
This patch release brings a fix to the initialisation of the Request
in endpoints which would prevent using the shortcuts for fields.
Canonical.Request()
method was unaffected.
Autoscaling.PutAutoscalingPolicy
Indices.Downsample
Indices.PutSettings
Indices.SimulateTemplate
Inference.PutModel
Logstash.PutPipeline
Ml.ValidateDetector
SearchApplication.Put
8.13.0
API
New APIS:
-
ConnectorSecretGet
-
ConnectorSecretPost
-
ConnectorSecretPut
-
ConnectorSecretDelete
-
ConnectorUpdateIndexName
-
ConnectorUpdateNative
-
ConnectorUpdateStatus
-
ConnectorUpdateAPIKeyDocumentID
-
ConnectorUpdateServiceDocumentType
-
EsqlAsyncQuery
Documentation -
EsqlAsyncQueryGet
Documentation -
ProfilingFlamegraph
Documentation -
ProfilingStacktraces
Documentation -
TextStructureTestGrokPattern
Documentation -
Indices.ResolveCluster
Documentation -
Security.QueryUser
Documentation
Typed API
indices.ResolveCluster
Documentationtextstructure.TestGrokPattern
Documentation
Thanks to @pakio, transport now has an optional pool based compression option. elastic/elastic-transport-go#19
And to @tblyler for fixing a very subtle memory leak in the BulkIndexer
. #797
8.12.1
- Fix: ticker memory leak in bulk indexer due to internal flush call resetting the ticker. #797
- Fix: Scroll now uses the body to pass the scroll_id. #785
- Add: generated UnmarshalJSON for Requests to allow injecting payloads using aliases.
Many thanks to @tblyler, @frkntplglu and @HaraldNordgren for their contribution!