Skip to content

Commit e0f05d9

Browse files
authored
doc: cleanup (#7)
1 parent bd6436a commit e0f05d9

File tree

4 files changed

+53
-151
lines changed

4 files changed

+53
-151
lines changed

README.md

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# esquery
1+
# opensearch query builder
22

3-
[![](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue&style=flat-square)](https://godoc.org/github.com/aquasecurity/esquery) [![](https://img.shields.io/github/license/aquasecurity/esquery?style=flat-square)](LICENSE) [![Build Status](https://travis-ci.org/aquasecurity/esquery.svg?branch=master)](https://travis-ci.org/aquasecurity/esquery)
3+
[![](https://img.shields.io/github/license/aquasecurity/esquery?style=flat-square)](LICENSE) [![Build Status](https://circleci.com/gh/deliveroo/os_query.svg?branch=main)](https://app.circleci.com/pipelines/github/deliveroo/os_query?branch=main)
44

55

6-
**A non-obtrusive, idiomatic and easy-to-use query and aggregation builder for the [official Go client](https://github.com/elastic/go-elasticsearch) for [ElasticSearch](https://www.elastic.co/products/elasticsearch).**
6+
**A non-obtrusive, idiomatic and easy-to-use query and aggregation builder for the [official Opensearch client](https://opensearch.org/docs/latest/clients/go/) for [Opensearch](https://opensearch.org/).**
77

88
## Table of Contents
99

@@ -34,65 +34,59 @@ This is an early release, API may still change.
3434

3535
`esquery` is a Go module. To install, simply run this in your project's root directory:
3636

37-
```bash
38-
go get github.com/aquasecurity/esquery
39-
```
40-
4137
## Usage
4238

43-
esquery provides a [method chaining](https://en.wikipedia.org/wiki/Method_chaining)-style API for building and executing queries and aggregations. It does not wrap the official Go client nor does it require you to change your existing code in order to integrate the library. Queries can be directly built with `esquery`, and executed by passing an `*elasticsearch.Client` instance (with optional search parameters). Results are returned as-is from the official client (e.g. `*esapi.Response` objects).
39+
it provides a [method chaining](https://en.wikipedia.org/wiki/Method_chaining)-style API for building and executing queries and aggregations. It does not wrap the official Go client nor does it require you to change your existing code in order to integrate the library. Queries can be directly built, and executed by passing an `*opensearch.Client` instance (with optional search parameters). Results are returned as-is from the official client (e.g. `*opensearchapi.Response` objects).
4440

4541
Getting started is extremely simple:
4642

4743
```go
4844
package main
4945

5046
import (
51-
"context"
5247
"log"
5348

54-
"github.com/aquasecurity/esquery"
55-
"github.com/elastic/go-elasticsearch/v7"
49+
"github.com/opensearch-project/opensearch-go/v2"
50+
51+
oq "github.com/deliveroo/os_query"
5652
)
5753

5854
func main() {
59-
// connect to an ElasticSearch instance
60-
es, err := elasticsearch.NewDefaultClient()
61-
if err != nil {
62-
log.Fatalf("Failed creating client: %s", err)
63-
}
64-
65-
// run a boolean search query
66-
res, err := esquery.Search().
67-
Query(
68-
esquery.
69-
Bool().
70-
Must(esquery.Term("title", "Go and Stuff")).
71-
Filter(esquery.Term("tag", "tech")),
72-
).
73-
Aggs(
74-
esquery.Avg("average_score", "score"),
75-
esquery.Max("max_score", "score"),
76-
).
77-
Size(20).
78-
Run(
79-
es,
80-
es.Search.WithContext(context.TODO()),
81-
es.Search.WithIndex("test"),
82-
)
83-
if err != nil {
84-
log.Fatalf("Failed searching for stuff: %s", err)
85-
}
86-
87-
defer res.Body.Close()
88-
89-
// ...
55+
// connect to an Opensearch instance
56+
client, err := opensearch.NewDefaultClient()
57+
if err != nil {
58+
log.Fatalf("Failed creating client: %s", err)
59+
}
60+
61+
query := oq.Query(
62+
oq.
63+
Bool().
64+
Must(oq.Term("title", "Go and Stuff")).
65+
Filter(oq.Term("tag", "tech")),
66+
).
67+
Aggs(
68+
oq.Avg("average_score", "score"),
69+
oq.Max("max_score", "score"),
70+
).
71+
Size(20)
72+
73+
queryString, err := query.MarshalJSON()
74+
if err != nil {
75+
log.Fatal("Failed creating query")
76+
}
77+
// run a boolean search query
78+
search := client.Search
79+
res, err := search(search.WithQuery(string(queryString)))
80+
if err != nil {
81+
log.Fatal("Failed executing query")
82+
}
83+
84+
defer res.Body.Close()
9085
}
9186
```
9287

9388
## Notes
9489

95-
* `esquery` currently supports version 7 of the ElasticSearch Go client.
9690
* The library cannot currently generate "short queries". For example, whereas
9791
ElasticSearch can accept this:
9892

es.go

Lines changed: 0 additions & 108 deletions
This file was deleted.

os.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package os_query
2+
3+
// Mappable is the interface implemented by the various query and aggregation
4+
// types provided by the package. It allows the library to easily transform the
5+
// different queries to "generic" maps that can be easily encoded to JSON.
6+
type Mappable interface {
7+
Map() map[string]interface{}
8+
}
9+
10+
// Aggregation is an interface that each aggregation type must implement. It
11+
// is simply an extension of the Mappable interface to include a Named function,
12+
// which returns the name of the aggregation.
13+
type Aggregation interface {
14+
Mappable
15+
Name() string
16+
}

es_test.go renamed to os_test.go

File renamed without changes.

0 commit comments

Comments
 (0)