Skip to content

Commit fb1c228

Browse files
authored
Add changelog for 9.0.0 (elastic#1005)
1 parent f862632 commit fb1c228

File tree

1 file changed

+141
-1
lines changed

1 file changed

+141
-1
lines changed

CHANGELOG.md

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,143 @@
1+
# 9.0.0
2+
3+
* The client now requires **Go 1.23** or later.
4+
5+
## New
6+
7+
* This release introduces an optional package for the `TypedAPI` named `esdsl`.
8+
It provides a domain-specific language (DSL) for building Elasticsearch queries in Go.
9+
The DSL is designed to simplify query construction, making it easier to build complex queries without writing raw JSON.
10+
11+
```go
12+
// create index
13+
{
14+
// delete index if exists
15+
if existsRes, err := es.Indices.Exists("test").IsSuccess(context.Background()); err != nil {
16+
log.Println(err)
17+
return
18+
} else if existsRes {
19+
if ok, _ := es.Indices.Delete("test").IsSuccess(context.Background()); !ok {
20+
log.Fatalf("Error deleting index: %v\n", err)
21+
}
22+
log.Println("Index deleted:", "test")
23+
} else {
24+
log.Println("Index does not exist:", "test")
25+
}
26+
27+
mappings := esdsl.NewTypeMapping().
28+
AddProperty("name", esdsl.NewTextProperty()).
29+
AddProperty("age", esdsl.NewIntegerNumberProperty())
30+
31+
createRes, err := es.Indices.Create("test").Mappings(mappings).Do(context.Background())
32+
if err != nil {
33+
log.Println(err)
34+
return
35+
}
36+
37+
log.Printf("Index created: %#v\n", createRes)
38+
}
39+
40+
// index document
41+
{
42+
documents := []Document{
43+
{"Alice", 30},
44+
{"Bob", 25},
45+
{"Charlie", 35},
46+
}
47+
48+
bulk := es.Bulk().Index("test")
49+
for _, document := range documents {
50+
err := bulk.IndexOp(types.IndexOperation{}, document)
51+
if err != nil {
52+
log.Println("Error indexing document:", err)
53+
}
54+
}
55+
bulkRes, err := bulk.Refresh(refresh.Waitfor).Do(context.Background())
56+
if err != nil {
57+
log.Println(err)
58+
return
59+
}
60+
if bulkRes.Errors {
61+
log.Println("Some documents failed to index")
62+
for _, item := range bulkRes.Items {
63+
for operationType, responseItem := range item {
64+
if responseItem.Error != nil {
65+
log.Println("Operation:", operationType)
66+
log.Println("Response:", responseItem)
67+
}
68+
}
69+
}
70+
}
71+
indexedDocs := 0
72+
for _, item := range bulkRes.Items {
73+
for _, responseItem := range item {
74+
if responseItem.Error == nil {
75+
indexedDocs++
76+
}
77+
}
78+
}
79+
80+
log.Println("Documents indexed:", indexedDocs)
81+
}
82+
83+
// calculate median age
84+
{
85+
searchRes, err := es.Search().
86+
Index("test").
87+
Size(0).
88+
AddAggregation("median_age", esdsl.NewPercentilesAggregation().Field("age").Percents(50)).
89+
Do(context.Background())
90+
if err != nil {
91+
log.Println(err)
92+
return
93+
}
94+
95+
if agg, ok := searchRes.Aggregations["median_age"].(*types.TDigestPercentilesAggregate); ok {
96+
if val, ok := agg.Values.(map[string]interface{})["50.0"]; ok {
97+
log.Println("Median age:", val)
98+
}
99+
}
100+
}
101+
102+
// search documents
103+
{
104+
matchRes, err := es.Search().
105+
Index("test").
106+
Query(esdsl.NewBoolQuery().
107+
Must(esdsl.NewMatchQuery("name", "Alice")).
108+
Filter(esdsl.NewNumberRangeQuery("age").Gte(20).Lte(40))).
109+
Sort(esdsl.NewSortOptions().AddSortOption("age", esdsl.NewFieldSort(sortorder.Asc))).
110+
Size(10).
111+
Do(context.Background())
112+
if err != nil {
113+
log.Println(err)
114+
return
115+
}
116+
if matchRes.Hits.Total.Value > 0 {
117+
for _, hit := range matchRes.Hits.Hits {
118+
doc := Document{}
119+
err := json.Unmarshal(hit.Source_, &doc)
120+
if err != nil {
121+
log.Println("Error unmarshalling document:", err)
122+
continue
123+
}
124+
log.Printf("Document ID: %s, Name: %s, Age: %d\n", *hit.Id_, doc.Name, doc.Age)
125+
}
126+
} else {
127+
log.Println("No documents found")
128+
}
129+
}
130+
```
131+
132+
# API
133+
134+
* Updated APIs to 9.0.0
135+
136+
# Typed API
137+
138+
* Update APIs to 9.0.0 ([52c473e](https://github.com/elastic/elasticsearch-specification/tree/52c473efb1fb5320a5bac12572d0b285882862fb))
139+
140+
1141
# 8.18.0
2142

3143
* Update `elastictransport` to `8.7.0`.
@@ -58,7 +198,7 @@ log.Printf("Elasticsearch version typedapi: %s\n", typedRes.Version.Int)
58198

59199
# Typed API
60200

61-
* Update APIs to 8.18 ([cbfcc73](https://github.com/elastic/elasticsearch-specification/tree/cbfcc73d01310bed2a480ec35aaef98138b598e5))
201+
* Update APIs to 8.18.0 ([f6a370d](https://github.com/elastic/elasticsearch-specification/tree/f6a370d0fba975752c644fc730f7c45610e28f36))
62202

63203
# 8.17.1
64204

0 commit comments

Comments
 (0)