summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go')
-rw-r--r--vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go102
1 files changed, 102 insertions, 0 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go
new file mode 100644
index 000000000..07f61b331
--- /dev/null
+++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go
@@ -0,0 +1,102 @@
+package elastic
+
+type GeoHashGridAggregation struct {
+ field string
+ precision int
+ size int
+ shardSize int
+ subAggregations map[string]Aggregation
+ meta map[string]interface{}
+}
+
+func NewGeoHashGridAggregation() *GeoHashGridAggregation {
+ return &GeoHashGridAggregation{
+ subAggregations: make(map[string]Aggregation),
+ precision: -1,
+ size: -1,
+ shardSize: -1,
+ }
+}
+
+func (a *GeoHashGridAggregation) Field(field string) *GeoHashGridAggregation {
+ a.field = field
+ return a
+}
+
+func (a *GeoHashGridAggregation) Precision(precision int) *GeoHashGridAggregation {
+ a.precision = precision
+ return a
+}
+
+func (a *GeoHashGridAggregation) Size(size int) *GeoHashGridAggregation {
+ a.size = size
+ return a
+}
+
+func (a *GeoHashGridAggregation) ShardSize(shardSize int) *GeoHashGridAggregation {
+ a.shardSize = shardSize
+ return a
+}
+
+func (a *GeoHashGridAggregation) SubAggregation(name string, subAggregation Aggregation) *GeoHashGridAggregation {
+ a.subAggregations[name] = subAggregation
+ return a
+}
+
+func (a *GeoHashGridAggregation) Meta(metaData map[string]interface{}) *GeoHashGridAggregation {
+ a.meta = metaData
+ return a
+}
+
+func (a *GeoHashGridAggregation) Source() (interface{}, error) {
+ // Example:
+ // {
+ // "aggs": {
+ // "new_york": {
+ // "geohash_grid": {
+ // "field": "location",
+ // "precision": 5
+ // }
+ // }
+ // }
+ // }
+
+ source := make(map[string]interface{})
+ opts := make(map[string]interface{})
+ source["geohash_grid"] = opts
+
+ if a.field != "" {
+ opts["field"] = a.field
+ }
+
+ if a.precision != -1 {
+ opts["precision"] = a.precision
+ }
+
+ if a.size != -1 {
+ opts["size"] = a.size
+ }
+
+ if a.shardSize != -1 {
+ opts["shard_size"] = a.shardSize
+ }
+
+ // AggregationBuilder (SubAggregations)
+ if len(a.subAggregations) > 0 {
+ aggsMap := make(map[string]interface{})
+ source["aggregations"] = aggsMap
+ for name, aggregate := range a.subAggregations {
+ src, err := aggregate.Source()
+ if err != nil {
+ return nil, err
+ }
+ aggsMap[name] = src
+ }
+ }
+
+ if len(a.meta) > 0 {
+ source["meta"] = a.meta
+ }
+
+ return source, nil
+}