From a2a8d54bb6e7124bd5d9381707267e924598eea6 Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Sat, 1 Apr 2017 02:41:27 +0530 Subject: [PATCH] Add `access` format support for Elasticsearch notification target (#4006) This change adds `access` format support for notifications to a Elasticsearch server, and it refactors `namespace` format support. In the case of `access` format, for each event in Minio, a JSON document is inserted into Elasticsearch with its timestamp set to the event's timestamp, and with the ID generated automatically by elasticsearch. No events are modified or deleted in this mode. In the case of `namespace` format, for each event in Minio, a JSON document is keyed together by the bucket and object name is updated in Elasticsearch. In the case of an object being created or over-written in Minio, a new document or an existing document is inserted into the Elasticsearch index. If an object is deleted in Minio, the corresponding document is deleted from the Elasticsearch index. Additionally, this change upgrades Elasticsearch support to the 5.x series. This is a breaking change, and users of previous elasticsearch versions should upgrade. Also updates documentation on Elasticsearch notification target usage and has a link to an elasticsearch upgrade guide. This is the last patch that finally resolves #3928. --- cmd/notifiers.go | 14 + cmd/notify-elasticsearch.go | 101 ++- cmd/notify-mysql.go | 39 +- cmd/notify-postgresql.go | 39 +- cmd/notify-redis.go | 36 +- docs/bucket/notifications/README.md | 137 ++-- .../x/net/context/ctxhttp/ctxhttp.go | 74 ++ .../x/net/context/ctxhttp/ctxhttp_pre17.go | 147 ++++ .../olivere/elastic.v3/backoff/LICENSE | 22 - .../olivere/elastic.v3/backoff/backoff.go | 159 ---- .../olivere/elastic.v3/delete_by_query.go | 301 -------- .../elastic.v3/indices_delete_warmer.go | 130 ---- .../olivere/elastic.v3/indices_get_warmer.go | 193 ----- .../olivere/elastic.v3/indices_put_alias.go | 110 --- .../olivere/elastic.v3/indices_put_warmer.go | 221 ------ .../olivere/elastic.v3/indices_refresh.go | 93 --- .../gopkg.in/olivere/elastic.v3/optimize.go | 129 ---- .../gopkg.in/olivere/elastic.v3/percolate.go | 308 -------- .../gopkg.in/olivere/elastic.v3/reindexer.go | 270 ------- vendor/gopkg.in/olivere/elastic.v3/scan.go | 358 --------- vendor/gopkg.in/olivere/elastic.v3/scroll.go | 205 ----- .../elastic.v3/search_queries_missing.go | 67 -- .../olivere/elastic.v3/search_queries_not.go | 45 -- .../search_queries_template_query.go | 84 --- .../CHANGELOG-3.0.md | 0 .../olivere/elastic.v5/CHANGELOG-5.0.md | 195 +++++ .../CONTRIBUTING.md | 0 .../{elastic.v3 => elastic.v5}/CONTRIBUTORS | 28 + .../ISSUE_TEMPLATE.md | 1 + .../{elastic.v3 => elastic.v5}/LICENSE | 0 .../{elastic.v3 => elastic.v5}/README.md | 106 ++- .../elastic.v5/acknowledged_response.go | 11 + vendor/gopkg.in/olivere/elastic.v5/backoff.go | 152 ++++ .../{elastic.v3 => elastic.v5}/bulk.go | 110 ++- .../bulk_delete_request.go | 19 +- .../bulk_index_request.go | 99 ++- .../bulk_processor.go | 37 +- .../bulk_request.go | 4 +- .../bulk_update_request.go | 78 +- .../canonicalize.go | 8 +- .../clear_scroll.go | 8 +- .../{elastic.v3 => elastic.v5}/client.go | 403 ++++++---- .../cluster_health.go | 42 +- .../cluster_state.go | 12 +- .../cluster_stats.go | 11 +- .../{elastic.v3 => elastic.v5}/connection.go | 2 +- .../{elastic.v3 => elastic.v5}/count.go | 8 +- .../{elastic.v3 => elastic.v5}/decoder.go | 2 +- .../{elastic.v3 => elastic.v5}/delete.go | 68 +- .../olivere/elastic.v5/delete_by_query.go | 649 ++++++++++++++++ .../delete_template.go | 23 +- .../olivere/{elastic.v3 => elastic.v5}/doc.go | 6 +- .../{elastic.v3 => elastic.v5}/errors.go | 2 +- .../{elastic.v3 => elastic.v5}/exists.go | 22 +- .../{elastic.v3 => elastic.v5}/explain.go | 19 +- .../fetch_source_context.go | 2 +- .../{elastic.v3 => elastic.v5}/field_stats.go | 13 +- .../{elastic.v3 => elastic.v5}/geo_point.go | 2 +- .../olivere/{elastic.v3 => elastic.v5}/get.go | 70 +- .../get_template.go | 12 +- .../{elastic.v3 => elastic.v5}/highlight.go | 22 +- .../{elastic.v3 => elastic.v5}/index.go | 88 ++- .../olivere/elastic.v5/indices_analyze.go | 280 +++++++ .../indices_close.go | 12 +- .../indices_create.go | 15 +- .../indices_delete.go | 12 +- .../indices_delete_template.go | 12 +- .../indices_exists.go | 12 +- .../indices_exists_template.go | 12 +- .../indices_exists_type.go | 16 +- .../indices_flush.go | 12 +- .../indices_forcemerge.go | 23 +- .../{elastic.v3 => elastic.v5}/indices_get.go | 12 +- .../indices_get_aliases.go | 72 +- .../elastic.v5/indices_get_field_mapping.go | 184 +++++ .../indices_get_mapping.go | 12 +- .../indices_get_settings.go | 12 +- .../indices_get_template.go | 12 +- .../indices_open.go | 12 +- .../olivere/elastic.v5/indices_put_alias.go | 296 ++++++++ .../indices_put_mapping.go | 12 +- .../indices_put_settings.go | 12 +- .../indices_put_template.go | 12 +- .../olivere/elastic.v5/indices_refresh.go | 105 +++ .../olivere/elastic.v5/indices_rollover.go | 268 +++++++ .../olivere/elastic.v5/indices_shrink.go | 174 +++++ .../indices_stats.go | 12 +- .../elastic.v5/ingest_delete_pipeline.go | 124 +++ .../olivere/elastic.v5/ingest_get_pipeline.go | 118 +++ .../olivere/elastic.v5/ingest_put_pipeline.go | 152 ++++ .../elastic.v5/ingest_simulate_pipeline.go | 157 ++++ .../{elastic.v3 => elastic.v5}/inner_hit.go | 24 +- .../{elastic.v3 => elastic.v5}/logger.go | 2 +- .../{elastic.v3 => elastic.v5}/mget.go | 135 ++-- .../{elastic.v3 => elastic.v5}/msearch.go | 11 +- .../mtermvectors.go | 10 +- .../{elastic.v3 => elastic.v5}/nodes_info.go | 21 +- .../olivere/elastic.v5/nodes_stats.go | 707 ++++++++++++++++++ .../{elastic.v3 => elastic.v5}/ping.go | 9 +- .../{elastic.v3 => elastic.v5}/plugins.go | 6 +- .../put_template.go} | 21 +- .../{elastic.v3 => elastic.v5}/query.go | 2 +- .../{elastic.v3 => elastic.v5}/reindex.go | 137 ++-- .../{elastic.v3 => elastic.v5}/request.go | 2 +- .../{elastic.v3 => elastic.v5}/rescore.go | 2 +- .../{elastic.v3 => elastic.v5}/rescorer.go | 2 +- .../{elastic.v3 => elastic.v5}/response.go | 2 +- vendor/gopkg.in/olivere/elastic.v5/retrier.go | 62 ++ .../backoff => elastic.v5}/retry.go | 27 +- .../olivere/elastic.v5/run-es-5.0.0-beta1.sh | 1 + .../olivere/elastic.v5/run-es-5.0.0-rc1.sh | 1 + .../olivere/elastic.v5/run-es-5.0.0.sh | 1 + .../olivere/elastic.v5/run-es-5.0.1.sh | 1 + .../olivere/elastic.v5/run-es-5.1.1.sh | 1 + .../olivere/elastic.v5/run-es-5.1.2.sh | 1 + .../olivere/elastic.v5/run-es-5.2.0.sh | 1 + .../olivere/elastic.v5/run-es-5.2.1.sh | 1 + .../olivere/elastic.v5/run-es-5.2.2.sh | 1 + .../{elastic.v3 => elastic.v5}/script.go | 6 +- vendor/gopkg.in/olivere/elastic.v5/scroll.go | 445 +++++++++++ .../{elastic.v3 => elastic.v5}/search.go | 167 +++-- .../{elastic.v3 => elastic.v5}/search_aggs.go | 163 ++-- .../search_aggs_bucket_children.go | 4 +- .../search_aggs_bucket_date_histogram.go | 4 +- .../search_aggs_bucket_date_range.go | 6 +- .../search_aggs_bucket_filter.go | 4 +- .../search_aggs_bucket_filters.go | 4 +- .../search_aggs_bucket_geo_distance.go | 6 +- .../search_aggs_bucket_geohash_grid.go | 0 .../search_aggs_bucket_global.go | 4 +- .../search_aggs_bucket_histogram.go | 4 +- .../search_aggs_bucket_missing.go | 4 +- .../search_aggs_bucket_nested.go | 4 +- .../search_aggs_bucket_range.go | 6 +- .../search_aggs_bucket_reverse_nested.go | 2 +- .../search_aggs_bucket_sampler.go | 40 +- .../search_aggs_bucket_significant_terms.go | 18 +- .../search_aggs_bucket_terms.go | 55 +- .../search_aggs_metrics_avg.go | 4 +- .../search_aggs_metrics_cardinality.go | 4 +- .../search_aggs_metrics_extended_stats.go | 4 +- .../search_aggs_metrics_geo_bounds.go | 4 +- .../search_aggs_metrics_max.go | 4 +- .../search_aggs_metrics_min.go | 4 +- .../search_aggs_metrics_percentile_ranks.go | 4 +- .../search_aggs_metrics_percentiles.go | 4 +- .../search_aggs_metrics_stats.go | 4 +- .../search_aggs_metrics_sum.go | 4 +- .../search_aggs_metrics_top_hits.go | 16 +- .../search_aggs_metrics_value_count.go | 4 +- .../search_aggs_pipeline_avg_bucket.go | 4 +- .../search_aggs_pipeline_bucket_script.go | 4 +- .../search_aggs_pipeline_bucket_selector.go | 4 +- .../search_aggs_pipeline_cumulative_sum.go | 4 +- .../search_aggs_pipeline_derivative.go | 4 +- .../search_aggs_pipeline_max_bucket.go | 4 +- .../search_aggs_pipeline_min_bucket.go | 4 +- .../search_aggs_pipeline_mov_avg.go | 16 +- .../search_aggs_pipeline_serial_diff.go | 4 +- .../search_aggs_pipeline_stats_bucket.go | 113 +++ .../search_aggs_pipeline_sum_bucket.go | 4 +- .../search_queries_bool.go | 12 +- .../search_queries_boosting.go | 4 +- .../search_queries_common_terms.go | 4 +- .../search_queries_constant_score.go | 4 +- .../search_queries_dis_max.go | 6 +- .../search_queries_exists.go | 4 +- .../search_queries_fsq.go | 4 +- .../search_queries_fsq_score_funcs.go | 30 +- .../search_queries_fuzzy.go | 4 +- .../search_queries_geo_bounding_box.go | 4 +- .../search_queries_geo_distance.go | 4 +- .../search_queries_geo_polygon.go | 6 +- .../search_queries_has_child.go | 20 +- .../search_queries_has_parent.go | 16 +- .../search_queries_ids.go | 4 +- .../search_queries_indices.go | 4 +- .../search_queries_match.go | 4 +- .../search_queries_match_all.go | 4 +- .../search_queries_more_like_this.go | 8 +- .../search_queries_multi_match.go | 6 +- .../search_queries_nested.go | 4 +- .../elastic.v5/search_queries_parent_id.go | 99 +++ .../elastic.v5/search_queries_percolator.go | 115 +++ .../search_queries_prefix.go | 4 +- .../search_queries_query_string.go | 6 +- .../search_queries_range.go | 4 +- .../elastic.v5/search_queries_raw_string.go | 26 + .../search_queries_regexp.go | 4 +- .../search_queries_script.go | 4 +- .../search_queries_simple_query_string.go | 6 +- .../elastic.v5/search_queries_slice.go | 53 ++ .../search_queries_term.go | 4 +- .../search_queries_terms.go | 4 +- .../search_queries_type.go | 4 +- .../search_queries_wildcard.go | 4 +- .../search_request.go | 70 +- .../search_source.go | 120 +-- .../{elastic.v3 => elastic.v5}/sort.go | 135 ++-- .../{elastic.v3 => elastic.v5}/suggest.go | 69 +- .../suggest_field.go | 42 +- .../{elastic.v3 => elastic.v5}/suggester.go | 2 +- .../suggester_completion.go | 17 +- .../suggester_completion_fuzzy.go | 10 +- .../suggester_context.go | 2 +- .../suggester_context_category.go | 6 +- .../suggester_context_geo.go | 12 +- .../suggester_phrase.go | 29 +- .../suggester_term.go | 18 +- .../tasks_cancel.go | 10 +- .../{elastic.v3 => elastic.v5}/tasks_list.go | 10 +- .../{elastic.v3 => elastic.v5}/termvectors.go | 14 +- .../{elastic.v3 => elastic.v5}/update.go | 84 +-- .../update_by_query.go | 242 +++--- .../uritemplates/LICENSE | 0 .../uritemplates/uritemplates.go | 0 .../uritemplates/utils.go | 0 vendor/vendor.json | 24 +- 218 files changed, 7041 insertions(+), 4510 deletions(-) create mode 100644 vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go create mode 100644 vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/backoff/LICENSE delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/backoff/backoff.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/delete_by_query.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/indices_delete_warmer.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/indices_get_warmer.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/indices_put_alias.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/indices_put_warmer.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/indices_refresh.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/optimize.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/percolate.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/reindexer.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/scan.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/scroll.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/search_queries_missing.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/search_queries_not.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v3/search_queries_template_query.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/CHANGELOG-3.0.md (100%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/CHANGELOG-5.0.md rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/CONTRIBUTING.md (100%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/CONTRIBUTORS (67%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/ISSUE_TEMPLATE.md (90%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/LICENSE (100%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/README.md (75%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/acknowledged_response.go create mode 100644 vendor/gopkg.in/olivere/elastic.v5/backoff.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/bulk.go (74%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/bulk_delete_request.go (84%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/bulk_index_request.go (71%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/bulk_processor.go (93%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/bulk_request.go (69%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/bulk_update_request.go (79%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/canonicalize.go (81%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/clear_scroll.go (88%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/client.go (80%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/cluster_health.go (86%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/cluster_state.go (96%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/cluster_stats.go (97%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/connection.go (96%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/count.go (97%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/decoder.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/delete.go (72%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/delete_by_query.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/delete_template.go (77%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/doc.go (89%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/errors.go (98%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/exists.go (87%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/explain.go (95%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/fetch_source_context.go (96%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/field_stats.go (93%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/geo_point.go (95%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/get.go (73%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/get_template.go (85%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/highlight.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/index.go (74%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/indices_analyze.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_close.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_create.go (85%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_delete.go (88%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_delete_template.go (87%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_exists.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_exists_template.go (86%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_exists_type.go (90%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_flush.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_forcemerge.go (88%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_get.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_get_aliases.go (63%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/indices_get_field_mapping.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_get_mapping.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_get_settings.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_get_template.go (88%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_open.go (91%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/indices_put_alias.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_put_mapping.go (93%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_put_settings.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_put_template.go (91%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/indices_refresh.go create mode 100644 vendor/gopkg.in/olivere/elastic.v5/indices_rollover.go create mode 100644 vendor/gopkg.in/olivere/elastic.v5/indices_shrink.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/indices_stats.go (97%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/ingest_delete_pipeline.go create mode 100644 vendor/gopkg.in/olivere/elastic.v5/ingest_get_pipeline.go create mode 100644 vendor/gopkg.in/olivere/elastic.v5/ingest_put_pipeline.go create mode 100644 vendor/gopkg.in/olivere/elastic.v5/ingest_simulate_pipeline.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/inner_hit.go (81%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/logger.go (80%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/mget.go (51%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/msearch.go (87%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/mtermvectors.go (97%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/nodes_info.go (95%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/nodes_stats.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/ping.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/plugins.go (83%) rename vendor/gopkg.in/olivere/{elastic.v3/search_template.go => elastic.v5/put_template.go} (84%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/query.go (87%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/reindex.go (79%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/request.go (98%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/rescore.go (93%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/rescorer.go (95%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/response.go (94%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/retrier.go rename vendor/gopkg.in/olivere/{elastic.v3/backoff => elastic.v5}/retry.go (69%) create mode 100755 vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0-beta1.sh create mode 100755 vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0-rc1.sh create mode 100755 vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0.sh create mode 100755 vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.1.sh create mode 100755 vendor/gopkg.in/olivere/elastic.v5/run-es-5.1.1.sh create mode 100755 vendor/gopkg.in/olivere/elastic.v5/run-es-5.1.2.sh create mode 100755 vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.0.sh create mode 100755 vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.1.sh create mode 100755 vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.2.sh rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/script.go (94%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/scroll.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search.go (69%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs.go (82%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_children.go (90%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_date_histogram.go (97%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_date_range.go (96%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_filter.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_filters.go (95%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_geo_distance.go (95%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_geohash_grid.go (100%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_global.go (90%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_histogram.go (97%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_missing.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_nested.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_range.go (96%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_reverse_nested.go (97%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_sampler.go (76%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_significant_terms.go (90%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_bucket_terms.go (88%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_avg.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_cardinality.go (93%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_extended_stats.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_geo_bounds.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_max.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_min.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_percentile_ranks.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_percentiles.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_stats.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_sum.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_top_hits.go (85%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_metrics_value_count.go (93%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_pipeline_avg_bucket.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_pipeline_bucket_script.go (95%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_pipeline_bucket_selector.go (95%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_pipeline_cumulative_sum.go (93%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_pipeline_derivative.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_pipeline_max_bucket.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_pipeline_min_bucket.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_pipeline_mov_avg.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_pipeline_serial_diff.go (94%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_stats_bucket.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_aggs_pipeline_sum_bucket.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_bool.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_boosting.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_common_terms.go (95%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_constant_score.go (89%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_dis_max.go (93%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_exists.go (87%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_fsq.go (96%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_fsq_score_funcs.go (90%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_fuzzy.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_geo_bounding_box.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_geo_distance.go (94%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_geo_polygon.go (89%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_has_child.go (86%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_has_parent.go (84%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_ids.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_indices.go (93%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_match.go (97%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_match_all.go (87%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_more_like_this.go (98%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_multi_match.go (97%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_nested.go (92%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/search_queries_parent_id.go create mode 100644 vendor/gopkg.in/olivere/elastic.v5/search_queries_percolator.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_prefix.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_query_string.go (98%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_range.go (95%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/search_queries_raw_string.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_regexp.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_script.go (87%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_simple_query_string.go (96%) create mode 100644 vendor/gopkg.in/olivere/elastic.v5/search_queries_slice.go rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_term.go (90%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_terms.go (90%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_type.go (79%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_queries_wildcard.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_request.go (67%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/search_source.go (79%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/sort.go (71%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/suggest.go (60%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/suggest_field.go (71%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/suggester.go (87%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/suggester_completion.go (87%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/suggester_completion_fuzzy.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/suggester_context.go (82%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/suggester_context_category.go (89%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/suggester_context_geo.go (87%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/suggester_phrase.go (92%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/suggester_term.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/tasks_cancel.go (91%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/tasks_list.go (96%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/termvectors.go (96%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/update.go (78%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/update_by_query.go (82%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/uritemplates/LICENSE (100%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/uritemplates/uritemplates.go (100%) rename vendor/gopkg.in/olivere/{elastic.v3 => elastic.v5}/uritemplates/utils.go (100%) diff --git a/cmd/notifiers.go b/cmd/notifiers.go index 5da9e086e..9a016f7d8 100644 --- a/cmd/notifiers.go +++ b/cmd/notifiers.go @@ -18,6 +18,7 @@ package cmd import ( "errors" + "fmt" "github.com/minio/minio/pkg/wildcard" ) @@ -221,3 +222,16 @@ func filterRuleMatch(object string, frs []filterRule) bool { } return prefixMatch && suffixMatch } + +// A type to represent dynamic error generation functions for +// notifications. +type notificationErrorFactoryFunc func(string, ...interface{}) error + +// A function to build dynamic error generation functions for +// notifications by setting an error prefix string. +func newNotificationErrorFactory(prefix string) notificationErrorFactoryFunc { + return func(msg string, a ...interface{}) error { + s := fmt.Sprintf(msg, a...) + return fmt.Errorf("%s: %s", prefix, s) + } +} diff --git a/cmd/notify-elasticsearch.go b/cmd/notify-elasticsearch.go index e879ccff0..e9ef5f76c 100644 --- a/cmd/notify-elasticsearch.go +++ b/cmd/notify-elasticsearch.go @@ -17,14 +17,20 @@ package cmd import ( - "encoding/hex" - "errors" + "context" "fmt" "io/ioutil" + "time" "github.com/Sirupsen/logrus" - "github.com/minio/sha256-simd" - "gopkg.in/olivere/elastic.v3" + "gopkg.in/olivere/elastic.v5" +) + +var ( + esErrFunc = newNotificationErrorFactory("Elasticsearch") + + errESFormat = esErrFunc(`"format" value is invalid - it must be one of "%s" or "%s".`, formatNamespace, formatAccess) + errESIndex = esErrFunc("Index name was not specified in the configuration.") ) // elasticQueue is a elasticsearch event notification queue. @@ -39,14 +45,15 @@ func (e *elasticSearchNotify) Validate() error { if !e.Enable { return nil } - if e.Format != formatNamespace { - return fmt.Errorf( - "Elasticsearch Notifier Error: \"format\" must be \"%s\"", - formatNamespace) + if e.Format != formatNamespace && e.Format != formatAccess { + return errESFormat } if _, err := checkURL(e.URL); err != nil { return err } + if e.Index == "" { + return errESIndex + } return nil } @@ -60,15 +67,11 @@ func dialElastic(esNotify elasticSearchNotify) (*elastic.Client, error) { if !esNotify.Enable { return nil, errNotifyNotEnabled } - client, err := elastic.NewClient( + return elastic.NewClient( elastic.SetURL(esNotify.URL), elastic.SetSniff(false), elastic.SetMaxRetries(10), ) - if err != nil { - return nil, err - } - return client, nil } func newElasticNotify(accountID string) (*logrus.Logger, error) { @@ -77,23 +80,26 @@ func newElasticNotify(accountID string) (*logrus.Logger, error) { // Dial to elastic search. client, err := dialElastic(esNotify) if err != nil { - return nil, err + return nil, esErrFunc("Error dialing the server: %v", err) } // Use the IndexExists service to check if a specified index exists. - exists, err := client.IndexExists(esNotify.Index).Do() + exists, err := client.IndexExists(esNotify.Index). + Do(context.Background()) if err != nil { - return nil, err + return nil, esErrFunc("Error checking if index exists: %v", err) } // Index does not exist, attempt to create it. if !exists { var createIndex *elastic.IndicesCreateResult - createIndex, err = client.CreateIndex(esNotify.Index).Do() + createIndex, err = client.CreateIndex(esNotify.Index). + Do(context.Background()) if err != nil { - return nil, err + return nil, esErrFunc("Error creating index `%s`: %v", + esNotify.Index, err) } if !createIndex.Acknowledged { - return nil, errors.New("Index not created") + return nil, esErrFunc("Index not created") } } @@ -118,7 +124,7 @@ func newElasticNotify(accountID string) (*logrus.Logger, error) { } // Fire is required to implement logrus hook -func (q elasticClient) Fire(entry *logrus.Entry) error { +func (q elasticClient) Fire(entry *logrus.Entry) (err error) { // Reflect on eventType and Key on their native type. entryStr, ok := entry.Data["EventType"].(string) if !ok { @@ -129,25 +135,44 @@ func (q elasticClient) Fire(entry *logrus.Entry) error { return nil } - // Calculate a unique key id. Choosing sha256 here. - shaKey := sha256.Sum256([]byte(keyStr)) - keyStr = hex.EncodeToString(shaKey[:]) - - // If event matches as delete, we purge the previous index. - if eventMatch(entryStr, []string{"s3:ObjectRemoved:*"}) { - _, err := q.Client.Delete().Index(q.params.Index). - Type("event").Id(keyStr).Do() - if err != nil { - return err + switch q.params.Format { + case formatNamespace: + // If event matches as delete, we purge the previous index. + if eventMatch(entryStr, []string{"s3:ObjectRemoved:*"}) { + _, err = q.Client.Delete().Index(q.params.Index). + Type("event").Id(keyStr).Do(context.Background()) + break + } // else we update elastic index or create a new one. + _, err = q.Client.Index().Index(q.params.Index). + Type("event"). + BodyJson(map[string]interface{}{ + "Records": entry.Data["Records"], + }).Id(keyStr).Do(context.Background()) + case formatAccess: + // eventTime is taken from the first entry in the + // records. + events, ok := entry.Data["Records"].([]NotificationEvent) + if !ok { + return esErrFunc("Unable to extract event time due to conversion error of entry.Data[\"Records\"]=%v", entry.Data["Records"]) } - return nil - } // else we update elastic index or create a new one. - _, err := q.Client.Index().Index(q.params.Index). - Type("event"). - BodyJson(map[string]interface{}{ - "Records": entry.Data["Records"], - }).Id(keyStr).Do() - return err + var eventTime time.Time + eventTime, err = time.Parse(timeFormatAMZ, events[0].EventTime) + if err != nil { + return esErrFunc("Unable to parse event time \"%s\": %v", + events[0].EventTime, err) + } + // Extract event time in milliseconds for Elasticsearch. + eventTimeStr := fmt.Sprintf("%d", eventTime.UnixNano()/1000000) + _, err = q.Client.Index().Index(q.params.Index).Type("event"). + Timestamp(eventTimeStr). + BodyJson(map[string]interface{}{ + "Records": entry.Data["Records"], + }).Do(context.Background()) + } + if err != nil { + return esErrFunc("Error inserting/deleting entry: %v", err) + } + return nil } // Required for logrus hook implementation diff --git a/cmd/notify-mysql.go b/cmd/notify-mysql.go index 9d1bb17f6..0bf5d143d 100644 --- a/cmd/notify-mysql.go +++ b/cmd/notify-mysql.go @@ -90,14 +90,11 @@ VALUES (?, ?);` tableExistsMySQL = `SELECT 1 FROM %s;` ) -func makeMySQLError(msg string, a ...interface{}) error { - s := fmt.Sprintf(msg, a...) - return fmt.Errorf("MySQL Notifier Error: %s", s) -} - var ( - myNFormatError = makeMySQLError(`"format" value is invalid - it must be one of "%s" or "%s".`, formatNamespace, formatAccess) - myNTableError = makeMySQLError("Table was not specified in the configuration.") + mysqlErrFunc = newNotificationErrorFactory("MySQL") + + errMysqlFormat = mysqlErrFunc(`"format" value is invalid - it must be one of "%s" or "%s".`, formatNamespace, formatAccess) + errMysqlTable = mysqlErrFunc("Table was not specified in the configuration.") ) type mySQLNotify struct { @@ -127,7 +124,7 @@ func (m *mySQLNotify) Validate() error { return nil } if m.Format != formatNamespace && m.Format != formatAccess { - return myNFormatError + return errMysqlFormat } if m.DsnString == "" { if _, err := checkURL(m.Host); err != nil { @@ -135,7 +132,7 @@ func (m *mySQLNotify) Validate() error { } } if m.Table == "" { - return myNTableError + return errMysqlTable } return nil } @@ -169,7 +166,7 @@ func dialMySQL(msql mySQLNotify) (mySQLConn, error) { db, err := sql.Open("mysql", dsnStr) if err != nil { - return mySQLConn{}, makeMySQLError( + return mySQLConn{}, mysqlErrFunc( "Connection opening failure (dsnStr=%s): %v", dsnStr, err) } @@ -177,7 +174,7 @@ func dialMySQL(msql mySQLNotify) (mySQLConn, error) { // ping to check that server is actually reachable. err = db.Ping() if err != nil { - return mySQLConn{}, makeMySQLError( + return mySQLConn{}, mysqlErrFunc( "Ping to server failed with: %v", err) } @@ -193,7 +190,7 @@ func dialMySQL(msql mySQLNotify) (mySQLConn, error) { _, errCreate := db.Exec(fmt.Sprintf(createStmt, msql.Table)) if errCreate != nil { // failed to create the table. error out. - return mySQLConn{}, makeMySQLError( + return mySQLConn{}, mysqlErrFunc( "'Select' failed with %v, then 'Create Table' failed with %v", err, errCreate, ) @@ -209,21 +206,21 @@ func dialMySQL(msql mySQLNotify) (mySQLConn, error) { msql.Table)) if err != nil { return mySQLConn{}, - makeMySQLError("create UPSERT prepared statement failed with: %v", err) + mysqlErrFunc("create UPSERT prepared statement failed with: %v", err) } // delete statement stmts["deleteRow"], err = db.Prepare(fmt.Sprintf(deleteRowForNSMySQL, msql.Table)) if err != nil { return mySQLConn{}, - makeMySQLError("create DELETE prepared statement failed with: %v", err) + mysqlErrFunc("create DELETE prepared statement failed with: %v", err) } case formatAccess: // insert statement stmts["insertRow"], err = db.Prepare(fmt.Sprintf(insertRowForAccessMySQL, msql.Table)) if err != nil { - return mySQLConn{}, makeMySQLError( + return mySQLConn{}, mysqlErrFunc( "create INSERT prepared statement failed with: %v", err) } @@ -274,7 +271,7 @@ func (myC mySQLConn) Fire(entry *logrus.Entry) error { "Records": d, }) if err != nil { - return nil, makeMySQLError( + return nil, mysqlErrFunc( "Unable to encode event %v to JSON: %v", d, err) } return value, nil @@ -287,7 +284,7 @@ func (myC mySQLConn) Fire(entry *logrus.Entry) error { // delete row from the table _, err := myC.preparedStmts["deleteRow"].Exec(entry.Data["Key"]) if err != nil { - return makeMySQLError( + return mysqlErrFunc( "Error deleting event with key = %v - got mysql error - %v", entry.Data["Key"], err, ) @@ -301,7 +298,7 @@ func (myC mySQLConn) Fire(entry *logrus.Entry) error { // upsert row into the table _, err = myC.preparedStmts["upsertRow"].Exec(entry.Data["Key"], value) if err != nil { - return makeMySQLError( + return mysqlErrFunc( "Unable to upsert event with Key=%v and Value=%v - got mysql error - %v", entry.Data["Key"], entry.Data["Records"], err, ) @@ -312,11 +309,11 @@ func (myC mySQLConn) Fire(entry *logrus.Entry) error { // records. events, ok := entry.Data["Records"].([]NotificationEvent) if !ok { - return makeMySQLError("unable to extract event time due to conversion error of entry.Data[\"Records\"]=%v", entry.Data["Records"]) + return mysqlErrFunc("unable to extract event time due to conversion error of entry.Data[\"Records\"]=%v", entry.Data["Records"]) } eventTime, err := time.Parse(timeFormatAMZ, events[0].EventTime) if err != nil { - return makeMySQLError("unable to parse event time \"%s\": %v", + return mysqlErrFunc("unable to parse event time \"%s\": %v", events[0].EventTime, err) } @@ -327,7 +324,7 @@ func (myC mySQLConn) Fire(entry *logrus.Entry) error { _, err = myC.preparedStmts["insertRow"].Exec(eventTime, value) if err != nil { - return makeMySQLError("Unable to insert event with value=%v: %v", + return mysqlErrFunc("Unable to insert event with value=%v: %v", value, err) } } diff --git a/cmd/notify-postgresql.go b/cmd/notify-postgresql.go index 2b3cec9f9..f0176f2bf 100644 --- a/cmd/notify-postgresql.go +++ b/cmd/notify-postgresql.go @@ -98,14 +98,11 @@ VALUES ($1, $2);` tableExists = `SELECT 1 FROM %s;` ) -func makePGError(msg string, a ...interface{}) error { - s := fmt.Sprintf(msg, a...) - return fmt.Errorf("PostgreSQL Notifier Error: %s", s) -} - var ( - pgNFormatError = makePGError(`"format" value is invalid - it must be one of "%s" or "%s".`, formatNamespace, formatAccess) - pgNTableError = makePGError("Table was not specified in the configuration.") + pgErrFunc = newNotificationErrorFactory("PostgreSQL") + + errPGFormatError = pgErrFunc(`"format" value is invalid - it must be one of "%s" or "%s".`, formatNamespace, formatAccess) + errPGTableError = pgErrFunc("Table was not specified in the configuration.") ) type postgreSQLNotify struct { @@ -135,7 +132,7 @@ func (p *postgreSQLNotify) Validate() error { return nil } if p.Format != formatNamespace && p.Format != formatAccess { - return pgNFormatError + return errPGFormatError } if p.ConnectionString == "" { if _, err := checkURL(p.Host); err != nil { @@ -143,7 +140,7 @@ func (p *postgreSQLNotify) Validate() error { } } if p.Table == "" { - return pgNTableError + return errPGTableError } return nil } @@ -182,7 +179,7 @@ func dialPostgreSQL(pgN postgreSQLNotify) (pgConn, error) { db, err := sql.Open("postgres", connStr) if err != nil { - return pgConn{}, makePGError( + return pgConn{}, pgErrFunc( "Connection opening failure (connectionString=%s): %v", connStr, err) } @@ -190,7 +187,7 @@ func dialPostgreSQL(pgN postgreSQLNotify) (pgConn, error) { // ping to check that server is actually reachable. err = db.Ping() if err != nil { - return pgConn{}, makePGError("Ping to server failed with: %v", + return pgConn{}, pgErrFunc("Ping to server failed with: %v", err) } @@ -206,7 +203,7 @@ func dialPostgreSQL(pgN postgreSQLNotify) (pgConn, error) { _, errCreate := db.Exec(fmt.Sprintf(createStmt, pgN.Table)) if errCreate != nil { // failed to create the table. error out. - return pgConn{}, makePGError( + return pgConn{}, pgErrFunc( "'Select' failed with %v, then 'Create Table' failed with %v", err, errCreate, ) @@ -221,14 +218,14 @@ func dialPostgreSQL(pgN postgreSQLNotify) (pgConn, error) { stmts["upsertRow"], err = db.Prepare(fmt.Sprintf(upsertRowForNS, pgN.Table)) if err != nil { - return pgConn{}, makePGError( + return pgConn{}, pgErrFunc( "create UPSERT prepared statement failed with: %v", err) } // delete statement stmts["deleteRow"], err = db.Prepare(fmt.Sprintf(deleteRowForNS, pgN.Table)) if err != nil { - return pgConn{}, makePGError( + return pgConn{}, pgErrFunc( "create DELETE prepared statement failed with: %v", err) } case formatAccess: @@ -236,7 +233,7 @@ func dialPostgreSQL(pgN postgreSQLNotify) (pgConn, error) { stmts["insertRow"], err = db.Prepare(fmt.Sprintf(insertRowForAccess, pgN.Table)) if err != nil { - return pgConn{}, makePGError( + return pgConn{}, pgErrFunc( "create INSERT prepared statement failed with: %v", err) } } @@ -279,7 +276,7 @@ func jsonEncodeEventData(d interface{}) ([]byte, error) { "Records": d, }) if err != nil { - return nil, makePGError( + return nil, pgErrFunc( "Unable to encode event %v to JSON: %v", d, err) } return value, nil @@ -301,7 +298,7 @@ func (pgC pgConn) Fire(entry *logrus.Entry) error { // delete row from the table _, err := pgC.preparedStmts["deleteRow"].Exec(entry.Data["Key"]) if err != nil { - return makePGError( + return pgErrFunc( "Error deleting event with key=%v: %v", entry.Data["Key"], err, ) @@ -315,7 +312,7 @@ func (pgC pgConn) Fire(entry *logrus.Entry) error { // upsert row into the table _, err = pgC.preparedStmts["upsertRow"].Exec(entry.Data["Key"], value) if err != nil { - return makePGError( + return pgErrFunc( "Unable to upsert event with key=%v and value=%v: %v", entry.Data["Key"], entry.Data["Records"], err, ) @@ -326,11 +323,11 @@ func (pgC pgConn) Fire(entry *logrus.Entry) error { // records. events, ok := entry.Data["Records"].([]NotificationEvent) if !ok { - return makePGError("unable to extract event time due to conversion error of entry.Data[\"Records\"]=%v", entry.Data["Records"]) + return pgErrFunc("unable to extract event time due to conversion error of entry.Data[\"Records\"]=%v", entry.Data["Records"]) } eventTime, err := time.Parse(timeFormatAMZ, events[0].EventTime) if err != nil { - return makePGError("unable to parse event time \"%s\": %v", + return pgErrFunc("unable to parse event time \"%s\": %v", events[0].EventTime, err) } @@ -341,7 +338,7 @@ func (pgC pgConn) Fire(entry *logrus.Entry) error { _, err = pgC.preparedStmts["insertRow"].Exec(eventTime, value) if err != nil { - return makePGError("Unable to insert event with value=%v: %v", + return pgErrFunc("Unable to insert event with value=%v: %v", value, err) } } diff --git a/cmd/notify-redis.go b/cmd/notify-redis.go index 328ab1d15..664760bfd 100644 --- a/cmd/notify-redis.go +++ b/cmd/notify-redis.go @@ -18,7 +18,6 @@ package cmd import ( "encoding/json" - "fmt" "io/ioutil" "net" "time" @@ -27,14 +26,11 @@ import ( "github.com/garyburd/redigo/redis" ) -func makeRedisError(msg string, a ...interface{}) error { - s := fmt.Sprintf(msg, a...) - return fmt.Errorf("Redis Notifier Error: %s", s) -} - var ( - rdNFormatError = makeRedisError(`"format" value is invalid - it must be one of "access" or "namespace".`) - rdNKeyError = makeRedisError("Key was not specified in the configuration.") + redisErrFunc = newNotificationErrorFactory("Redis") + + errRedisFormat = redisErrFunc(`"format" value is invalid - it must be one of "access" or "namespace".`) + errRedisKeyError = redisErrFunc("Key was not specified in the configuration.") ) // redisNotify to send logs to Redis server @@ -51,13 +47,13 @@ func (r *redisNotify) Validate() error { return nil } if r.Format != formatNamespace && r.Format != formatAccess { - return rdNFormatError + return errRedisFormat } if _, _, err := net.SplitHostPort(r.Addr); err != nil { return err } if r.Key == "" { - return rdNKeyError + return errRedisKeyError } return nil } @@ -106,13 +102,13 @@ func dialRedis(rNotify redisNotify) (*redis.Pool, error) { // Check connection. _, err := rConn.Do("PING") if err != nil { - return nil, makeRedisError("Error connecting to server: %v", err) + return nil, redisErrFunc("Error connecting to server: %v", err) } // Test that Key is of desired type reply, err := redis.String(rConn.Do("TYPE", rNotify.Key)) if err != nil { - return nil, makeRedisError("Error getting type of Key=%s: %v", + return nil, redisErrFunc("Error getting type of Key=%s: %v", rNotify.Key, err) } if reply != "none" { @@ -121,7 +117,7 @@ func dialRedis(rNotify redisNotify) (*redis.Pool, error) { expectedType = "list" } if reply != expectedType { - return nil, makeRedisError( + return nil, redisErrFunc( "Key=%s has type %s, but we expect it to be a %s", rNotify.Key, reply, expectedType) } @@ -137,7 +133,7 @@ func newRedisNotify(accountID string) (*logrus.Logger, error) { // Dial redis. rPool, err := dialRedis(rNotify) if err != nil { - return nil, err + return nil, redisErrFunc("Error dialing server: %v", err) } rrConn := redisConn{ @@ -175,7 +171,7 @@ func (r redisConn) Fire(entry *logrus.Entry) error { if eventMatch(entryStr, []string{"s3:ObjectRemoved:*"}) { _, err := rConn.Do("HDEL", r.params.Key, entry.Data["Key"]) if err != nil { - return makeRedisError("Error deleting entry: %v", + return redisErrFunc("Error deleting entry: %v", err) } return nil @@ -185,14 +181,14 @@ func (r redisConn) Fire(entry *logrus.Entry) error { "Records": entry.Data["Records"], }) if err != nil { - return makeRedisError( + return redisErrFunc( "Unable to encode event %v to JSON: %v", entry.Data["Records"], err) } _, err = rConn.Do("HSET", r.params.Key, entry.Data["Key"], value) if err != nil { - return makeRedisError("Error updating hash entry: %v", + return redisErrFunc("Error updating hash entry: %v", err) } case formatAccess: @@ -200,18 +196,18 @@ func (r redisConn) Fire(entry *logrus.Entry) error { // records. events, ok := entry.Data["Records"].([]NotificationEvent) if !ok { - return makeRedisError("unable to extract event time due to conversion error of entry.Data[\"Records\"]=%v", entry.Data["Records"]) + return redisErrFunc("unable to extract event time due to conversion error of entry.Data[\"Records\"]=%v", entry.Data["Records"]) } eventTime := events[0].EventTime listEntry := []interface{}{eventTime, entry.Data["Records"]} jsonValue, err := json.Marshal(listEntry) if err != nil { - return makeRedisError("JSON encoding error: %v", err) + return redisErrFunc("JSON encoding error: %v", err) } _, err = rConn.Do("RPUSH", r.params.Key, jsonValue) if err != nil { - return makeRedisError("Error appending to Redis list: %v", + return redisErrFunc("Error appending to Redis list: %v", err) } } diff --git a/docs/bucket/notifications/README.md b/docs/bucket/notifications/README.md index 961f05dbc..f34a1e27d 100644 --- a/docs/bucket/notifications/README.md +++ b/docs/bucket/notifications/README.md @@ -137,29 +137,52 @@ python rabbit.py ## Publish Minio events via Elasticsearch -Install Elasticsearch 2.4 from [here](https://www.elastic.co/downloads/past-releases/elasticsearch-2-4-0). +Install [Elasticsearch](https://www.elastic.co/downloads/elasticsearch) server. Minio server supports the latest major release series 5.x. Elasticsearch provides version upgrade migration guidelines [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-upgrade.html). + +This notification target supports two formats: _namespace_ and _access_. + +When the _namespace_ format is used, Minio synchronizes objects in the bucket with documents in the index. For each event in the Minio, the server creates a document with the bucket and object name from the event as the document ID. Other details of the event are stored in the body of the document. Thus if an existing object is over-written in Minio, the corresponding document in the Elasticsearch index is updated. If an object is deleted, the corresponding document is deleted from the index. + +When the _access_ format is used, Minio appends events as documents in an Elasticsearch index. For each event, a document with the event details, with the timestamp of document set to the event's timestamp is appended to an index. The ID of the documented is randomly generated by Elasticsearch. No documents are deleted or modified in this format. + +The steps below show how to use this notification target in `namespace` format. The other format is very similar and is omitted for brevity. -## Recipe steps ### Step 1: Add Elasticsearch endpoint to Minio -The default location of Minio server configuration file is ``~/.minio/config.json``. Update the Elasticsearch configuration block in ``config.json`` as follows: +The default location of Minio server configuration file is ``~/.minio/config.json``. The Elasticsearch configuration is located in the `elasticsearch` key under the `notify` top-level key. Create a configuration key-value pair here for your Elasticsearch instance. The key is a name for your Elasticsearch endpoint, and the value is a collection of key-value parameters described in the table below. + +| Parameter | Type | Description | +|:---|:---|:---| +| `enable` | _bool_ | (Required) Is this server endpoint configuration active/enabled? | +| `format` | _string_ | (Required) Either `namespace` or `access`. | +| `url` | _string_ | (Required) The Elasticsearch server's address. For example: `http://localhost:9200`. | +| `index` | _string_ | (Required) The name of an Elasticsearch index in which Minio will store documents. | + +An example of Elasticsearch configuration is as follows: ```json "elasticsearch": { "1": { "enable": true, + "format": "namespace", "url": "http://127.0.0.1:9200", - "index": "bucketevents" + "index": "minio_events" } }, ``` -Restart Minio server to reflect config changes. ``bucketevents`` is the index used by Elasticsearch. +After updating the configuration file, restart the Minio server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs:us-east-1:1:elasticsearch` at start-up if there were no errors. + +Note that, you can add as many Elasticsearch server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the Elasticsearch instance and an object of per-server configuration parameters. ### Step 2: Enable bucket notification using Minio client -We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted from ``images`` bucket on ``myminio`` server. Here ARN value is ``arn:minio:sqs:us-east-1:1:elasticsearch``. To understand more about ARN please follow [AWS ARN](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) documentation. +We will now enable bucket event notifications on a bucket named `images`. Whenever a JPEG image is created/overwritten, a new document is added or an existing document is updated in the Elasticsearch index configured above. When an existing object is deleted, the corresponding document is deleted from the index. Thus, the rows in the Elasticsearch index, reflect the `.jpg` objects in the `images` bucket. + +To configure this bucket notification, we need the ARN printed by Minio in the previous step. Additional information about ARN is available [here](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html). + +With the `mc` tool, the configuration is very simple to add. Let us say that the Minio server is aliased as `myminio` in our mc configuration. Execute the following: ``` mc mb myminio/images @@ -170,26 +193,18 @@ arn:minio:sqs:us-east-1:1:elasticsearch s3:ObjectCreated:*,s3:ObjectRemoved:* Fi ### Step 3: Test on Elasticsearch -Upload a JPEG image into ``images`` bucket, this is the bucket which has been configured for event notification. +Upload a JPEG image into ``images`` bucket. ``` mc cp myphoto.jpg myminio/images ``` -Run ``curl`` to see new index name ``bucketevents`` in your Elasticsearch setup. +Use curl to view contents of ``minio_events`` index. ``` -curl -XGET '127.0.0.1:9200/_cat/indices?v' -health status index pri rep docs.count docs.deleted store.size pri.store.size -yellow open bucketevents 5 1 1 0 7.8kb 7.8kb -``` - -Use curl to view contents of ``bucketevents`` index. - -``` -curl -XGET '127.0.0.1:9200/bucketevents/_search?pretty=1' +$ curl "http://localhost:9200/minio_events/_search?pretty=true" { - "took" : 3, + "took" : 40, "timed_out" : false, "_shards" : { "total" : 5, @@ -199,49 +214,64 @@ curl -XGET '127.0.0.1:9200/bucketevents/_search?pretty=1' "hits" : { "total" : 1, "max_score" : 1.0, - "hits" : [ { - "_index" : "bucketevents", - "_type" : "event", - "_id" : "AVcRVOlwe-uNB1tfj6bx", - "_score" : 1.0, - "_source" : { - "Records" : [ { - "eventVersion" : "2.0", - "eventSource" : "aws:s3", - "awsRegion" : "us-east-1", - "eventTime" : "2016-09-09T23:42:39.977Z", - "eventName" : "s3:ObjectCreated:Put", - "userIdentity" : { - "principalId" : "minio" - }, - "requestParameters" : { - "sourceIPAddress" : "10.1.10.150:52140" - }, - "responseElements" : { }, - "s3" : { - "s3SchemaVersion" : "1.0", - "configurationId" : "Config", - "bucket" : { - "name" : "images", - "ownerIdentity" : { + "hits" : [ + { + "_index" : "minio_events", + "_type" : "event", + "_id" : "images/myphoto.jpg", + "_score" : 1.0, + "_source" : { + "Records" : [ + { + "eventVersion" : "2.0", + "eventSource" : "minio:s3", + "awsRegion" : "us-east-1", + "eventTime" : "2017-03-30T08:00:41Z", + "eventName" : "s3:ObjectCreated:Put", + "userIdentity" : { "principalId" : "minio" }, - "arn" : "arn:aws:s3:::images" - }, - "object" : { - "key" : "myphoto.jpg", - "size" : 200436, - "sequencer" : "1472CC35E6971AF3" + "requestParameters" : { + "sourceIPAddress" : "127.0.0.1:38062" + }, + "responseElements" : { + "x-amz-request-id" : "14B09A09703FC47B", + "x-minio-origin-endpoint" : "http://192.168.86.115:9000" + }, + "s3" : { + "s3SchemaVersion" : "1.0", + "configurationId" : "Config", + "bucket" : { + "name" : "images", + "ownerIdentity" : { + "principalId" : "minio" + }, + "arn" : "arn:aws:s3:::images" + }, + "object" : { + "key" : "myphoto.jpg", + "size" : 6474, + "eTag" : "a3410f4f8788b510d6f19c5067e60a90", + "sequencer" : "14B09A09703FC47B" + } + }, + "source" : { + "host" : "127.0.0.1", + "port" : "38062", + "userAgent" : "Minio (linux; amd64) minio-go/2.0.3 mc/2017-02-15T17:57:25Z" + } } - } - } ] + ] + } } - } ] + ] } } ``` -``curl`` output above states that an Elasticsearch index has been successfully created with notification contents. +This output shows that a document has been created for the event in Elasticsearch. + +Here we see that the document ID is the bucket and object name. In case `access` format was used, the document ID would be automatically generated by Elasticsearch. ## Publish Minio events via Redis @@ -270,7 +300,6 @@ The default location of Minio server configuration file is ``~/.minio/config.jso An example of Redis configuration is as follows: - ```json "redis": { "1": { diff --git a/vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go b/vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go new file mode 100644 index 000000000..606cf1f97 --- /dev/null +++ b/vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go @@ -0,0 +1,74 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.7 + +// Package ctxhttp provides helper functions for performing context-aware HTTP requests. +package ctxhttp // import "golang.org/x/net/context/ctxhttp" + +import ( + "io" + "net/http" + "net/url" + "strings" + + "golang.org/x/net/context" +) + +// Do sends an HTTP request with the provided http.Client and returns +// an HTTP response. +// +// If the client is nil, http.DefaultClient is used. +// +// The provided ctx must be non-nil. If it is canceled or times out, +// ctx.Err() will be returned. +func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) { + if client == nil { + client = http.DefaultClient + } + resp, err := client.Do(req.WithContext(ctx)) + // If we got an error, and the context has been canceled, + // the context's error is probably more useful. + if err != nil { + select { + case <-ctx.Done(): + err = ctx.Err() + default: + } + } + return resp, err +} + +// Get issues a GET request via the Do function. +func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error) { + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + return Do(ctx, client, req) +} + +// Head issues a HEAD request via the Do function. +func Head(ctx context.Context, client *http.Client, url string) (*http.Response, error) { + req, err := http.NewRequest("HEAD", url, nil) + if err != nil { + return nil, err + } + return Do(ctx, client, req) +} + +// Post issues a POST request via the Do function. +func Post(ctx context.Context, client *http.Client, url string, bodyType string, body io.Reader) (*http.Response, error) { + req, err := http.NewRequest("POST", url, body) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", bodyType) + return Do(ctx, client, req) +} + +// PostForm issues a POST request via the Do function. +func PostForm(ctx context.Context, client *http.Client, url string, data url.Values) (*http.Response, error) { + return Post(ctx, client, url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) +} diff --git a/vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17.go b/vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17.go new file mode 100644 index 000000000..926870cc2 --- /dev/null +++ b/vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17.go @@ -0,0 +1,147 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !go1.7 + +package ctxhttp // import "golang.org/x/net/context/ctxhttp" + +import ( + "io" + "net/http" + "net/url" + "strings" + + "golang.org/x/net/context" +) + +func nop() {} + +var ( + testHookContextDoneBeforeHeaders = nop + testHookDoReturned = nop + testHookDidBodyClose = nop +) + +// Do sends an HTTP request with the provided http.Client and returns an HTTP response. +// If the client is nil, http.DefaultClient is used. +// If the context is canceled or times out, ctx.Err() will be returned. +func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) { + if client == nil { + client = http.DefaultClient + } + + // TODO(djd): Respect any existing value of req.Cancel. + cancel := make(chan struct{}) + req.Cancel = cancel + + type responseAndError struct { + resp *http.Response + err error + } + result := make(chan responseAndError, 1) + + // Make local copies of test hooks closed over by goroutines below. + // Prevents data races in tests. + testHookDoReturned := testHookDoReturned + testHookDidBodyClose := testHookDidBodyClose + + go func() { + resp, err := client.Do(req) + testHookDoReturned() + result <- responseAndError{resp, err} + }() + + var resp *http.Response + + select { + case <-ctx.Done(): + testHookContextDoneBeforeHeaders() + close(cancel) + // Clean up after the goroutine calling client.Do: + go func() { + if r := <-result; r.resp != nil { + testHookDidBodyClose() + r.resp.Body.Close() + } + }() + return nil, ctx.Err() + case r := <-result: + var err error + resp, err = r.resp, r.err + if err != nil { + return resp, err + } + } + + c := make(chan struct{}) + go func() { + select { + case <-ctx.Done(): + close(cancel) + case <-c: + // The response's Body is closed. + } + }() + resp.Body = ¬ifyingReader{resp.Body, c} + + return resp, nil +} + +// Get issues a GET request via the Do function. +func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error) { + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + return Do(ctx, client, req) +} + +// Head issues a HEAD request via the Do function. +func Head(ctx context.Context, client *http.Client, url string) (*http.Response, error) { + req, err := http.NewRequest("HEAD", url, nil) + if err != nil { + return nil, err + } + return Do(ctx, client, req) +} + +// Post issues a POST request via the Do function. +func Post(ctx context.Context, client *http.Client, url string, bodyType string, body io.Reader) (*http.Response, error) { + req, err := http.NewRequest("POST", url, body) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", bodyType) + return Do(ctx, client, req) +} + +// PostForm issues a POST request via the Do function. +func PostForm(ctx context.Context, client *http.Client, url string, data url.Values) (*http.Response, error) { + return Post(ctx, client, url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) +} + +// notifyingReader is an io.ReadCloser that closes the notify channel after +// Close is called or a Read fails on the underlying ReadCloser. +type notifyingReader struct { + io.ReadCloser + notify chan<- struct{} +} + +func (r *notifyingReader) Read(p []byte) (int, error) { + n, err := r.ReadCloser.Read(p) + if err != nil && r.notify != nil { + close(r.notify) + r.notify = nil + } + return n, err +} + +func (r *notifyingReader) Close() error { + err := r.ReadCloser.Close() + if r.notify != nil { + close(r.notify) + r.notify = nil + } + return err +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/backoff/LICENSE b/vendor/gopkg.in/olivere/elastic.v3/backoff/LICENSE deleted file mode 100644 index f6f2dcc97..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/backoff/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Portions of this code rely on this LICENSE: - -The MIT License (MIT) - -Copyright (c) 2014 Cenk Altı - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/gopkg.in/olivere/elastic.v3/backoff/backoff.go b/vendor/gopkg.in/olivere/elastic.v3/backoff/backoff.go deleted file mode 100644 index f6d7ad9a0..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/backoff/backoff.go +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2012-2016 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package backoff - -import ( - "math" - "math/rand" - "sync" - "sync/atomic" - "time" -) - -// Backoff is an interface for different types of backoff algorithms. -type Backoff interface { - Next() time.Duration - Reset() -} - -// Stop is used as a signal to indicate that no more retries should be made. -const Stop time.Duration = -1 - -// -- Simple Backoff -- - -// SimpleBackoff takes a list of fixed values for backoff intervals. -// Each call to Next returns the next value from that fixed list. -// After each value is returned, subsequent calls to Next will only return -// the last element. The caller may specify if the values are "jittered". -type SimpleBackoff struct { - sync.Mutex - ticks []int - index int - jitter bool - stop bool -} - -// NewSimpleBackoff creates a SimpleBackoff algorithm with the specified -// list of fixed intervals in milliseconds. -func NewSimpleBackoff(ticks ...int) *SimpleBackoff { - return &SimpleBackoff{ - ticks: ticks, - index: 0, - jitter: false, - stop: false, - } -} - -// Jitter, when set, randomizes to return a value of [0.5*value .. 1.5*value]. -func (b *SimpleBackoff) Jitter(doJitter bool) *SimpleBackoff { - b.Lock() - defer b.Unlock() - b.jitter = doJitter - return b -} - -// SendStop, when enables, makes Next to return Stop once -// the list of values is exhausted. -func (b *SimpleBackoff) SendStop(doStop bool) *SimpleBackoff { - b.Lock() - defer b.Unlock() - b.stop = doStop - return b -} - -// Next returns the next wait interval. -func (b *SimpleBackoff) Next() time.Duration { - b.Lock() - defer b.Unlock() - - i := b.index - if i >= len(b.ticks) { - if b.stop { - return Stop - } - i = len(b.ticks) - 1 - b.index = i - } else { - b.index++ - } - - ms := b.ticks[i] - if b.jitter { - ms = jitter(ms) - } - return time.Duration(ms) * time.Millisecond -} - -// Reset resets SimpleBackoff. -func (b *SimpleBackoff) Reset() { - b.Lock() - b.index = 0 - b.Unlock() -} - -// jitter randomizes the interval to return a value of [0.5*millis .. 1.5*millis]. -func jitter(millis int) int { - if millis <= 0 { - return 0 - } - return millis/2 + rand.Intn(millis) -} - -// -- Exponential -- - -// ExponentialBackoff implements the simple exponential backoff described by -// Douglas Thain at http://dthain.blogspot.de/2009/02/exponential-backoff-in-distributed.html. -type ExponentialBackoff struct { - sync.Mutex - t float64 // initial timeout (in msec) - f float64 // exponential factor (e.g. 2) - m float64 // maximum timeout (in msec) - n int64 // number of retries - stop bool // indicates whether Next should send "Stop" whan max timeout is reached -} - -// NewExponentialBackoff returns a ExponentialBackoff backoff policy. -// Use initialTimeout to set the first/minimal interval -// and maxTimeout to set the maximum wait interval. -func NewExponentialBackoff(initialTimeout, maxTimeout time.Duration) *ExponentialBackoff { - return &ExponentialBackoff{ - t: float64(int64(initialTimeout / time.Millisecond)), - f: 2.0, - m: float64(int64(maxTimeout / time.Millisecond)), - n: 0, - stop: false, - } -} - -// SendStop, when enables, makes Next to return Stop once -// the maximum timeout is reached. -func (b *ExponentialBackoff) SendStop(doStop bool) *ExponentialBackoff { - b.Lock() - defer b.Unlock() - b.stop = doStop - return b -} - -// Next returns the next wait interval. -func (t *ExponentialBackoff) Next() time.Duration { - t.Lock() - defer t.Unlock() - - n := float64(atomic.AddInt64(&t.n, 1)) - r := 1.0 + rand.Float64() // random number in [1..2] - m := math.Min(r*t.t*math.Pow(t.f, n), t.m) - if t.stop && m >= t.m { - return Stop - } - d := time.Duration(int64(m)) * time.Millisecond - return d -} - -// Reset resets the backoff policy so that it can be reused. -func (t *ExponentialBackoff) Reset() { - t.Lock() - t.n = 0 - t.Unlock() -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/delete_by_query.go b/vendor/gopkg.in/olivere/elastic.v3/delete_by_query.go deleted file mode 100644 index ba531b6f4..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/delete_by_query.go +++ /dev/null @@ -1,301 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "fmt" - "net/url" - "strings" - - "gopkg.in/olivere/elastic.v3/uritemplates" -) - -// DeleteByQueryService deletes documents that match a query. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/docs-delete-by-query.html. -type DeleteByQueryService struct { - client *Client - indices []string - types []string - analyzer string - consistency string - defaultOper string - df string - ignoreUnavailable *bool - allowNoIndices *bool - expandWildcards string - replication string - routing string - timeout string - pretty bool - q string - query Query -} - -// NewDeleteByQueryService creates a new DeleteByQueryService. -// You typically use the client's DeleteByQuery to get a reference to -// the service. -func NewDeleteByQueryService(client *Client) *DeleteByQueryService { - builder := &DeleteByQueryService{ - client: client, - } - return builder -} - -// Index sets the indices on which to perform the delete operation. -func (s *DeleteByQueryService) Index(indices ...string) *DeleteByQueryService { - if s.indices == nil { - s.indices = make([]string, 0) - } - s.indices = append(s.indices, indices...) - return s -} - -// Type limits the delete operation to the given types. -func (s *DeleteByQueryService) Type(types ...string) *DeleteByQueryService { - if s.types == nil { - s.types = make([]string, 0) - } - s.types = append(s.types, types...) - return s -} - -// Analyzer to use for the query string. -func (s *DeleteByQueryService) Analyzer(analyzer string) *DeleteByQueryService { - s.analyzer = analyzer - return s -} - -// Consistency represents the specific write consistency setting for the operation. -// It can be one, quorum, or all. -func (s *DeleteByQueryService) Consistency(consistency string) *DeleteByQueryService { - s.consistency = consistency - return s -} - -// DefaultOperator for query string query (AND or OR). -func (s *DeleteByQueryService) DefaultOperator(defaultOperator string) *DeleteByQueryService { - s.defaultOper = defaultOperator - return s -} - -// DF is the field to use as default where no field prefix is given in the query string. -func (s *DeleteByQueryService) DF(defaultField string) *DeleteByQueryService { - s.df = defaultField - return s -} - -// DefaultField is the field to use as default where no field prefix is given in the query string. -// It is an alias to the DF func. -func (s *DeleteByQueryService) DefaultField(defaultField string) *DeleteByQueryService { - s.df = defaultField - return s -} - -// IgnoreUnavailable indicates whether specified concrete indices should be -// ignored when unavailable (missing or closed). -func (s *DeleteByQueryService) IgnoreUnavailable(ignore bool) *DeleteByQueryService { - s.ignoreUnavailable = &ignore - return s -} - -// AllowNoIndices indicates whether to ignore if a wildcard indices -// expression resolves into no concrete indices (including the _all string -// or when no indices have been specified). -func (s *DeleteByQueryService) AllowNoIndices(allow bool) *DeleteByQueryService { - s.allowNoIndices = &allow - return s -} - -// ExpandWildcards indicates whether to expand wildcard expression to -// concrete indices that are open, closed or both. It can be "open" or "closed". -func (s *DeleteByQueryService) ExpandWildcards(expand string) *DeleteByQueryService { - s.expandWildcards = expand - return s -} - -// Replication sets a specific replication type (sync or async). -func (s *DeleteByQueryService) Replication(replication string) *DeleteByQueryService { - s.replication = replication - return s -} - -// Q specifies the query in Lucene query string syntax. You can also use -// Query to programmatically specify the query. -func (s *DeleteByQueryService) Q(query string) *DeleteByQueryService { - s.q = query - return s -} - -// QueryString is an alias to Q. Notice that you can also use Query to -// programmatically set the query. -func (s *DeleteByQueryService) QueryString(query string) *DeleteByQueryService { - s.q = query - return s -} - -// Routing sets a specific routing value. -func (s *DeleteByQueryService) Routing(routing string) *DeleteByQueryService { - s.routing = routing - return s -} - -// Timeout sets an explicit operation timeout, e.g. "1s" or "10000ms". -func (s *DeleteByQueryService) Timeout(timeout string) *DeleteByQueryService { - s.timeout = timeout - return s -} - -// Pretty indents the JSON output from Elasticsearch. -func (s *DeleteByQueryService) Pretty(pretty bool) *DeleteByQueryService { - s.pretty = pretty - return s -} - -// Query sets the query programmatically. -func (s *DeleteByQueryService) Query(query Query) *DeleteByQueryService { - s.query = query - return s -} - -// Do executes the delete-by-query operation. -func (s *DeleteByQueryService) Do() (*DeleteByQueryResult, error) { - var err error - - // Build url - path := "/" - - // Indices part - indexPart := make([]string, 0) - for _, index := range s.indices { - index, err = uritemplates.Expand("{index}", map[string]string{ - "index": index, - }) - if err != nil { - return nil, err - } - indexPart = append(indexPart, index) - } - if len(indexPart) > 0 { - path += strings.Join(indexPart, ",") - } - - // Types part - typesPart := make([]string, 0) - for _, typ := range s.types { - typ, err = uritemplates.Expand("{type}", map[string]string{ - "type": typ, - }) - if err != nil { - return nil, err - } - typesPart = append(typesPart, typ) - } - if len(typesPart) > 0 { - path += "/" + strings.Join(typesPart, ",") - } - - // Search - path += "/_query" - - // Parameters - params := make(url.Values) - if s.analyzer != "" { - params.Set("analyzer", s.analyzer) - } - if s.consistency != "" { - params.Set("consistency", s.consistency) - } - if s.defaultOper != "" { - params.Set("default_operator", s.defaultOper) - } - if s.df != "" { - params.Set("df", s.df) - } - if s.ignoreUnavailable != nil { - params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) - } - if s.allowNoIndices != nil { - params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) - } - if s.expandWildcards != "" { - params.Set("expand_wildcards", s.expandWildcards) - } - if s.replication != "" { - params.Set("replication", s.replication) - } - if s.routing != "" { - params.Set("routing", s.routing) - } - if s.timeout != "" { - params.Set("timeout", s.timeout) - } - if s.pretty { - params.Set("pretty", fmt.Sprintf("%v", s.pretty)) - } - if s.q != "" { - params.Set("q", s.q) - } - - // Set body if there is a query set - var body interface{} - if s.query != nil { - src, err := s.query.Source() - if err != nil { - return nil, err - } - query := make(map[string]interface{}) - query["query"] = src - body = query - } - - // Get response - res, err := s.client.PerformRequest("DELETE", path, params, body) - if err != nil { - return nil, err - } - - // Return result - ret := new(DeleteByQueryResult) - if err := s.client.decoder.Decode(res.Body, ret); err != nil { - return nil, err - } - return ret, nil -} - -// DeleteByQueryResult is the outcome of executing Do with DeleteByQueryService. -type DeleteByQueryResult struct { - Took int64 `json:"took"` - TimedOut bool `json:"timed_out"` - Indices map[string]IndexDeleteByQueryResult `json:"_indices"` - Failures []shardOperationFailure `json:"failures"` -} - -// IndexNames returns the names of the indices the DeleteByQuery touched. -func (res DeleteByQueryResult) IndexNames() []string { - var indices []string - for index, _ := range res.Indices { - indices = append(indices, index) - } - return indices -} - -// All returns the index delete-by-query result of all indices. -func (res DeleteByQueryResult) All() IndexDeleteByQueryResult { - all, _ := res.Indices["_all"] - return all -} - -// IndexDeleteByQueryResult is the result of a delete-by-query for a specific -// index. -type IndexDeleteByQueryResult struct { - // Found documents, matching the query. - Found int `json:"found"` - // Deleted documents, successfully, from the given index. - Deleted int `json:"deleted"` - // Missing documents when trying to delete them. - Missing int `json:"missing"` - // Failed documents to be deleted for the given index. - Failed int `json:"failed"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_delete_warmer.go b/vendor/gopkg.in/olivere/elastic.v3/indices_delete_warmer.go deleted file mode 100644 index ab3dbfec2..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_delete_warmer.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "fmt" - "net/url" - "strings" - - "gopkg.in/olivere/elastic.v3/uritemplates" -) - -// IndicesDeleteWarmerService allows to delete a warmer. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html. -type IndicesDeleteWarmerService struct { - client *Client - pretty bool - index []string - name []string - masterTimeout string -} - -// NewIndicesDeleteWarmerService creates a new IndicesDeleteWarmerService. -func NewIndicesDeleteWarmerService(client *Client) *IndicesDeleteWarmerService { - return &IndicesDeleteWarmerService{ - client: client, - index: make([]string, 0), - name: make([]string, 0), - } -} - -// Index is a list of index names the mapping should be added to -// (supports wildcards); use `_all` or omit to add the mapping on all indices. -func (s *IndicesDeleteWarmerService) Index(indices ...string) *IndicesDeleteWarmerService { - s.index = append(s.index, indices...) - return s -} - -// Name is a list of warmer names to delete (supports wildcards); -// use `_all` to delete all warmers in the specified indices. -func (s *IndicesDeleteWarmerService) Name(name ...string) *IndicesDeleteWarmerService { - s.name = append(s.name, name...) - return s -} - -// MasterTimeout specifies the timeout for connection to master. -func (s *IndicesDeleteWarmerService) MasterTimeout(masterTimeout string) *IndicesDeleteWarmerService { - s.masterTimeout = masterTimeout - return s -} - -// Pretty indicates that the JSON response be indented and human readable. -func (s *IndicesDeleteWarmerService) Pretty(pretty bool) *IndicesDeleteWarmerService { - s.pretty = pretty - return s -} - -// buildURL builds the URL for the operation. -func (s *IndicesDeleteWarmerService) buildURL() (string, url.Values, error) { - // Build URL - path, err := uritemplates.Expand("/{index}/_warmer/{name}", map[string]string{ - "index": strings.Join(s.index, ","), - "name": strings.Join(s.name, ","), - }) - if err != nil { - return "", url.Values{}, err - } - - // Add query string parameters - params := url.Values{} - if s.pretty { - params.Set("pretty", "1") - } - if s.masterTimeout != "" { - params.Set("master_timeout", s.masterTimeout) - } - if len(s.name) > 0 { - params.Set("name", strings.Join(s.name, ",")) - } - return path, params, nil -} - -// Validate checks if the operation is valid. -func (s *IndicesDeleteWarmerService) Validate() error { - var invalid []string - if len(s.index) == 0 { - invalid = append(invalid, "Index") - } - if len(s.name) == 0 { - invalid = append(invalid, "Name") - } - if len(invalid) > 0 { - return fmt.Errorf("missing required fields: %v", invalid) - } - return nil -} - -// Do executes the operation. -func (s *IndicesDeleteWarmerService) Do() (*DeleteWarmerResponse, error) { - // Check pre-conditions - if err := s.Validate(); err != nil { - return nil, err - } - - // Get URL for request - path, params, err := s.buildURL() - if err != nil { - return nil, err - } - - // Get HTTP response - res, err := s.client.PerformRequest("DELETE", path, params, nil) - if err != nil { - return nil, err - } - - // Return operation response - ret := new(DeleteWarmerResponse) - if err := s.client.decoder.Decode(res.Body, ret); err != nil { - return nil, err - } - return ret, nil -} - -// DeleteWarmerResponse is the response of IndicesDeleteWarmerService.Do. -type DeleteWarmerResponse struct { - Acknowledged bool `json:"acknowledged"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_get_warmer.go b/vendor/gopkg.in/olivere/elastic.v3/indices_get_warmer.go deleted file mode 100644 index 8ca4883a0..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_get_warmer.go +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "fmt" - "net/url" - "strings" - - "gopkg.in/olivere/elastic.v3/uritemplates" -) - -// IndicesGetWarmerService allows to get the definition of a warmer for a -// specific index (or alias, or several indices) based on its name. -// The provided name can be a simple wildcard expression or omitted to get -// all warmers. -// -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html -// for more information. -type IndicesGetWarmerService struct { - client *Client - pretty bool - index []string - name []string - typ []string - allowNoIndices *bool - expandWildcards string - ignoreUnavailable *bool - local *bool -} - -// NewIndicesGetWarmerService creates a new IndicesGetWarmerService. -func NewIndicesGetWarmerService(client *Client) *IndicesGetWarmerService { - return &IndicesGetWarmerService{ - client: client, - typ: make([]string, 0), - index: make([]string, 0), - name: make([]string, 0), - } -} - -// Index is a list of index names to restrict the operation; use `_all` to perform the operation on all indices. -func (s *IndicesGetWarmerService) Index(indices ...string) *IndicesGetWarmerService { - s.index = append(s.index, indices...) - return s -} - -// Name is the name of the warmer (supports wildcards); leave empty to get all warmers. -func (s *IndicesGetWarmerService) Name(name ...string) *IndicesGetWarmerService { - s.name = append(s.name, name...) - return s -} - -// Type is a list of type names the mapping should be added to -// (supports wildcards); use `_all` or omit to add the mapping on all types. -func (s *IndicesGetWarmerService) Type(typ ...string) *IndicesGetWarmerService { - s.typ = append(s.typ, typ...) - return s -} - -// AllowNoIndices indicates whether to ignore if a wildcard indices -// expression resolves into no concrete indices. -// This includes `_all` string or when no indices have been specified. -func (s *IndicesGetWarmerService) AllowNoIndices(allowNoIndices bool) *IndicesGetWarmerService { - s.allowNoIndices = &allowNoIndices - return s -} - -// ExpandWildcards indicates whether to expand wildcard expression to -// concrete indices that are open, closed or both. -func (s *IndicesGetWarmerService) ExpandWildcards(expandWildcards string) *IndicesGetWarmerService { - s.expandWildcards = expandWildcards - return s -} - -// IgnoreUnavailable indicates whether specified concrete indices should be -// ignored when unavailable (missing or closed). -func (s *IndicesGetWarmerService) IgnoreUnavailable(ignoreUnavailable bool) *IndicesGetWarmerService { - s.ignoreUnavailable = &ignoreUnavailable - return s -} - -// Local indicates wether or not to return local information, -// do not retrieve the state from master node (default: false). -func (s *IndicesGetWarmerService) Local(local bool) *IndicesGetWarmerService { - s.local = &local - return s -} - -// Pretty indicates that the JSON response be indented and human readable. -func (s *IndicesGetWarmerService) Pretty(pretty bool) *IndicesGetWarmerService { - s.pretty = pretty - return s -} - -// buildURL builds the URL for the operation. -func (s *IndicesGetWarmerService) buildURL() (string, url.Values, error) { - var err error - var path string - - if len(s.index) == 0 && len(s.typ) == 0 && len(s.name) == 0 { - path = "/_warmer" - } else if len(s.index) == 0 && len(s.typ) == 0 && len(s.name) > 0 { - path, err = uritemplates.Expand("/_warmer/{name}", map[string]string{ - "name": strings.Join(s.name, ","), - }) - } else if len(s.index) == 0 && len(s.typ) > 0 && len(s.name) == 0 { - path, err = uritemplates.Expand("/_all/{type}/_warmer", map[string]string{ - "type": strings.Join(s.typ, ","), - }) - } else if len(s.index) == 0 && len(s.typ) > 0 && len(s.name) > 0 { - path, err = uritemplates.Expand("/_all/{type}/_warmer/{name}", map[string]string{ - "type": strings.Join(s.typ, ","), - "name": strings.Join(s.name, ","), - }) - } else if len(s.index) > 0 && len(s.typ) == 0 && len(s.name) == 0 { - path, err = uritemplates.Expand("/{index}/_warmer", map[string]string{ - "index": strings.Join(s.index, ","), - }) - } else if len(s.index) > 0 && len(s.typ) == 0 && len(s.name) > 0 { - path, err = uritemplates.Expand("/{index}/_warmer/{name}", map[string]string{ - "index": strings.Join(s.index, ","), - "name": strings.Join(s.name, ","), - }) - } else if len(s.index) > 0 && len(s.typ) > 0 && len(s.name) == 0 { - path, err = uritemplates.Expand("/{index}/{type}/_warmer", map[string]string{ - "index": strings.Join(s.index, ","), - "type": strings.Join(s.typ, ","), - }) - } else if len(s.index) > 0 && len(s.typ) > 0 && len(s.name) > 0 { - path, err = uritemplates.Expand("/{index}/{type}/_warmer/{name}", map[string]string{ - "index": strings.Join(s.index, ","), - "type": strings.Join(s.typ, ","), - "name": strings.Join(s.name, ","), - }) - } - if err != nil { - return "", url.Values{}, err - } - - // Add query string parameters - params := url.Values{} - if s.pretty { - params.Set("pretty", "1") - } - if s.allowNoIndices != nil { - params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) - } - if s.expandWildcards != "" { - params.Set("expand_wildcards", s.expandWildcards) - } - if s.ignoreUnavailable != nil { - params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) - } - if s.local != nil { - params.Set("local", fmt.Sprintf("%v", *s.local)) - } - return path, params, nil -} - -// Validate checks if the operation is valid. -func (s *IndicesGetWarmerService) Validate() error { - return nil -} - -// Do executes the operation. -func (s *IndicesGetWarmerService) Do() (map[string]interface{}, error) { - // Check pre-conditions - if err := s.Validate(); err != nil { - return nil, err - } - - // Get URL for request - path, params, err := s.buildURL() - if err != nil { - return nil, err - } - - // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) - if err != nil { - return nil, err - } - - // Return operation response - var ret map[string]interface{} - if err := s.client.decoder.Decode(res.Body, &ret); err != nil { - return nil, err - } - return ret, nil -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_put_alias.go b/vendor/gopkg.in/olivere/elastic.v3/indices_put_alias.go deleted file mode 100644 index 17a091264..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_put_alias.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "fmt" - "net/url" -) - -type AliasService struct { - client *Client - actions []aliasAction - pretty bool -} - -type aliasAction struct { - // "add" or "remove" - Type string - // Index name - Index string - // Alias name - Alias string - // Filter - Filter Query -} - -func NewAliasService(client *Client) *AliasService { - builder := &AliasService{ - client: client, - actions: make([]aliasAction, 0), - } - return builder -} - -func (s *AliasService) Pretty(pretty bool) *AliasService { - s.pretty = pretty - return s -} - -func (s *AliasService) Add(indexName string, aliasName string) *AliasService { - action := aliasAction{Type: "add", Index: indexName, Alias: aliasName} - s.actions = append(s.actions, action) - return s -} - -func (s *AliasService) AddWithFilter(indexName string, aliasName string, filter Query) *AliasService { - action := aliasAction{Type: "add", Index: indexName, Alias: aliasName, Filter: filter} - s.actions = append(s.actions, action) - return s -} - -func (s *AliasService) Remove(indexName string, aliasName string) *AliasService { - action := aliasAction{Type: "remove", Index: indexName, Alias: aliasName} - s.actions = append(s.actions, action) - return s -} - -func (s *AliasService) Do() (*AliasResult, error) { - // Build url - path := "/_aliases" - - // Parameters - params := make(url.Values) - if s.pretty { - params.Set("pretty", fmt.Sprintf("%v", s.pretty)) - } - - // Actions - body := make(map[string]interface{}) - actionsJson := make([]interface{}, 0) - - for _, action := range s.actions { - actionJson := make(map[string]interface{}) - detailsJson := make(map[string]interface{}) - detailsJson["index"] = action.Index - detailsJson["alias"] = action.Alias - if action.Filter != nil { - src, err := action.Filter.Source() - if err != nil { - return nil, err - } - detailsJson["filter"] = src - } - actionJson[action.Type] = detailsJson - actionsJson = append(actionsJson, actionJson) - } - - body["actions"] = actionsJson - - // Get response - res, err := s.client.PerformRequest("POST", path, params, body) - if err != nil { - return nil, err - } - - // Return results - ret := new(AliasResult) - if err := s.client.decoder.Decode(res.Body, ret); err != nil { - return nil, err - } - return ret, nil -} - -// -- Result of an alias request. - -type AliasResult struct { - Acknowledged bool `json:"acknowledged"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_put_warmer.go b/vendor/gopkg.in/olivere/elastic.v3/indices_put_warmer.go deleted file mode 100644 index 8974e7b4b..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_put_warmer.go +++ /dev/null @@ -1,221 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "fmt" - "net/url" - "strings" - - "gopkg.in/olivere/elastic.v3/uritemplates" -) - -// IndicesPutWarmerService allows to register a warmer. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html. -type IndicesPutWarmerService struct { - client *Client - pretty bool - typ []string - index []string - name string - masterTimeout string - ignoreUnavailable *bool - allowNoIndices *bool - requestCache *bool - expandWildcards string - bodyJson map[string]interface{} - bodyString string -} - -// NewIndicesPutWarmerService creates a new IndicesPutWarmerService. -func NewIndicesPutWarmerService(client *Client) *IndicesPutWarmerService { - return &IndicesPutWarmerService{ - client: client, - index: make([]string, 0), - typ: make([]string, 0), - } -} - -// Index is a list of index names the mapping should be added to -// (supports wildcards); use `_all` or omit to add the mapping on all indices. -func (s *IndicesPutWarmerService) Index(indices ...string) *IndicesPutWarmerService { - s.index = append(s.index, indices...) - return s -} - -// Type is a list of type names the mapping should be added to -// (supports wildcards); use `_all` or omit to add the mapping on all types. -func (s *IndicesPutWarmerService) Type(typ ...string) *IndicesPutWarmerService { - s.typ = append(s.typ, typ...) - return s -} - -// Name specifies the name of the warmer (supports wildcards); -// leave empty to get all warmers -func (s *IndicesPutWarmerService) Name(name string) *IndicesPutWarmerService { - s.name = name - return s -} - -// MasterTimeout specifies the timeout for connection to master. -func (s *IndicesPutWarmerService) MasterTimeout(masterTimeout string) *IndicesPutWarmerService { - s.masterTimeout = masterTimeout - return s -} - -// IgnoreUnavailable indicates whether specified concrete indices should be -// ignored when unavailable (missing or closed). -func (s *IndicesPutWarmerService) IgnoreUnavailable(ignoreUnavailable bool) *IndicesPutWarmerService { - s.ignoreUnavailable = &ignoreUnavailable - return s -} - -// AllowNoIndices indicates whether to ignore if a wildcard indices -// expression resolves into no concrete indices. -// This includes `_all` string or when no indices have been specified. -func (s *IndicesPutWarmerService) AllowNoIndices(allowNoIndices bool) *IndicesPutWarmerService { - s.allowNoIndices = &allowNoIndices - return s -} - -// RequestCache specifies whether the request to be warmed should use the request cache, -// defaults to index level setting -func (s *IndicesPutWarmerService) RequestCache(requestCache bool) *IndicesPutWarmerService { - s.requestCache = &requestCache - return s -} - -// ExpandWildcards indicates whether to expand wildcard expression to -// concrete indices that are open, closed or both. -func (s *IndicesPutWarmerService) ExpandWildcards(expandWildcards string) *IndicesPutWarmerService { - s.expandWildcards = expandWildcards - return s -} - -// Pretty indicates that the JSON response be indented and human readable. -func (s *IndicesPutWarmerService) Pretty(pretty bool) *IndicesPutWarmerService { - s.pretty = pretty - return s -} - -// BodyJson contains the mapping definition. -func (s *IndicesPutWarmerService) BodyJson(mapping map[string]interface{}) *IndicesPutWarmerService { - s.bodyJson = mapping - return s -} - -// BodyString is the mapping definition serialized as a string. -func (s *IndicesPutWarmerService) BodyString(mapping string) *IndicesPutWarmerService { - s.bodyString = mapping - return s -} - -// buildURL builds the URL for the operation. -func (s *IndicesPutWarmerService) buildURL() (string, url.Values, error) { - var err error - var path string - - if len(s.index) == 0 && len(s.typ) == 0 { - path, err = uritemplates.Expand("/_warmer/{name}", map[string]string{ - "name": s.name, - }) - } else if len(s.index) == 0 && len(s.typ) > 0 { - path, err = uritemplates.Expand("/_all/{type}/_warmer/{name}", map[string]string{ - "type": strings.Join(s.typ, ","), - "name": s.name, - }) - } else if len(s.index) > 0 && len(s.typ) == 0 { - path, err = uritemplates.Expand("/{index}/_warmer/{name}", map[string]string{ - "index": strings.Join(s.index, ","), - "name": s.name, - }) - } else { - path, err = uritemplates.Expand("/{index}/{type}/_warmer/{name}", map[string]string{ - "index": strings.Join(s.index, ","), - "type": strings.Join(s.typ, ","), - "name": s.name, - }) - } - if err != nil { - return "", url.Values{}, err - } - - // Add query string parameters - params := url.Values{} - if s.pretty { - params.Set("pretty", "1") - } - if s.ignoreUnavailable != nil { - params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) - } - if s.allowNoIndices != nil { - params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) - } - if s.requestCache != nil { - params.Set("request_cache", fmt.Sprintf("%v", *s.requestCache)) - } - if s.expandWildcards != "" { - params.Set("expand_wildcards", s.expandWildcards) - } - if s.masterTimeout != "" { - params.Set("master_timeout", s.masterTimeout) - } - return path, params, nil -} - -// Validate checks if the operation is valid. -func (s *IndicesPutWarmerService) Validate() error { - var invalid []string - if s.name == "" { - invalid = append(invalid, "Name") - } - if s.bodyString == "" && s.bodyJson == nil { - invalid = append(invalid, "BodyJson") - } - if len(invalid) > 0 { - return fmt.Errorf("missing required fields: %v", invalid) - } - return nil -} - -// Do executes the operation. -func (s *IndicesPutWarmerService) Do() (*PutWarmerResponse, error) { - // Check pre-conditions - if err := s.Validate(); err != nil { - return nil, err - } - - // Get URL for request - path, params, err := s.buildURL() - if err != nil { - return nil, err - } - - // Setup HTTP request body - var body interface{} - if s.bodyJson != nil { - body = s.bodyJson - } else { - body = s.bodyString - } - - // Get HTTP response - res, err := s.client.PerformRequest("PUT", path, params, body) - if err != nil { - return nil, err - } - - // Return operation response - ret := new(PutWarmerResponse) - if err := s.client.decoder.Decode(res.Body, ret); err != nil { - return nil, err - } - return ret, nil -} - -// PutWarmerResponse is the response of IndicesPutWarmerService.Do. -type PutWarmerResponse struct { - Acknowledged bool `json:"acknowledged"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_refresh.go b/vendor/gopkg.in/olivere/elastic.v3/indices_refresh.go deleted file mode 100644 index dc8ebe254..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_refresh.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "fmt" - "net/url" - "strings" - - "gopkg.in/olivere/elastic.v3/uritemplates" -) - -type RefreshService struct { - client *Client - indices []string - force *bool - pretty bool -} - -func NewRefreshService(client *Client) *RefreshService { - builder := &RefreshService{ - client: client, - indices: make([]string, 0), - } - return builder -} - -func (s *RefreshService) Index(indices ...string) *RefreshService { - s.indices = append(s.indices, indices...) - return s -} - -func (s *RefreshService) Force(force bool) *RefreshService { - s.force = &force - return s -} - -func (s *RefreshService) Pretty(pretty bool) *RefreshService { - s.pretty = pretty - return s -} - -func (s *RefreshService) Do() (*RefreshResult, error) { - // Build url - path := "/" - - // Indices part - indexPart := make([]string, 0) - for _, index := range s.indices { - index, err := uritemplates.Expand("{index}", map[string]string{ - "index": index, - }) - if err != nil { - return nil, err - } - indexPart = append(indexPart, index) - } - if len(indexPart) > 0 { - path += strings.Join(indexPart, ",") - } - - path += "/_refresh" - - // Parameters - params := make(url.Values) - if s.force != nil { - params.Set("force", fmt.Sprintf("%v", *s.force)) - } - if s.pretty { - params.Set("pretty", fmt.Sprintf("%v", s.pretty)) - } - - // Get response - res, err := s.client.PerformRequest("POST", path, params, nil) - if err != nil { - return nil, err - } - - // Return result - ret := new(RefreshResult) - if err := s.client.decoder.Decode(res.Body, ret); err != nil { - return nil, err - } - return ret, nil -} - -// -- Result of a refresh request. - -type RefreshResult struct { - Shards shardsInfo `json:"_shards,omitempty"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/optimize.go b/vendor/gopkg.in/olivere/elastic.v3/optimize.go deleted file mode 100644 index 0e94cea23..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/optimize.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "fmt" - "net/url" - "strings" - - "gopkg.in/olivere/elastic.v3/uritemplates" -) - -type OptimizeService struct { - client *Client - indices []string - maxNumSegments *int - onlyExpungeDeletes *bool - flush *bool - waitForMerge *bool - force *bool - pretty bool -} - -func NewOptimizeService(client *Client) *OptimizeService { - builder := &OptimizeService{ - client: client, - indices: make([]string, 0), - } - return builder -} - -func (s *OptimizeService) Index(indices ...string) *OptimizeService { - s.indices = append(s.indices, indices...) - return s -} - -func (s *OptimizeService) MaxNumSegments(maxNumSegments int) *OptimizeService { - s.maxNumSegments = &maxNumSegments - return s -} - -func (s *OptimizeService) OnlyExpungeDeletes(onlyExpungeDeletes bool) *OptimizeService { - s.onlyExpungeDeletes = &onlyExpungeDeletes - return s -} - -func (s *OptimizeService) Flush(flush bool) *OptimizeService { - s.flush = &flush - return s -} - -func (s *OptimizeService) WaitForMerge(waitForMerge bool) *OptimizeService { - s.waitForMerge = &waitForMerge - return s -} - -func (s *OptimizeService) Force(force bool) *OptimizeService { - s.force = &force - return s -} - -func (s *OptimizeService) Pretty(pretty bool) *OptimizeService { - s.pretty = pretty - return s -} - -func (s *OptimizeService) Do() (*OptimizeResult, error) { - // Build url - path := "/" - - // Indices part - indexPart := make([]string, 0) - for _, index := range s.indices { - index, err := uritemplates.Expand("{index}", map[string]string{ - "index": index, - }) - if err != nil { - return nil, err - } - indexPart = append(indexPart, index) - } - if len(indexPart) > 0 { - path += strings.Join(indexPart, ",") - } - - path += "/_optimize" - - // Parameters - params := make(url.Values) - if s.maxNumSegments != nil { - params.Set("max_num_segments", fmt.Sprintf("%d", *s.maxNumSegments)) - } - if s.onlyExpungeDeletes != nil { - params.Set("only_expunge_deletes", fmt.Sprintf("%v", *s.onlyExpungeDeletes)) - } - if s.flush != nil { - params.Set("flush", fmt.Sprintf("%v", *s.flush)) - } - if s.waitForMerge != nil { - params.Set("wait_for_merge", fmt.Sprintf("%v", *s.waitForMerge)) - } - if s.force != nil { - params.Set("force", fmt.Sprintf("%v", *s.force)) - } - if s.pretty { - params.Set("pretty", fmt.Sprintf("%v", s.pretty)) - } - - // Get response - res, err := s.client.PerformRequest("POST", path, params, nil) - if err != nil { - return nil, err - } - - // Return result - ret := new(OptimizeResult) - if err := s.client.decoder.Decode(res.Body, ret); err != nil { - return nil, err - } - return ret, nil -} - -// -- Result of an optimize request. - -type OptimizeResult struct { - Shards shardsInfo `json:"_shards,omitempty"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/percolate.go b/vendor/gopkg.in/olivere/elastic.v3/percolate.go deleted file mode 100644 index 31518a932..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/percolate.go +++ /dev/null @@ -1,308 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "fmt" - "net/url" - "strings" - - "gopkg.in/olivere/elastic.v3/uritemplates" -) - -// PercolateService is documented at http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/search-percolate.html. -type PercolateService struct { - client *Client - pretty bool - index string - typ string - id string - version interface{} - versionType string - routing []string - preference string - ignoreUnavailable *bool - percolateIndex string - percolatePreference string - percolateRouting string - source string - allowNoIndices *bool - expandWildcards string - percolateFormat string - percolateType string - bodyJson interface{} - bodyString string -} - -// NewPercolateService creates a new PercolateService. -func NewPercolateService(client *Client) *PercolateService { - return &PercolateService{ - client: client, - routing: make([]string, 0), - } -} - -// Index is the name of the index of the document being percolated. -func (s *PercolateService) Index(index string) *PercolateService { - s.index = index - return s -} - -// Type is the type of the document being percolated. -func (s *PercolateService) Type(typ string) *PercolateService { - s.typ = typ - return s -} - -// Id is to substitute the document in the request body with a -// document that is known by the specified id. On top of the id, -// the index and type parameter will be used to retrieve -// the document from within the cluster. -func (s *PercolateService) Id(id string) *PercolateService { - s.id = id - return s -} - -// ExpandWildcards indicates whether to expand wildcard expressions -// to concrete indices that are open, closed or both. -func (s *PercolateService) ExpandWildcards(expandWildcards string) *PercolateService { - s.expandWildcards = expandWildcards - return s -} - -// PercolateFormat indicates whether to return an array of matching -// query IDs instead of objects. -func (s *PercolateService) PercolateFormat(percolateFormat string) *PercolateService { - s.percolateFormat = percolateFormat - return s -} - -// PercolateType is the type to percolate document into. Defaults to type. -func (s *PercolateService) PercolateType(percolateType string) *PercolateService { - s.percolateType = percolateType - return s -} - -// PercolateRouting is the routing value to use when percolating -// the existing document. -func (s *PercolateService) PercolateRouting(percolateRouting string) *PercolateService { - s.percolateRouting = percolateRouting - return s -} - -// Source is the URL-encoded request definition. -func (s *PercolateService) Source(source string) *PercolateService { - s.source = source - return s -} - -// AllowNoIndices indicates whether to ignore if a wildcard indices -// expression resolves into no concrete indices. -// (This includes `_all` string or when no indices have been specified). -func (s *PercolateService) AllowNoIndices(allowNoIndices bool) *PercolateService { - s.allowNoIndices = &allowNoIndices - return s -} - -// IgnoreUnavailable indicates whether specified concrete indices should -// be ignored when unavailable (missing or closed). -func (s *PercolateService) IgnoreUnavailable(ignoreUnavailable bool) *PercolateService { - s.ignoreUnavailable = &ignoreUnavailable - return s -} - -// PercolateIndex is the index to percolate the document into. Defaults to index. -func (s *PercolateService) PercolateIndex(percolateIndex string) *PercolateService { - s.percolateIndex = percolateIndex - return s -} - -// PercolatePreference defines which shard to prefer when executing -// the percolate request. -func (s *PercolateService) PercolatePreference(percolatePreference string) *PercolateService { - s.percolatePreference = percolatePreference - return s -} - -// Version is an explicit version number for concurrency control. -func (s *PercolateService) Version(version interface{}) *PercolateService { - s.version = version - return s -} - -// VersionType is the specific version type. -func (s *PercolateService) VersionType(versionType string) *PercolateService { - s.versionType = versionType - return s -} - -// Routing is a list of specific routing values. -func (s *PercolateService) Routing(routing []string) *PercolateService { - s.routing = routing - return s -} - -// Preference specifies the node or shard the operation should be -// performed on (default: random). -func (s *PercolateService) Preference(preference string) *PercolateService { - s.preference = preference - return s -} - -// Pretty indicates that the JSON response be indented and human readable. -func (s *PercolateService) Pretty(pretty bool) *PercolateService { - s.pretty = pretty - return s -} - -// Doc wraps the given document into the "doc" key of the body. -func (s *PercolateService) Doc(doc interface{}) *PercolateService { - return s.BodyJson(map[string]interface{}{"doc": doc}) -} - -// BodyJson is the percolator request definition using the percolate DSL. -func (s *PercolateService) BodyJson(body interface{}) *PercolateService { - s.bodyJson = body - return s -} - -// BodyString is the percolator request definition using the percolate DSL. -func (s *PercolateService) BodyString(body string) *PercolateService { - s.bodyString = body - return s -} - -// buildURL builds the URL for the operation. -func (s *PercolateService) buildURL() (string, url.Values, error) { - // Build URL - var path string - var err error - if s.id == "" { - path, err = uritemplates.Expand("/{index}/{type}/_percolate", map[string]string{ - "index": s.index, - "type": s.typ, - }) - } else { - path, err = uritemplates.Expand("/{index}/{type}/{id}/_percolate", map[string]string{ - "index": s.index, - "type": s.typ, - "id": s.id, - }) - } - if err != nil { - return "", url.Values{}, err - } - - // Add query string parameters - params := url.Values{} - if s.pretty { - params.Set("pretty", "1") - } - if s.version != nil { - params.Set("version", fmt.Sprintf("%v", s.version)) - } - if s.versionType != "" { - params.Set("version_type", s.versionType) - } - if len(s.routing) > 0 { - params.Set("routing", strings.Join(s.routing, ",")) - } - if s.preference != "" { - params.Set("preference", s.preference) - } - if s.ignoreUnavailable != nil { - params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) - } - if s.percolateIndex != "" { - params.Set("percolate_index", s.percolateIndex) - } - if s.percolatePreference != "" { - params.Set("percolate_preference", s.percolatePreference) - } - if s.percolateRouting != "" { - params.Set("percolate_routing", s.percolateRouting) - } - if s.source != "" { - params.Set("source", s.source) - } - if s.allowNoIndices != nil { - params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) - } - if s.expandWildcards != "" { - params.Set("expand_wildcards", s.expandWildcards) - } - if s.percolateFormat != "" { - params.Set("percolate_format", s.percolateFormat) - } - if s.percolateType != "" { - params.Set("percolate_type", s.percolateType) - } - return path, params, nil -} - -// Validate checks if the operation is valid. -func (s *PercolateService) Validate() error { - var invalid []string - if s.index == "" { - invalid = append(invalid, "Index") - } - if s.typ == "" { - invalid = append(invalid, "Type") - } - if len(invalid) > 0 { - return fmt.Errorf("missing required fields: %v", invalid) - } - return nil -} - -// Do executes the operation. -func (s *PercolateService) Do() (*PercolateResponse, error) { - // Check pre-conditions - if err := s.Validate(); err != nil { - return nil, err - } - - // Get URL for request - path, params, err := s.buildURL() - if err != nil { - return nil, err - } - - // Setup HTTP request body - var body interface{} - if s.bodyJson != nil { - body = s.bodyJson - } else { - body = s.bodyString - } - - // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, body) - if err != nil { - return nil, err - } - - // Return operation response - ret := new(PercolateResponse) - if err := s.client.decoder.Decode(res.Body, ret); err != nil { - return nil, err - } - return ret, nil -} - -// PercolateResponse is the response of PercolateService.Do. -type PercolateResponse struct { - TookInMillis int64 `json:"took"` // search time in milliseconds - Total int64 `json:"total"` // total matches - Matches []*PercolateMatch `json:"matches,omitempty"` - Aggregations Aggregations `json:"aggregations,omitempty"` // results from aggregations -} - -// PercolateMatch returns a single match in a PercolateResponse. -type PercolateMatch struct { - Index string `json:"_index,omitempty"` - Id string `json:"_id"` - Score float64 `json:"_score,omitempty"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/reindexer.go b/vendor/gopkg.in/olivere/elastic.v3/reindexer.go deleted file mode 100644 index 7193a1337..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/reindexer.go +++ /dev/null @@ -1,270 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "encoding/json" - "errors" -) - -// Reindexer simplifies the process of reindexing an index. You typically -// reindex a source index to a target index. However, you can also specify -// a query that filters out documents from the source index before bulk -// indexing them into the target index. The caller may also specify a -// different client for the target, e.g. when copying indices from one -// Elasticsearch cluster to another. -// -// Internally, the Reindex users a scan and scroll operation on the source -// index and bulk indexing to push data into the target index. -// -// By default the reindexer fetches the _source, _parent, and _routing -// attributes from the source index, using the provided CopyToTargetIndex -// will copy those attributes into the destinationIndex. -// This behaviour can be overridden by setting the ScanFields and providing a -// custom ReindexerFunc. -// -// The caller is responsible for setting up and/or clearing the target index -// before starting the reindex process. -// -// See http://www.elastic.co/guide/en/elasticsearch/guide/current/reindex.html -// for more information about reindexing. -type Reindexer struct { - sourceClient, targetClient *Client - sourceIndex string - query Query - scanFields []string - bulkSize int - size int - scroll string - reindexerFunc ReindexerFunc - progress ReindexerProgressFunc - statsOnly bool -} - -// A ReindexerFunc receives each hit from the sourceIndex. -// It can choose to add any number of BulkableRequests to the bulkService. -type ReindexerFunc func(hit *SearchHit, bulkService *BulkService) error - -// CopyToTargetIndex returns a ReindexerFunc that copies the SearchHit's -// _source, _parent, and _routing attributes into the targetIndex -func CopyToTargetIndex(targetIndex string) ReindexerFunc { - return func(hit *SearchHit, bulkService *BulkService) error { - // TODO(oe) Do we need to deserialize here? - source := make(map[string]interface{}) - if err := json.Unmarshal(*hit.Source, &source); err != nil { - return err - } - req := NewBulkIndexRequest().Index(targetIndex).Type(hit.Type).Id(hit.Id).Doc(source) - if hit.Parent != "" { - req = req.Parent(hit.Parent) - } - if hit.Routing != "" { - req = req.Routing(hit.Routing) - } - bulkService.Add(req) - return nil - } -} - -// ReindexerProgressFunc is a callback that can be used with Reindexer -// to report progress while reindexing data. -type ReindexerProgressFunc func(current, total int64) - -// ReindexerResponse is returned from the Do func in a Reindexer. -// By default, it returns the number of succeeded and failed bulk operations. -// To return details about all failed items, set StatsOnly to false in -// Reindexer. -type ReindexerResponse struct { - Success int64 - Failed int64 - Errors []*BulkResponseItem -} - -// NewReindexer returns a new Reindexer. -func NewReindexer(client *Client, source string, reindexerFunc ReindexerFunc) *Reindexer { - return &Reindexer{ - sourceClient: client, - sourceIndex: source, - reindexerFunc: reindexerFunc, - statsOnly: true, - } -} - -// TargetClient specifies a different client for the target. This is -// necessary when the target index is in a different Elasticsearch cluster. -// By default, the source and target clients are the same. -func (ix *Reindexer) TargetClient(c *Client) *Reindexer { - ix.targetClient = c - return ix -} - -// Query specifies the query to apply to the source. It filters out those -// documents to be indexed into target. A nil query does not filter out any -// documents. -func (ix *Reindexer) Query(q Query) *Reindexer { - ix.query = q - return ix -} - -// ScanFields specifies the fields the scan query should load. -// The default fields are _source, _parent, _routing. -func (ix *Reindexer) ScanFields(scanFields ...string) *Reindexer { - ix.scanFields = scanFields - return ix -} - -// BulkSize returns the number of documents to send to Elasticsearch per chunk. -// The default is 500. -func (ix *Reindexer) BulkSize(bulkSize int) *Reindexer { - ix.bulkSize = bulkSize - return ix -} - -// Size is the number of results to return per shard, not per request. -// So a size of 10 which hits 5 shards will return a maximum of 50 results -// per scan request. -func (ix *Reindexer) Size(size int) *Reindexer { - ix.size = size - return ix -} - -// Scroll specifies for how long the scroll operation on the source index -// should be maintained. The default is 5m. -func (ix *Reindexer) Scroll(timeout string) *Reindexer { - ix.scroll = timeout - return ix -} - -// Progress indicates a callback that will be called while indexing. -func (ix *Reindexer) Progress(f ReindexerProgressFunc) *Reindexer { - ix.progress = f - return ix -} - -// StatsOnly indicates whether the Do method should return details e.g. about -// the documents that failed while indexing. It is true by default, i.e. only -// the number of documents that succeeded/failed are returned. Set to false -// if you want all the details. -func (ix *Reindexer) StatsOnly(statsOnly bool) *Reindexer { - ix.statsOnly = statsOnly - return ix -} - -// Do starts the reindexing process. -func (ix *Reindexer) Do() (*ReindexerResponse, error) { - if ix.sourceClient == nil { - return nil, errors.New("no source client") - } - if ix.sourceIndex == "" { - return nil, errors.New("no source index") - } - if ix.targetClient == nil { - ix.targetClient = ix.sourceClient - } - if ix.scanFields == nil { - ix.scanFields = []string{"_source", "_parent", "_routing"} - } - if ix.bulkSize <= 0 { - ix.bulkSize = 500 - } - if ix.scroll == "" { - ix.scroll = "5m" - } - - // Count total to report progress (if necessary) - var err error - var current, total int64 - if ix.progress != nil { - total, err = ix.count() - if err != nil { - return nil, err - } - } - - // Prepare scan and scroll to iterate through the source index - scanner := ix.sourceClient.Scan(ix.sourceIndex).Scroll(ix.scroll).Fields(ix.scanFields...) - if ix.query != nil { - scanner = scanner.Query(ix.query) - } - if ix.size > 0 { - scanner = scanner.Size(ix.size) - } - cursor, err := scanner.Do() - - bulk := ix.targetClient.Bulk() - - ret := &ReindexerResponse{ - Errors: make([]*BulkResponseItem, 0), - } - - // Main loop iterates through the source index and bulk indexes into target. - for { - docs, err := cursor.Next() - if err == EOS { - break - } - if err != nil { - return ret, err - } - - if docs.TotalHits() > 0 { - for _, hit := range docs.Hits.Hits { - if ix.progress != nil { - current++ - ix.progress(current, total) - } - - err := ix.reindexerFunc(hit, bulk) - if err != nil { - return ret, err - } - - if bulk.NumberOfActions() >= ix.bulkSize { - bulk, err = ix.commit(bulk, ret) - if err != nil { - return ret, err - } - } - } - } - } - - // Final flush - if bulk.NumberOfActions() > 0 { - bulk, err = ix.commit(bulk, ret) - if err != nil { - return ret, err - } - bulk = nil - } - - return ret, nil -} - -// count returns the number of documents in the source index. -// The query is taken into account, if specified. -func (ix *Reindexer) count() (int64, error) { - service := ix.sourceClient.Count(ix.sourceIndex) - if ix.query != nil { - service = service.Query(ix.query) - } - return service.Do() -} - -// commit commits a bulk, updates the stats, and returns a fresh bulk service. -func (ix *Reindexer) commit(bulk *BulkService, ret *ReindexerResponse) (*BulkService, error) { - bres, err := bulk.Do() - if err != nil { - return nil, err - } - ret.Success += int64(len(bres.Succeeded())) - failed := bres.Failed() - ret.Failed += int64(len(failed)) - if !ix.statsOnly { - ret.Errors = append(ret.Errors, failed...) - } - bulk = ix.targetClient.Bulk() - return bulk, nil -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/scan.go b/vendor/gopkg.in/olivere/elastic.v3/scan.go deleted file mode 100644 index 08f2ef38c..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/scan.go +++ /dev/null @@ -1,358 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "errors" - "fmt" - "net/url" - "strings" - - "gopkg.in/olivere/elastic.v3/uritemplates" -) - -const ( - defaultKeepAlive = "5m" -) - -var ( - // End of stream (or scan) - EOS = errors.New("EOS") - - // No ScrollId - ErrNoScrollId = errors.New("no scrollId") -) - -// ScanService manages a cursor through documents in Elasticsearch. -type ScanService struct { - client *Client - indices []string - types []string - keepAlive string - searchSource *SearchSource - pretty bool - routing string - preference string - size *int -} - -// NewScanService creates a new service to iterate through the results -// of a query. -func NewScanService(client *Client) *ScanService { - builder := &ScanService{ - client: client, - searchSource: NewSearchSource().Query(NewMatchAllQuery()), - } - return builder -} - -// Index sets the name(s) of the index to use for scan. -func (s *ScanService) Index(indices ...string) *ScanService { - if s.indices == nil { - s.indices = make([]string, 0) - } - s.indices = append(s.indices, indices...) - return s -} - -// Types allows to restrict the scan to a list of types. -func (s *ScanService) Type(types ...string) *ScanService { - if s.types == nil { - s.types = make([]string, 0) - } - s.types = append(s.types, types...) - return s -} - -// Scroll is an alias for KeepAlive, the time to keep -// the cursor alive (e.g. "5m" for 5 minutes). -func (s *ScanService) Scroll(keepAlive string) *ScanService { - s.keepAlive = keepAlive - return s -} - -// KeepAlive sets the maximum time the cursor will be -// available before expiration (e.g. "5m" for 5 minutes). -func (s *ScanService) KeepAlive(keepAlive string) *ScanService { - s.keepAlive = keepAlive - return s -} - -// Fields tells Elasticsearch to only load specific fields from a search hit. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-fields.html. -func (s *ScanService) Fields(fields ...string) *ScanService { - s.searchSource = s.searchSource.Fields(fields...) - return s -} - -// SearchSource sets the search source builder to use with this service. -func (s *ScanService) SearchSource(searchSource *SearchSource) *ScanService { - s.searchSource = searchSource - if s.searchSource == nil { - s.searchSource = NewSearchSource().Query(NewMatchAllQuery()) - } - return s -} - -// Routing allows for (a comma-separated) list of specific routing values. -func (s *ScanService) Routing(routings ...string) *ScanService { - s.routing = strings.Join(routings, ",") - return s -} - -// Preference specifies the node or shard the operation should be -// performed on (default: "random"). -func (s *ScanService) Preference(preference string) *ScanService { - s.preference = preference - return s -} - -// Query sets the query to perform, e.g. MatchAllQuery. -func (s *ScanService) Query(query Query) *ScanService { - s.searchSource = s.searchSource.Query(query) - return s -} - -// PostFilter is executed as the last filter. It only affects the -// search hits but not facets. See -// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-post-filter.html -// for details. -func (s *ScanService) PostFilter(postFilter Query) *ScanService { - s.searchSource = s.searchSource.PostFilter(postFilter) - return s -} - -// FetchSource indicates whether the response should contain the stored -// _source for every hit. -func (s *ScanService) FetchSource(fetchSource bool) *ScanService { - s.searchSource = s.searchSource.FetchSource(fetchSource) - return s -} - -// FetchSourceContext indicates how the _source should be fetched. -func (s *ScanService) FetchSourceContext(fetchSourceContext *FetchSourceContext) *ScanService { - s.searchSource = s.searchSource.FetchSourceContext(fetchSourceContext) - return s -} - -// Version can be set to true to return a version for each search hit. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-version.html. -func (s *ScanService) Version(version bool) *ScanService { - s.searchSource = s.searchSource.Version(version) - return s -} - -// Sort the results by the given field, in the given order. -// Use the alternative SortWithInfo to use a struct to define the sorting. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html -// for detailed documentation of sorting. -func (s *ScanService) Sort(field string, ascending bool) *ScanService { - s.searchSource = s.searchSource.Sort(field, ascending) - return s -} - -// SortWithInfo defines how to sort results. -// Use the Sort func for a shortcut. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html -// for detailed documentation of sorting. -func (s *ScanService) SortWithInfo(info SortInfo) *ScanService { - s.searchSource = s.searchSource.SortWithInfo(info) - return s -} - -// SortBy defines how to sort results. -// Use the Sort func for a shortcut. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html -// for detailed documentation of sorting. -func (s *ScanService) SortBy(sorter ...Sorter) *ScanService { - s.searchSource = s.searchSource.SortBy(sorter...) - return s -} - -// Pretty enables the caller to indent the JSON output. -func (s *ScanService) Pretty(pretty bool) *ScanService { - s.pretty = pretty - return s -} - -// Size is the number of results to return per shard, not per request. -// So a size of 10 which hits 5 shards will return a maximum of 50 results -// per scan request. -func (s *ScanService) Size(size int) *ScanService { - s.size = &size - return s -} - -// Do executes the query and returns a "server-side cursor". -func (s *ScanService) Do() (*ScanCursor, error) { - // Build url - path := "/" - - // Indices part - indexPart := make([]string, 0) - for _, index := range s.indices { - index, err := uritemplates.Expand("{index}", map[string]string{ - "index": index, - }) - if err != nil { - return nil, err - } - indexPart = append(indexPart, index) - } - if len(indexPart) > 0 { - path += strings.Join(indexPart, ",") - } - - // Types - typesPart := make([]string, 0) - for _, typ := range s.types { - typ, err := uritemplates.Expand("{type}", map[string]string{ - "type": typ, - }) - if err != nil { - return nil, err - } - typesPart = append(typesPart, typ) - } - if len(typesPart) > 0 { - path += "/" + strings.Join(typesPart, ",") - } - - // Search - path += "/_search" - - // Parameters - params := make(url.Values) - if !s.searchSource.hasSort() { - // TODO: ES 2.1 deprecates search_type=scan. See https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_21_search_changes.html#_literal_search_type_scan_literal_deprecated. - params.Set("search_type", "scan") - } - if s.pretty { - params.Set("pretty", fmt.Sprintf("%v", s.pretty)) - } - if s.keepAlive != "" { - params.Set("scroll", s.keepAlive) - } else { - params.Set("scroll", defaultKeepAlive) - } - if s.size != nil && *s.size > 0 { - params.Set("size", fmt.Sprintf("%d", *s.size)) - } - if s.routing != "" { - params.Set("routing", s.routing) - } - - // Get response - body, err := s.searchSource.Source() - if err != nil { - return nil, err - } - res, err := s.client.PerformRequest("POST", path, params, body) - if err != nil { - return nil, err - } - - // Return result - searchResult := new(SearchResult) - if err := s.client.decoder.Decode(res.Body, searchResult); err != nil { - return nil, err - } - - cursor := NewScanCursor(s.client, s.keepAlive, s.pretty, searchResult) - - return cursor, nil -} - -// scanCursor represents a single page of results from -// an Elasticsearch Scan operation. -type ScanCursor struct { - Results *SearchResult - - client *Client - keepAlive string - pretty bool - currentPage int -} - -// newScanCursor returns a new initialized instance -// of scanCursor. -func NewScanCursor(client *Client, keepAlive string, pretty bool, searchResult *SearchResult) *ScanCursor { - return &ScanCursor{ - client: client, - keepAlive: keepAlive, - pretty: pretty, - Results: searchResult, - } -} - -// TotalHits is a convenience method that returns the number -// of hits the cursor will iterate through. -func (c *ScanCursor) TotalHits() int64 { - if c.Results.Hits == nil { - return 0 - } - return c.Results.Hits.TotalHits -} - -// Next returns the next search result or nil when all -// documents have been scanned. -// -// Usage: -// -// for { -// res, err := cursor.Next() -// if err == elastic.EOS { -// // End of stream (or scan) -// break -// } -// if err != nil { -// // Handle error -// } -// // Work with res -// } -// -func (c *ScanCursor) Next() (*SearchResult, error) { - if c.currentPage > 0 { - if c.Results.Hits == nil || len(c.Results.Hits.Hits) == 0 || c.Results.Hits.TotalHits == 0 { - return nil, EOS - } - } - if c.Results.ScrollId == "" { - return nil, EOS - } - - // Build url - path := "/_search/scroll" - - // Parameters - params := make(url.Values) - if c.pretty { - params.Set("pretty", fmt.Sprintf("%v", c.pretty)) - } - if c.keepAlive != "" { - params.Set("scroll", c.keepAlive) - } else { - params.Set("scroll", defaultKeepAlive) - } - - // Set body - body := c.Results.ScrollId - - // Get response - res, err := c.client.PerformRequest("POST", path, params, body) - if err != nil { - return nil, err - } - - // Return result - c.Results = &SearchResult{ScrollId: body} - if err := c.client.decoder.Decode(res.Body, c.Results); err != nil { - return nil, err - } - - c.currentPage += 1 - - return c.Results, nil -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/scroll.go b/vendor/gopkg.in/olivere/elastic.v3/scroll.go deleted file mode 100644 index 00847f5aa..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/scroll.go +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "fmt" - "net/url" - "strings" - - "gopkg.in/olivere/elastic.v3/uritemplates" -) - -// ScrollService manages a cursor through documents in Elasticsearch. -type ScrollService struct { - client *Client - indices []string - types []string - keepAlive string - query Query - size *int - pretty bool - scrollId string -} - -func NewScrollService(client *Client) *ScrollService { - builder := &ScrollService{ - client: client, - query: NewMatchAllQuery(), - } - return builder -} - -func (s *ScrollService) Index(indices ...string) *ScrollService { - if s.indices == nil { - s.indices = make([]string, 0) - } - s.indices = append(s.indices, indices...) - return s -} - -func (s *ScrollService) Type(types ...string) *ScrollService { - if s.types == nil { - s.types = make([]string, 0) - } - s.types = append(s.types, types...) - return s -} - -// Scroll is an alias for KeepAlive, the time to keep -// the cursor alive (e.g. "5m" for 5 minutes). -func (s *ScrollService) Scroll(keepAlive string) *ScrollService { - s.keepAlive = keepAlive - return s -} - -// KeepAlive sets the maximum time the cursor will be -// available before expiration (e.g. "5m" for 5 minutes). -func (s *ScrollService) KeepAlive(keepAlive string) *ScrollService { - s.keepAlive = keepAlive - return s -} - -func (s *ScrollService) Query(query Query) *ScrollService { - s.query = query - return s -} - -func (s *ScrollService) Pretty(pretty bool) *ScrollService { - s.pretty = pretty - return s -} - -func (s *ScrollService) Size(size int) *ScrollService { - s.size = &size - return s -} - -func (s *ScrollService) ScrollId(scrollId string) *ScrollService { - s.scrollId = scrollId - return s -} - -func (s *ScrollService) Do() (*SearchResult, error) { - if s.scrollId == "" { - return s.GetFirstPage() - } - return s.GetNextPage() -} - -func (s *ScrollService) GetFirstPage() (*SearchResult, error) { - // Build url - path := "/" - - // Indices part - indexPart := make([]string, 0) - for _, index := range s.indices { - index, err := uritemplates.Expand("{index}", map[string]string{ - "index": index, - }) - if err != nil { - return nil, err - } - indexPart = append(indexPart, index) - } - if len(indexPart) > 0 { - path += strings.Join(indexPart, ",") - } - - // Types - typesPart := make([]string, 0) - for _, typ := range s.types { - typ, err := uritemplates.Expand("{type}", map[string]string{ - "type": typ, - }) - if err != nil { - return nil, err - } - typesPart = append(typesPart, typ) - } - if len(typesPart) > 0 { - path += "/" + strings.Join(typesPart, ",") - } - - // Search - path += "/_search" - - // Parameters - params := make(url.Values) - if s.pretty { - params.Set("pretty", fmt.Sprintf("%v", s.pretty)) - } - if s.keepAlive != "" { - params.Set("scroll", s.keepAlive) - } else { - params.Set("scroll", defaultKeepAlive) - } - if s.size != nil && *s.size > 0 { - params.Set("size", fmt.Sprintf("%d", *s.size)) - } - - // Set body - body := make(map[string]interface{}) - if s.query != nil { - src, err := s.query.Source() - if err != nil { - return nil, err - } - body["query"] = src - } - - // Get response - res, err := s.client.PerformRequest("POST", path, params, body) - if err != nil { - return nil, err - } - - // Return result - searchResult := new(SearchResult) - if err := s.client.decoder.Decode(res.Body, searchResult); err != nil { - return nil, err - } - - return searchResult, nil -} - -func (s *ScrollService) GetNextPage() (*SearchResult, error) { - if s.scrollId == "" { - return nil, EOS - } - - // Build url - path := "/_search/scroll" - - // Parameters - params := make(url.Values) - if s.pretty { - params.Set("pretty", fmt.Sprintf("%v", s.pretty)) - } - if s.keepAlive != "" { - params.Set("scroll", s.keepAlive) - } else { - params.Set("scroll", defaultKeepAlive) - } - - // Get response - res, err := s.client.PerformRequest("POST", path, params, s.scrollId) - if err != nil { - return nil, err - } - - // Return result - searchResult := new(SearchResult) - if err := s.client.decoder.Decode(res.Body, searchResult); err != nil { - return nil, err - } - - // Determine last page - if searchResult == nil || searchResult.Hits == nil || len(searchResult.Hits.Hits) == 0 || searchResult.Hits.TotalHits == 0 { - return nil, EOS - } - - return searchResult, nil -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_missing.go b/vendor/gopkg.in/olivere/elastic.v3/search_queries_missing.go deleted file mode 100644 index 0fff3f55c..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_missing.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -// MissingQuery returns documents that have only null values or no value -// in the original field. -// -// For details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-missing-query.html -type MissingQuery struct { - name string - queryName string - nullValue *bool - existence *bool -} - -// NewMissingQuery creates and initializes a new MissingQuery. -func NewMissingQuery(name string) *MissingQuery { - return &MissingQuery{name: name} -} - -// QueryName sets the query name for the query that can be used when -// searching for matched filters hit. -func (q *MissingQuery) QueryName(queryName string) *MissingQuery { - q.queryName = queryName - return q -} - -// NullValue indicates whether the missing filter automatically includes -// fields with null value configured in the mappings. Defaults to false. -func (q *MissingQuery) NullValue(nullValue bool) *MissingQuery { - q.nullValue = &nullValue - return q -} - -// Existence indicates whether the missing filter includes documents where -// the field doesn't exist in the docs. -func (q *MissingQuery) Existence(existence bool) *MissingQuery { - q.existence = &existence - return q -} - -// Source returns JSON for the query. -func (q *MissingQuery) Source() (interface{}, error) { - // { - // "missing" : { - // "field" : "..." - // } - // } - - source := make(map[string]interface{}) - params := make(map[string]interface{}) - source["missing"] = params - params["field"] = q.name - if q.nullValue != nil { - params["null_value"] = *q.nullValue - } - if q.existence != nil { - params["existence"] = *q.existence - } - if q.queryName != "" { - params["_name"] = q.queryName - } - return source, nil -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_not.go b/vendor/gopkg.in/olivere/elastic.v3/search_queries_not.go deleted file mode 100644 index 7a1ee8e08..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_not.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -// NotQuery filters out matched documents using a query. -// -// For details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-not-query.html -type NotQuery struct { - filter Query - queryName string -} - -// NewNotQuery creates and initializes a new NotQuery. -func NewNotQuery(filter Query) *NotQuery { - return &NotQuery{ - filter: filter, - } -} - -// QueryName sets the query name for the filter that can be used -// when searching for matched_filters per hit -func (q *NotQuery) QueryName(queryName string) *NotQuery { - q.queryName = queryName - return q -} - -// Source returns JSON for the query. -func (q *NotQuery) Source() (interface{}, error) { - source := make(map[string]interface{}) - params := make(map[string]interface{}) - source["not"] = params - - src, err := q.filter.Source() - if err != nil { - return nil, err - } - params["query"] = src - if q.queryName != "" { - params["_name"] = q.queryName - } - return source, nil -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_template_query.go b/vendor/gopkg.in/olivere/elastic.v3/search_queries_template_query.go deleted file mode 100644 index 0611c3ea4..000000000 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_template_query.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -// TemplateQuery is a query that accepts a query template and a -// map of key/value pairs to fill in template parameters. -// -// For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-template-query.html -type TemplateQuery struct { - template string - templateType string - vars map[string]interface{} -} - -// NewTemplateQuery creates and initializes a new TemplateQuery. -func NewTemplateQuery(name string) *TemplateQuery { - return &TemplateQuery{ - template: name, - vars: make(map[string]interface{}), - } -} - -// Template specifies the name of the template. -func (q *TemplateQuery) Template(name string) *TemplateQuery { - q.template = name - return q -} - -// TemplateType defines which kind of query we use. The values can be: -// inline, indexed, or file. If undefined, inline is used. -func (q *TemplateQuery) TemplateType(typ string) *TemplateQuery { - q.templateType = typ - return q -} - -// Var sets a single parameter pair. -func (q *TemplateQuery) Var(name string, value interface{}) *TemplateQuery { - q.vars[name] = value - return q -} - -// Vars sets parameters for the template query. -func (q *TemplateQuery) Vars(vars map[string]interface{}) *TemplateQuery { - q.vars = vars - return q -} - -// Source returns the JSON serializable content for the search. -func (q *TemplateQuery) Source() (interface{}, error) { - // { - // "template" : { - // "query" : {"match_{{template}}": {}}, - // "params" : { - // "template": "all" - // } - // } - // } - - query := make(map[string]interface{}) - - tmpl := make(map[string]interface{}) - query["template"] = tmpl - - // TODO(oe): Implementation differs from online documentation at http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-template-query.html - var fieldname string - switch q.templateType { - case "file": // file - fieldname = "file" - case "indexed", "id": // indexed - fieldname = "id" - default: // inline - fieldname = "query" - } - - tmpl[fieldname] = q.template - if len(q.vars) > 0 { - tmpl["params"] = q.vars - } - - return query, nil -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/CHANGELOG-3.0.md b/vendor/gopkg.in/olivere/elastic.v5/CHANGELOG-3.0.md similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v3/CHANGELOG-3.0.md rename to vendor/gopkg.in/olivere/elastic.v5/CHANGELOG-3.0.md diff --git a/vendor/gopkg.in/olivere/elastic.v5/CHANGELOG-5.0.md b/vendor/gopkg.in/olivere/elastic.v5/CHANGELOG-5.0.md new file mode 100644 index 000000000..161c6a1ce --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/CHANGELOG-5.0.md @@ -0,0 +1,195 @@ +# Changes in Elastic 5.0 + +## Enforce context.Context in PerformRequest and Do + +We enforce the usage of `context.Context` everywhere you execute a request. +You need to change all your `Do()` calls to pass a context: `Do(ctx)`. +This enables automatic request cancelation and many other patterns. + +If you don't need this, simply pass `context.TODO()` or `context.Background()`. + +## Warmers removed + +Warmers are no longer necessary and have been [removed in ES 5.0](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_index_apis.html#_warmers). + +## Optimize removed + +Optimize was deprecated in ES 2.0 and has been [removed in ES 5.0](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_rest_api_changes.html#_literal__optimize_literal_endpoint_removed). +Use [Force Merge](https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html) instead. + +## Missing Query removed + +The `missing` query has been [removed](https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-exists-query.html#_literal_missing_literal_query). +Use `exists` query with `must_not` in `bool` query instead. + +## And Query removed + +The `and` query has been [removed](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_search_changes.html#_deprecated_queries_removed). +Use `must` clauses in a `bool` query instead. + +## Not Query removed + +TODO Is it removed? + +## Or Query removed + +The `or` query has been [removed](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_search_changes.html#_deprecated_queries_removed). +Use `should` clauses in a `bool` query instead. + +## Filtered Query removed + +The `filtered` query has been [removed](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_search_changes.html#_deprecated_queries_removed). +Use `bool` query instead, which supports `filter` clauses too. + +## Limit Query removed + +The `limit` query has been [removed](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_search_changes.html#_deprecated_queries_removed). +Use the `terminate_after` parameter instead. + +# Template Query removed + +The `template` query has been [deprecated](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/query-dsl-template-query.html). You should use +Search Templates instead. + +We remove it from Elastic 5.0 as the 5.0 update is already a good opportunity +to get rid of old stuff. + +## `_timestamp` and `_ttl` removed + +Both of these fields were deprecated and are now [removed](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_mapping_changes.html#_literal__timestamp_literal_and_literal__ttl_literal). + +## Search template Put/Delete API returns `acknowledged` only + +The response type for Put/Delete search templates has changed. +It only returns a single `acknowledged` flag now. + +## Fields has been renamed to Stored Fields + +The `fields` parameter has been renamed to `stored_fields`. +See [here](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/breaking_50_search_changes.html#_literal_fields_literal_parameter). + +## Fielddatafields has been renamed to Docvaluefields + +The `fielddata_fields` parameter [has been renamed](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/breaking_50_search_changes.html#_literal_fielddata_fields_literal_parameter) +to `docvalue_fields`. + +## Type exists endpoint changed + +The endpoint for checking whether a type exists has been changed from +`HEAD {index}/{type}` to `HEAD {index}/_mapping/{type}`. +See [here](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_rest_api_changes.html#_literal_head_index_type_literal_replaced_with_literal_head_index__mapping_type_literal). + +## Refresh parameter changed + +The `?refresh` parameter previously could be a boolean value. It indicated +whether changes made by a request (e.g. by the Bulk API) should be immediately +visible in search, or not. Using `refresh=true` had the positive effect of +immediately seeing the changes when searching; the negative effect is that +it is a rather big performance hit. + +With 5.0, you now have the choice between these 3 values. + +* `"true"` - Refresh immediately +* `"false"` - Do not refresh (the default value) +* `"wait_for"` - Wait until ES made the document visible in search + +See [?refresh](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-refresh.html) in the documentation. + +Notice that `true` and `false` (the boolean values) are no longer available +now in Elastic. You must use a string instead, with one of the above values. + +## ReindexerService removed + +The `ReindexerService` was a custom solution that was started in the ES 1.x era +to automate reindexing data, from one index to another or even between clusters. + +ES 2.3 introduced its own [Reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html) +so we're going to remove our custom solution and ask you to use the native reindexer. + +The `ReindexService` is available via `client.Reindex()` (which used to point +to the custom reindexer). + +## Delete By Query back in core + +The [Delete By Query API](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html) +was moved into a plugin in 2.0. Now its back in core with a complete rewrite based on the Bulk API. + +It has it's own endpoint at `/_delete_by_query`. + +Delete By Query, Reindex, and Update By Query are very similar under the hood. + +## Reindex, Delete By Query, and Update By Query response changed + +The response from the above APIs changed a bit. E.g. the `retries` value +used to be an `int64` and returns separate values for `bulk` and `search` now: + +``` +// Old +{ + ... + "retries": 123, + ... +} +``` + +``` +// New +{ + ... + "retries": { + "bulk": 123, + "search": 0 + }, + ... +} +``` + +## ScanService removed + +The `ScanService` is removed. Use the (new) `ScrollService` instead. + +## New ScrollService + +There was confusion around `ScanService` and `ScrollService` doing basically +the same. One was returning slices and didn't support all query details, the +other returned one document after another and wasn't safe for concurrent use. +So we merged the two and merged it into a new `ScrollService` that +removes all the problems with the older services. + +In other words: +If you used `ScanService`, switch to `ScrollService`. +If you used the old `ScrollService`, you might need to fix some things but +overall it should just work. + +Changes: +- We replaced `elastic.EOS` with `io.EOF` to indicate the "end of scroll". + +TODO Not implemented yet + +## Suggesters + +They have been [completely rewritten in ES 5.0](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_suggester.html). + +Some changes: +- Suggesters no longer have an [output](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_suggester.html#_simpler_completion_indexing). + +TODO Fix all structural changes in suggesters + +## Percolator + +Percolator has [changed considerably](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/breaking_50_percolator.html). + +Elastic 5.0 adds the new +[Percolator Query](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/query-dsl-percolate-query.html) +which can be used in combination with the new +[Percolator type](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/percolator.html). + +The Percolate service is removed from Elastic 5.0. + +## Remove Consistency, add WaitForActiveShards + +The `consistency` parameter has been removed in a lot of places, e.g. the Bulk, +Index, Delete, Delete-by-Query, Reindex, Update, and Update-by-Query API. + +It has been replaced by a somewhat similar `wait_for_active_shards` parameter. +See https://github.com/elastic/elasticsearch/pull/19454. diff --git a/vendor/gopkg.in/olivere/elastic.v3/CONTRIBUTING.md b/vendor/gopkg.in/olivere/elastic.v5/CONTRIBUTING.md similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v3/CONTRIBUTING.md rename to vendor/gopkg.in/olivere/elastic.v5/CONTRIBUTING.md diff --git a/vendor/gopkg.in/olivere/elastic.v3/CONTRIBUTORS b/vendor/gopkg.in/olivere/elastic.v5/CONTRIBUTORS similarity index 67% rename from vendor/gopkg.in/olivere/elastic.v3/CONTRIBUTORS rename to vendor/gopkg.in/olivere/elastic.v5/CONTRIBUTORS index dff2a14d7..f3ec2ce73 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/CONTRIBUTORS +++ b/vendor/gopkg.in/olivere/elastic.v5/CONTRIBUTORS @@ -6,12 +6,20 @@ # # Please keep this list sorted. +0x6875790d0a [@huydx](https://github.com/huydx) Adam Alix [@adamalix](https://github.com/adamalix) Adam Weiner [@adamweiner](https://github.com/adamweiner) +Adrian Lungu [@AdrianLungu](https://github.com/AdrianLungu) +Alex [@akotlar](https://github.com/akotlar) +Alexandre Olivier [@aliphen](https://github.com/aliphen) Alexey Sharov [@nizsheanez](https://github.com/nizsheanez) +AndreKR [@AndreKR](https://github.com/AndreKR) +Andrew Gaul [@andrewgaul](https://github.com/andrewgaul) +Benjamin Fernandes [@LotharSee](https://github.com/LotharSee) Benjamin Zarzycki [@kf6nux](https://github.com/kf6nux) Braden Bassingthwaite [@bbassingthwaite-va](https://github.com/bbassingthwaite-va) Brady Love [@bradylove](https://github.com/bradylove) +Bryan Conklin [@bmconklin](https://github.com/bmconklin) Bruce Zhou [@brucez-isell](https://github.com/brucez-isell) Chris M [@tebriel](https://github.com/tebriel) Christophe Courtaut [@kri5](https://github.com/kri5) @@ -21,25 +29,39 @@ Daniel Barrett [@shendaras](https://github.com/shendaras) Daniel Heckrath [@DanielHeckrath](https://github.com/DanielHeckrath) Daniel Imfeld [@dimfeld](https://github.com/dimfeld) Dwayne Schultz [@myshkin5](https://github.com/myshkin5) +Ellison Leão [@ellisonleao](https://github.com/ellisonleao) +Eugene Egorov [@EugeneEgorov](https://github.com/EugeneEgorov) Faolan C-P [@fcheslack](https://github.com/fcheslack) Gerhard Häring [@ghaering](https://github.com/ghaering) Guilherme Silveira [@guilherme-santos](https://github.com/guilherme-santos) Guillaume J. Charmes [@creack](https://github.com/creack) +Guiseppe [@gm42](https://github.com/gm42) Han Yu [@MoonighT](https://github.com/MoonighT) Harrison Wright [@wright8191](https://github.com/wright8191) Igor Dubinskiy [@idubinskiy](https://github.com/idubinskiy) +initialcontext [@initialcontext](https://github.com/initialcontext) Isaac Saldana [@isaldana](https://github.com/isaldana) Jack Lindamood [@cep21](https://github.com/cep21) +Jacob [@jdelgad](https://github.com/jdelgad) +Jayme Rotsaert [@jrots](https://github.com/jrots) +Jeremy Canady [@jrmycanady](https://github.com/jrmycanady) Joe Buck [@four2five](https://github.com/four2five) John Barker [@j16r](https://github.com/j16r) John Goodall [@jgoodall](https://github.com/jgoodall) +John Stanford [@jxstanford](https://github.com/jxstanford) +jun [@coseyo](https://github.com/coseyo) Junpei Tsuji [@jun06t](https://github.com/jun06t) Kenta SUZUKI [@suzuken](https://github.com/suzuken) +Kyle Brandt [@kylebrandt](https://github.com/kylebrandt) +Leandro Piccilli [@lpic10](https://github.com/lpic10) Maciej Lisiewski [@c2h5oh](https://github.com/c2h5oh) Mara Kim [@autochthe](https://github.com/autochthe) Marcy Buccellato [@marcybuccellato](https://github.com/marcybuccellato) +Mark Costello [@mcos](https://github.com/mcos) Medhi Bechina [@mdzor](https://github.com/mdzor) +mosa [@mosasiru](https://github.com/mosasiru) naimulhaider [@naimulhaider](https://github.com/naimulhaider) +Naoya Yoshizawa [@azihsoyn](https://github.com/azihsoyn) navins [@ishare](https://github.com/ishare) Naoya Tsutsumi [@tutuming](https://github.com/tutuming) Nicholas Wolff [@nwolff](https://github.com/nwolff) @@ -52,9 +74,15 @@ Sean DuBois [@Sean-Der](https://github.com/Sean-Der) Shalin LK [@shalinlk](https://github.com/shalinlk) Stephen Kubovic [@stephenkubovic](https://github.com/stephenkubovic) Stuart Warren [@Woz](https://github.com/stuart-warren) +Sulaiman [@salajlan](https://github.com/salajlan) Sundar [@sundarv85](https://github.com/sundarv85) +Take [ww24](https://github.com/ww24) Tetsuya Morimoto [@t2y](https://github.com/t2y) TimeEmit [@TimeEmit](https://github.com/timeemit) TusharM [@tusharm](https://github.com/tusharm) +wangtuo [@wangtuo](https://github.com/wangtuo) wolfkdy [@wolfkdy](https://github.com/wolfkdy) +Wyndham Blanton [@wyndhblb](https://github.com/wyndhblb) +Yarden Bar [@ayashjorden](https://github.com/ayashjorden) zakthomas [@zakthomas](https://github.com/zakthomas) +singham [@zhaochenxiao90](https://github.com/zhaochenxiao90) diff --git a/vendor/gopkg.in/olivere/elastic.v3/ISSUE_TEMPLATE.md b/vendor/gopkg.in/olivere/elastic.v5/ISSUE_TEMPLATE.md similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v3/ISSUE_TEMPLATE.md rename to vendor/gopkg.in/olivere/elastic.v5/ISSUE_TEMPLATE.md index 558cd6711..c5eb690a7 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/ISSUE_TEMPLATE.md +++ b/vendor/gopkg.in/olivere/elastic.v5/ISSUE_TEMPLATE.md @@ -5,6 +5,7 @@ your issue/question without further inquiry. Thank you. [ ] elastic.v2 (for Elasticsearch 1.x) [ ] elastic.v3 (for Elasticsearch 2.x) +[ ] elastic.v5 (for Elasticsearch 5.x) ### Please describe the expected behavior diff --git a/vendor/gopkg.in/olivere/elastic.v3/LICENSE b/vendor/gopkg.in/olivere/elastic.v5/LICENSE similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v3/LICENSE rename to vendor/gopkg.in/olivere/elastic.v5/LICENSE diff --git a/vendor/gopkg.in/olivere/elastic.v3/README.md b/vendor/gopkg.in/olivere/elastic.v5/README.md similarity index 75% rename from vendor/gopkg.in/olivere/elastic.v3/README.md rename to vendor/gopkg.in/olivere/elastic.v5/README.md index cc4416eec..09d7bbd3d 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/README.md +++ b/vendor/gopkg.in/olivere/elastic.v5/README.md @@ -3,8 +3,8 @@ Elastic is an [Elasticsearch](http://www.elasticsearch.org/) client for the [Go](http://www.golang.org/) programming language. -[![Build Status](https://travis-ci.org/olivere/elastic.svg?branch=release-branch.v3)](https://travis-ci.org/olivere/elastic) -[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](http://godoc.org/gopkg.in/olivere/elastic.v3) +[![Build Status](https://travis-ci.org/olivere/elastic.svg?branch=release-branch.v5)](https://travis-ci.org/olivere/elastic) +[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](http://godoc.org/gopkg.in/olivere/elastic.v5) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/olivere/elastic/master/LICENSE) See the [wiki](https://github.com/olivere/elastic/wiki) for additional information about Elastic. @@ -12,40 +12,58 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for additional informati ## Releases -**The release branches (e.g. [`release-branch.v3`](https://github.com/olivere/elastic/tree/release-branch.v3)) are actively being worked on and can break at any time. If you want to use stable versions of Elastic, please use the packages released via [gopkg.in](https://gopkg.in).** +**The release branches (e.g. [`release-branch.v5`](https://github.com/olivere/elastic/tree/release-branch.v5)) +are actively being worked on and can break at any time. +If you want to use stable versions of Elastic, please use the packages released via [gopkg.in](https://gopkg.in).** Here's the version matrix: Elasticsearch version | Elastic version -| Package URL ----------------------|------------------|------------ +5.x | 5.0 | [`gopkg.in/olivere/elastic.v5`](https://gopkg.in/olivere/elastic.v5) ([source](https://github.com/olivere/elastic/tree/release-branch.v5) [doc](http://godoc.org/gopkg.in/olivere/elastic.v5)) 2.x | 3.0 | [`gopkg.in/olivere/elastic.v3`](https://gopkg.in/olivere/elastic.v3) ([source](https://github.com/olivere/elastic/tree/release-branch.v3) [doc](http://godoc.org/gopkg.in/olivere/elastic.v3)) 1.x | 2.0 | [`gopkg.in/olivere/elastic.v2`](https://gopkg.in/olivere/elastic.v2) ([source](https://github.com/olivere/elastic/tree/release-branch.v2) [doc](http://godoc.org/gopkg.in/olivere/elastic.v2)) 0.9-1.3 | 1.0 | [`gopkg.in/olivere/elastic.v1`](https://gopkg.in/olivere/elastic.v1) ([source](https://github.com/olivere/elastic/tree/release-branch.v1) [doc](http://godoc.org/gopkg.in/olivere/elastic.v1)) **Example:** -You have installed Elasticsearch 2.1.1 and want to use Elastic. As listed above, you should use Elastic 3.0. So you first install the stable release of Elastic 3.0 from gopkg.in. +You have installed Elasticsearch 5.0.0 and want to use Elastic. +As listed above, you should use Elastic 5.0. +So you first install the stable release of Elastic 5.0 from gopkg.in. ```sh -$ go get gopkg.in/olivere/elastic.v3 +$ go get gopkg.in/olivere/elastic.v5 ``` You then import it with this import path: ```go -import "gopkg.in/olivere/elastic.v3" +import elastic "gopkg.in/olivere/elastic.v5" ``` +### Elastic 5.0 + +Elastic 5.0 targets Elasticsearch 5.0.0 and later. Elasticsearch 5.0.0 was +[released on 26th October 2016](https://www.elastic.co/blog/elasticsearch-5-0-0-released). + +Notice that there are will be a lot of [breaking changes in Elasticsearch 5.0](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking-changes-5.0.html) +and we used this as an opportunity to [clean up and refactor Elastic](https://github.com/olivere/elastic/blob/release-branch.v5/CHANGELOG-5.0.md) +as we did in the transition from Elastic 2.0 (for Elasticsearch 1.x) to Elastic 3.0 (for Elasticsearch 2.x). + +Furthermore, the jump in version numbers will give us a chance to be in sync with the Elastic Stack. + ### Elastic 3.0 -Elastic 3.0 targets Elasticsearch 2.0 and later. Elasticsearch 2.0.0 was [released on 28th October 2015](https://www.elastic.co/blog/elasticsearch-2-0-0-released). +Elastic 3.0 targets Elasticsearch 2.x and is published via [`gopkg.in/olivere/elastic.v3`](https://gopkg.in/olivere/elastic.v3). -Notice that there are a lot of [breaking changes in Elasticsearch 2.0](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/breaking-changes-2.0.html) and we used this as an opportunity to [clean up and refactor Elastic as well](https://github.com/olivere/elastic/blob/release-branch.v3/CHANGELOG-3.0.md). +Elastic 3.0 will only get critical bug fixes. You should update to a recent version. ### Elastic 2.0 Elastic 2.0 targets Elasticsearch 1.x and is published via [`gopkg.in/olivere/elastic.v2`](https://gopkg.in/olivere/elastic.v2). +Elastic 2.0 will only get critical bug fixes. You should update to a recent version. + ### Elastic 1.0 Elastic 1.0 is deprecated. You should really update Elasticsearch and Elastic @@ -68,7 +86,7 @@ to rewrite your application big time. More often than not it's renaming APIs and adding/removing features so that Elastic is in sync with Elasticsearch. Elastic has been used in production with the following Elasticsearch versions: -0.90, 1.0-1.7. Furthermore, we use [Travis CI](https://travis-ci.org/) +0.90, 1.0-1.7, and 2.0-2.4.1. Furthermore, we use [Travis CI](https://travis-ci.org/) to test Elastic with the most recent versions of Elasticsearch and Go. See the [.travis.yml](https://github.com/olivere/elastic/blob/master/.travis.yml) file for the exact matrix and [Travis](https://travis-ci.org/olivere/elastic) @@ -83,20 +101,25 @@ Having said that, I hope you find the project useful. ## Getting Started -The first thing you do is to create a [Client](https://github.com/olivere/elastic/blob/master/client.go). The client connects to Elasticsearch on `http://127.0.0.1:9200` by default. +The first thing you do is to create a [Client](https://github.com/olivere/elastic/blob/master/client.go). +The client connects to Elasticsearch on `http://127.0.0.1:9200` by default. You typically create one client for your app. Here's a complete example of creating a client, creating an index, adding a document, executing a search etc. ```go +// Create a context +ctx := context.Background() + // Create a client client, err := elastic.NewClient() if err != nil { // Handle error + panic(err) } // Create an index -_, err = client.CreateIndex("twitter").Do() +_, err = client.CreateIndex("twitter").Do(ctx) if err != nil { // Handle error panic(err) @@ -109,8 +132,8 @@ _, err = client.Index(). Type("tweet"). Id("1"). BodyJson(tweet). - Refresh(true). - Do() + Refresh("true"). + Do(ctx) if err != nil { // Handle error panic(err) @@ -124,7 +147,7 @@ searchResult, err := client.Search(). Sort("user", true). // sort by "user" field, ascending From(0).Size(10). // take documents 0-9 Pretty(true). // pretty print request and response JSON - Do() // execute + Do(ctx) // execute if err != nil { // Handle error panic(err) @@ -171,7 +194,7 @@ if searchResult.Hits.TotalHits > 0 { } // Delete the index again -_, err = client.DeleteIndex("twitter").Do() +_, err = client.DeleteIndex("twitter").Do(ctx) if err != nil { // Handle error panic(err) @@ -203,6 +226,7 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [x] Search - [x] Search Template +- [ ] Multi Search Template - [ ] Search Shards API - [x] Suggesters - [x] Term Suggester @@ -214,7 +238,7 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [ ] Search Exists API - [ ] Validate API - [x] Explain API -- [x] Percolator API +- [ ] Profile API - [x] Field Stats API ### Aggregations @@ -224,6 +248,7 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [x] Cardinality - [x] Extended Stats - [x] Geo Bounds + - [ ] Geo Centroid - [x] Max - [x] Min - [x] Percentiles @@ -243,7 +268,7 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [ ] GeoHash Grid - [x] Global - [x] Histogram - - [x] IPv4 Range + - [x] IP Range - [x] Missing - [x] Nested - [x] Range @@ -257,11 +282,16 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [x] Max Bucket - [x] Min Bucket - [x] Sum Bucket + - [x] Stats Bucket + - [ ] Extended Stats Bucket + - [ ] Percentiles Bucket - [x] Moving Average - [x] Cumulative Sum - [x] Bucket Script - [x] Bucket Selector - [x] Serial Differencing +- [ ] Matrix Aggregations + - [ ] Matrix Stats - [x] Aggregation Metadata ### Indices APIs @@ -271,6 +301,8 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [x] Get Index - [x] Indices Exists - [x] Open / Close Index +- [x] Shrink Index +- [ ] Rollover Index - [x] Put Mapping - [x] Get Mapping - [ ] Get Field Mapping @@ -278,17 +310,17 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [x] Index Aliases - [x] Update Indices Settings - [x] Get Settings -- [ ] Analyze +- [x] Analyze - [x] Index Templates -- [x] Warmers +- [ ] Shadow Replica Indices - [x] Indices Stats - [ ] Indices Segments - [ ] Indices Recovery +- [ ] Indices Shard Stores - [ ] Clear Cache - [x] Flush - [x] Refresh -- [x] Optimize -- [ ] Shadow Replica Indices +- [x] Force Merge - [ ] Upgrade ### cat APIs @@ -302,13 +334,16 @@ The cat APIs are not implemented as of now. We think they are better suited for - [ ] cat health - [ ] cat indices - [ ] cat master +- [ ] cat nodeattrs - [ ] cat nodes - [ ] cat pending tasks - [ ] cat plugins - [ ] cat recovery +- [ ] cat repositories - [ ] cat thread pool - [ ] cat shards - [ ] cat segments +- [ ] cat snapshots ### Cluster APIs @@ -318,10 +353,11 @@ The cat APIs are not implemented as of now. We think they are better suited for - [ ] Pending Cluster Tasks - [ ] Cluster Reroute - [ ] Cluster Update Settings -- [ ] Nodes Stats +- [x] Nodes Stats - [x] Nodes Info - [x] Task Management API - [ ] Nodes hot_threads +- [ ] Cluster Allocation Explain API ### Query DSL @@ -329,6 +365,8 @@ The cat APIs are not implemented as of now. We think they are better suited for - [x] Inner hits - Full text queries - [x] Match Query + - [x] Match Phrase Query + - [x] Match Phrase Prefix Query - [x] Multi Match Query - [x] Common Terms Query - [x] Query String Query @@ -338,7 +376,6 @@ The cat APIs are not implemented as of now. We think they are better suited for - [x] Terms Query - [x] Range Query - [x] Exists Query - - [x] Missing Query - [x] Prefix Query - [x] Wildcard Query - [x] Regexp Query @@ -352,15 +389,11 @@ The cat APIs are not implemented as of now. We think they are better suited for - [x] Function Score Query - [x] Boosting Query - [x] Indices Query - - [x] And Query (deprecated) - - [x] Not Query - - [x] Or Query (deprecated) - - [ ] Filtered Query (deprecated) - - [ ] Limit Query (deprecated) - Joining queries - [x] Nested Query - [x] Has Child Query - [x] Has Parent Query + - [x] Parent Id Query - Geo queries - [ ] GeoShape Query - [x] Geo Bounding Box Query @@ -372,6 +405,7 @@ The cat APIs are not implemented as of now. We think they are better suited for - [x] More Like This Query - [x] Template Query - [x] Script Query + - [x] Percolate Query - Span queries - [ ] Span Term Query - [ ] Span Multi Term Query @@ -381,6 +415,9 @@ The cat APIs are not implemented as of now. We think they are better suited for - [ ] Span Not Query - [ ] Span Containing Query - [ ] Span Within Query + - [ ] Span Field Masking Query +- [ ] Minimum Should Match +- [ ] Multi Term Query Rewrite ### Modules @@ -392,12 +429,15 @@ The cat APIs are not implemented as of now. We think they are better suited for - [x] Sort by field - [x] Sort by geo distance - [x] Sort by script +- [x] Sort by doc -### Scan +### Scrolling -Scrolling through documents (e.g. `search_type=scan`) are implemented via -the `Scroll` and `Scan` services. The `ClearScroll` API is implemented as well. +Scrolling is supported via a `ScrollService`. It supports an iterator-like interface. +The `ClearScroll` API is implemented as well. +A pattern for [efficiently scrolling in parallel](https://github.com/olivere/elastic/wiki/ScrollParallel) +is described in the [Wiki](https://github.com/olivere/elastic/wiki). ## How to contribute @@ -406,9 +446,9 @@ Read [the contribution guidelines](https://github.com/olivere/elastic/blob/maste ## Credits Thanks a lot for the great folks working hard on -[Elasticsearch](http://www.elasticsearch.org/) +[Elasticsearch](https://www.elastic.co/products/elasticsearch) and -[Go](http://www.golang.org/). +[Go](https://golang.org/). Elastic uses portions of the [uritemplates](https://github.com/jtacoma/uritemplates) library diff --git a/vendor/gopkg.in/olivere/elastic.v5/acknowledged_response.go b/vendor/gopkg.in/olivere/elastic.v5/acknowledged_response.go new file mode 100644 index 000000000..83f954f44 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/acknowledged_response.go @@ -0,0 +1,11 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +// AcknowledgedResponse is returned from various APIs. It simply indicates +// whether the operation is ack'd or not. +type AcknowledgedResponse struct { + Acknowledged bool `json:"acknowledged"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/backoff.go b/vendor/gopkg.in/olivere/elastic.v5/backoff.go new file mode 100644 index 000000000..2b4f87498 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/backoff.go @@ -0,0 +1,152 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "math" + "math/rand" + "sync" + "time" +) + +// BackoffFunc specifies the signature of a function that returns the +// time to wait before the next call to a resource. To stop retrying +// return false in the 2nd return value. +type BackoffFunc func(retry int) (time.Duration, bool) + +// Backoff allows callers to implement their own Backoff strategy. +type Backoff interface { + // Next implements a BackoffFunc. + Next(retry int) (time.Duration, bool) +} + +// -- ZeroBackoff -- + +// ZeroBackoff is a fixed backoff policy whose backoff time is always zero, +// meaning that the operation is retried immediately without waiting, +// indefinitely. +type ZeroBackoff struct{} + +// Next implements BackoffFunc for ZeroBackoff. +func (b ZeroBackoff) Next(retry int) (time.Duration, bool) { + return 0, true +} + +// -- StopBackoff -- + +// StopBackoff is a fixed backoff policy that always returns false for +// Next(), meaning that the operation should never be retried. +type StopBackoff struct{} + +// Next implements BackoffFunc for StopBackoff. +func (b StopBackoff) Next(retry int) (time.Duration, bool) { + return 0, false +} + +// -- ConstantBackoff -- + +// ConstantBackoff is a backoff policy that always returns the same delay. +type ConstantBackoff struct { + interval time.Duration +} + +// NewConstantBackoff returns a new ConstantBackoff. +func NewConstantBackoff(interval time.Duration) *ConstantBackoff { + return &ConstantBackoff{interval: interval} +} + +// Next implements BackoffFunc for ConstantBackoff. +func (b *ConstantBackoff) Next(retry int) (time.Duration, bool) { + return b.interval, true +} + +// -- Exponential -- + +// ExponentialBackoff implements the simple exponential backoff described by +// Douglas Thain at http://dthain.blogspot.de/2009/02/exponential-backoff-in-distributed.html. +type ExponentialBackoff struct { + sync.Mutex + t float64 // initial timeout (in msec) + f float64 // exponential factor (e.g. 2) + m float64 // maximum timeout (in msec) +} + +// NewExponentialBackoff returns a ExponentialBackoff backoff policy. +// Use initialTimeout to set the first/minimal interval +// and maxTimeout to set the maximum wait interval. +func NewExponentialBackoff(initialTimeout, maxTimeout time.Duration) *ExponentialBackoff { + return &ExponentialBackoff{ + t: float64(int64(initialTimeout / time.Millisecond)), + f: 2.0, + m: float64(int64(maxTimeout / time.Millisecond)), + } +} + +// Next implements BackoffFunc for ExponentialBackoff. +func (b *ExponentialBackoff) Next(retry int) (time.Duration, bool) { + b.Lock() + defer b.Unlock() + + r := 1.0 + rand.Float64() // random number in [1..2] + m := math.Min(r*b.t*math.Pow(b.f, float64(retry)), b.m) + if m >= b.m { + return 0, false + } + d := time.Duration(int64(m)) * time.Millisecond + return d, true +} + +// -- Simple Backoff -- + +// SimpleBackoff takes a list of fixed values for backoff intervals. +// Each call to Next returns the next value from that fixed list. +// After each value is returned, subsequent calls to Next will only return +// the last element. The values are optionally "jittered" (off by default). +type SimpleBackoff struct { + sync.Mutex + ticks []int + jitter bool +} + +// NewSimpleBackoff creates a SimpleBackoff algorithm with the specified +// list of fixed intervals in milliseconds. +func NewSimpleBackoff(ticks ...int) *SimpleBackoff { + return &SimpleBackoff{ + ticks: ticks, + jitter: false, + } +} + +// Jitter enables or disables jittering values. +func (b *SimpleBackoff) Jitter(flag bool) *SimpleBackoff { + b.Lock() + b.jitter = flag + b.Unlock() + return b +} + +// jitter randomizes the interval to return a value of [0.5*millis .. 1.5*millis]. +func jitter(millis int) int { + if millis <= 0 { + return 0 + } + return millis/2 + rand.Intn(millis) +} + +// Next implements BackoffFunc for SimpleBackoff. +func (b *SimpleBackoff) Next(retry int) (time.Duration, bool) { + b.Lock() + defer b.Unlock() + + if retry >= len(b.ticks) { + return 0, false + } + + ms := b.ticks[retry] + if b.jitter { + ms = jitter(ms) + } + return time.Duration(ms) * time.Millisecond, true +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/bulk.go b/vendor/gopkg.in/olivere/elastic.v5/bulk.go similarity index 74% rename from vendor/gopkg.in/olivere/elastic.v3/bulk.go rename to vendor/gopkg.in/olivere/elastic.v5/bulk.go index 2003c2743..6b6020f37 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/bulk.go +++ b/vendor/gopkg.in/olivere/elastic.v5/bulk.go @@ -10,7 +10,9 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // BulkService allows for batching bulk requests and sending them to @@ -22,26 +24,30 @@ import ( // reuse BulkService to send many batches. You do not have to create a new // BulkService for each batch. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/2.x/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html // for more details. type BulkService struct { client *Client - index string - typ string - requests []BulkableRequest - timeout string - refresh *bool - pretty bool + index string + typ string + requests []BulkableRequest + pipeline string + timeout string + refresh string + routing string + waitForActiveShards string + pretty bool - sizeInBytes int64 + // estimated bulk size in bytes, up to the request index sizeInBytesCursor + sizeInBytes int64 + sizeInBytesCursor int } // NewBulkService initializes a new BulkService. func NewBulkService(client *Client) *BulkService { builder := &BulkService{ - client: client, - requests: make([]BulkableRequest, 0), + client: client, } return builder } @@ -49,6 +55,7 @@ func NewBulkService(client *Client) *BulkService { func (s *BulkService) reset() { s.requests = make([]BulkableRequest, 0) s.sizeInBytes = 0 + s.sizeInBytesCursor = 0 } // Index specifies the index to use for all batches. You may also leave @@ -73,11 +80,35 @@ func (s *BulkService) Timeout(timeout string) *BulkService { return s } -// Refresh, when set to true, tells Elasticsearch to make the bulk requests -// available to search immediately after being processed. Normally, this -// only happens after a specified refresh interval. -func (s *BulkService) Refresh(refresh bool) *BulkService { - s.refresh = &refresh +// Refresh controls when changes made by this request are made visible +// to search. The allowed values are: "true" (refresh the relevant +// primary and replica shards immediately), "wait_for" (wait for the +// changes to be made visible by a refresh before applying), or "false" +// (no refresh related actions). +func (s *BulkService) Refresh(refresh string) *BulkService { + s.refresh = refresh + return s +} + +// Routing specifies the routing value. +func (s *BulkService) Routing(routing string) *BulkService { + s.routing = routing + return s +} + +// Pipeline specifies the pipeline id to preprocess incoming documents with. +func (s *BulkService) Pipeline(pipeline string) *BulkService { + s.pipeline = pipeline + return s +} + +// WaitForActiveShards sets the number of shard copies that must be active +// before proceeding with the bulk operation. Defaults to 1, meaning the +// primary shard only. Set to `all` for all shard copies, otherwise set to +// any non-negative value less than or equal to the total number of copies +// for the shard (number of replicas + 1). +func (s *BulkService) WaitForActiveShards(waitForActiveShards string) *BulkService { + s.waitForActiveShards = waitForActiveShards return s } @@ -92,7 +123,6 @@ func (s *BulkService) Pretty(pretty bool) *BulkService { func (s *BulkService) Add(requests ...BulkableRequest) *BulkService { for _, r := range requests { s.requests = append(s.requests, r) - s.sizeInBytes += s.estimateSizeInBytes(r) } return s } @@ -100,6 +130,13 @@ func (s *BulkService) Add(requests ...BulkableRequest) *BulkService { // EstimatedSizeInBytes returns the estimated size of all bulkable // requests added via Add. func (s *BulkService) EstimatedSizeInBytes() int64 { + if s.sizeInBytesCursor == len(s.requests) { + return s.sizeInBytes + } + for _, r := range s.requests[s.sizeInBytesCursor:] { + s.sizeInBytes += s.estimateSizeInBytes(r) + s.sizeInBytesCursor++ + } return s.sizeInBytes } @@ -123,7 +160,7 @@ func (s *BulkService) NumberOfActions() int { } func (s *BulkService) bodyAsString() (string, error) { - buf := bytes.NewBufferString("") + var buf bytes.Buffer for _, req := range s.requests { source, err := req.Source() @@ -131,10 +168,8 @@ func (s *BulkService) bodyAsString() (string, error) { return "", err } for _, line := range source { - _, err := buf.WriteString(fmt.Sprintf("%s\n", line)) - if err != nil { - return "", nil - } + buf.WriteString(line) + buf.WriteByte('\n') } } @@ -144,7 +179,7 @@ func (s *BulkService) bodyAsString() (string, error) { // Do sends the batched requests to Elasticsearch. Note that, when successful, // you can reuse the BulkService for the next batch as the list of bulk // requests is cleared on success. -func (s *BulkService) Do() (*BulkResponse, error) { +func (s *BulkService) Do(ctx context.Context) (*BulkResponse, error) { // No actions? if s.NumberOfActions() == 0 { return nil, errors.New("elastic: No bulk actions to commit") @@ -158,7 +193,7 @@ func (s *BulkService) Do() (*BulkResponse, error) { // Build url path := "/" - if s.index != "" { + if len(s.index) > 0 { index, err := uritemplates.Expand("{index}", map[string]string{ "index": s.index, }) @@ -167,7 +202,7 @@ func (s *BulkService) Do() (*BulkResponse, error) { } path += index + "/" } - if s.typ != "" { + if len(s.typ) > 0 { typ, err := uritemplates.Expand("{type}", map[string]string{ "type": s.typ, }) @@ -183,15 +218,24 @@ func (s *BulkService) Do() (*BulkResponse, error) { if s.pretty { params.Set("pretty", fmt.Sprintf("%v", s.pretty)) } - if s.refresh != nil { - params.Set("refresh", fmt.Sprintf("%v", *s.refresh)) + if s.pipeline != "" { + params.Set("pipeline", s.pipeline) + } + if s.refresh != "" { + params.Set("refresh", s.refresh) + } + if s.routing != "" { + params.Set("routing", s.routing) } if s.timeout != "" { params.Set("timeout", s.timeout) } + if s.waitForActiveShards != "" { + params.Set("wait_for_active_shards", s.waitForActiveShards) + } // Get response - res, err := s.client.PerformRequest("POST", path, params, body) + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) if err != nil { return nil, err } @@ -260,7 +304,7 @@ type BulkResponseItem struct { Index string `json:"_index,omitempty"` Type string `json:"_type,omitempty"` Id string `json:"_id,omitempty"` - Version int `json:"_version,omitempty"` + Version int64 `json:"_version,omitempty"` Status int `json:"status,omitempty"` Found bool `json:"found,omitempty"` Error *ErrorDetails `json:"error,omitempty"` @@ -292,7 +336,7 @@ func (r *BulkResponse) ByAction(action string) []*BulkResponseItem { if r.Items == nil { return nil } - items := make([]*BulkResponseItem, 0) + var items []*BulkResponseItem for _, item := range r.Items { if result, found := item[action]; found { items = append(items, result) @@ -307,7 +351,7 @@ func (r *BulkResponse) ById(id string) []*BulkResponseItem { if r.Items == nil { return nil } - items := make([]*BulkResponseItem, 0) + var items []*BulkResponseItem for _, item := range r.Items { for _, result := range item { if result.Id == id { @@ -324,7 +368,7 @@ func (r *BulkResponse) Failed() []*BulkResponseItem { if r.Items == nil { return nil } - errors := make([]*BulkResponseItem, 0) + var errors []*BulkResponseItem for _, item := range r.Items { for _, result := range item { if !(result.Status >= 200 && result.Status <= 299) { @@ -341,7 +385,7 @@ func (r *BulkResponse) Succeeded() []*BulkResponseItem { if r.Items == nil { return nil } - succeeded := make([]*BulkResponseItem, 0) + var succeeded []*BulkResponseItem for _, item := range r.Items { for _, result := range item { if result.Status >= 200 && result.Status <= 299 { diff --git a/vendor/gopkg.in/olivere/elastic.v3/bulk_delete_request.go b/vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go similarity index 84% rename from vendor/gopkg.in/olivere/elastic.v3/bulk_delete_request.go rename to vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go index 5a9a74ee0..5d4a2a5a7 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/bulk_delete_request.go +++ b/vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go @@ -12,9 +12,9 @@ import ( // -- Bulk delete request -- -// Bulk request to remove a document from Elasticsearch. +// BulkDeleteRequest is a request to remove a document from Elasticsearch. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html // for details. type BulkDeleteRequest struct { BulkableRequest @@ -23,7 +23,6 @@ type BulkDeleteRequest struct { id string parent string routing string - refresh *bool version int64 // default is MATCH_ANY versionType string // default is "internal" @@ -73,15 +72,6 @@ func (r *BulkDeleteRequest) Routing(routing string) *BulkDeleteRequest { return r } -// Refresh indicates whether to update the shards immediately after -// the delete has been processed. Deleted documents will disappear -// in search immediately at the cost of slower bulk performance. -func (r *BulkDeleteRequest) Refresh(refresh bool) *BulkDeleteRequest { - r.refresh = &refresh - r.source = nil - return r -} - // Version indicates the version to be deleted as part of an optimistic // concurrency model. func (r *BulkDeleteRequest) Version(version int64) *BulkDeleteRequest { @@ -110,7 +100,7 @@ func (r *BulkDeleteRequest) String() string { // Source returns the on-wire representation of the delete request, // split into an action-and-meta-data line and an (optional) source line. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html // for details. func (r *BulkDeleteRequest) Source() ([]string, error) { if r.source != nil { @@ -141,9 +131,6 @@ func (r *BulkDeleteRequest) Source() ([]string, error) { if r.versionType != "" { deleteCommand["_version_type"] = r.versionType } - if r.refresh != nil { - deleteCommand["refresh"] = *r.refresh - } source["delete"] = deleteCommand body, err := json.Marshal(source) diff --git a/vendor/gopkg.in/olivere/elastic.v3/bulk_index_request.go b/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go similarity index 71% rename from vendor/gopkg.in/olivere/elastic.v3/bulk_index_request.go rename to vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go index bab1b8cc4..1c9302881 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/bulk_index_request.go +++ b/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go @@ -10,24 +10,24 @@ import ( "strings" ) -// Bulk request to add a document to Elasticsearch. +// BulkIndexRequest is a request to add a document to Elasticsearch. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html // for details. type BulkIndexRequest struct { BulkableRequest - index string - typ string - id string - opType string - routing string - parent string - timestamp string - ttl int64 - refresh *bool - version int64 // default is MATCH_ANY - versionType string // default is "internal" - doc interface{} + index string + typ string + id string + opType string + routing string + parent string + version int64 // default is MATCH_ANY + versionType string // default is "internal" + doc interface{} + pipeline string + retryOnConflict *int + ttl string source []string } @@ -65,7 +65,7 @@ func (r *BulkIndexRequest) Id(id string) *BulkIndexRequest { // OpType specifies if this request should follow create-only or upsert // behavior. This follows the OpType of the standard document index API. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#operation-type +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html#operation-type // for details. func (r *BulkIndexRequest) OpType(opType string) *BulkIndexRequest { r.opType = opType @@ -87,34 +87,6 @@ func (r *BulkIndexRequest) Parent(parent string) *BulkIndexRequest { return r } -// Timestamp can be used to index a document with a timestamp. -// This is deprecated as of 2.0.0-beta2; you should use a normal date field -// and set its value explicitly. -func (r *BulkIndexRequest) Timestamp(timestamp string) *BulkIndexRequest { - r.timestamp = timestamp - r.source = nil - return r -} - -// Ttl (time to live) sets an expiration date for the document. Expired -// documents will be expunged automatically. -// This is deprecated as of 2.0.0-beta2 and will be replaced by a different -// implementation in a future version. -func (r *BulkIndexRequest) Ttl(ttl int64) *BulkIndexRequest { - r.ttl = ttl - r.source = nil - return r -} - -// Refresh indicates whether to update the shards immediately after -// the request has been processed. Newly added documents will appear -// in search immediately at the cost of slower bulk performance. -func (r *BulkIndexRequest) Refresh(refresh bool) *BulkIndexRequest { - r.refresh = &refresh - r.source = nil - return r -} - // Version indicates the version of the document as part of an optimistic // concurrency model. func (r *BulkIndexRequest) Version(version int64) *BulkIndexRequest { @@ -126,7 +98,7 @@ func (r *BulkIndexRequest) Version(version int64) *BulkIndexRequest { // VersionType specifies how versions are created. It can be e.g. internal, // external, external_gte, or force. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#index-versioning +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html#index-versioning // for details. func (r *BulkIndexRequest) VersionType(versionType string) *BulkIndexRequest { r.versionType = versionType @@ -141,6 +113,27 @@ func (r *BulkIndexRequest) Doc(doc interface{}) *BulkIndexRequest { return r } +// RetryOnConflict specifies how often to retry in case of a version conflict. +func (r *BulkIndexRequest) RetryOnConflict(retryOnConflict int) *BulkIndexRequest { + r.retryOnConflict = &retryOnConflict + r.source = nil + return r +} + +// TTL is an expiration time for the document. +func (r *BulkIndexRequest) TTL(ttl string) *BulkIndexRequest { + r.ttl = ttl + r.source = nil + return r +} + +// Pipeline to use while processing the request. +func (r *BulkIndexRequest) Pipeline(pipeline string) *BulkIndexRequest { + r.pipeline = pipeline + r.source = nil + return r +} + // String returns the on-wire representation of the index request, // concatenated as a single string. func (r *BulkIndexRequest) String() string { @@ -153,7 +146,7 @@ func (r *BulkIndexRequest) String() string { // Source returns the on-wire representation of the index request, // split into an action-and-meta-data line and an (optional) source line. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html // for details. func (r *BulkIndexRequest) Source() ([]string, error) { // { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } } @@ -183,20 +176,20 @@ func (r *BulkIndexRequest) Source() ([]string, error) { if r.parent != "" { indexCommand["_parent"] = r.parent } - if r.timestamp != "" { - indexCommand["_timestamp"] = r.timestamp - } - if r.ttl > 0 { - indexCommand["_ttl"] = r.ttl - } if r.version > 0 { indexCommand["_version"] = r.version } if r.versionType != "" { indexCommand["_version_type"] = r.versionType } - if r.refresh != nil { - indexCommand["refresh"] = *r.refresh + if r.retryOnConflict != nil { + indexCommand["_retry_on_conflict"] = *r.retryOnConflict + } + if r.ttl != "" { + indexCommand["_ttl"] = r.ttl + } + if r.pipeline != "" { + indexCommand["pipeline"] = r.pipeline } command[r.opType] = indexCommand line, err := json.Marshal(command) diff --git a/vendor/gopkg.in/olivere/elastic.v3/bulk_processor.go b/vendor/gopkg.in/olivere/elastic.v5/bulk_processor.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v3/bulk_processor.go rename to vendor/gopkg.in/olivere/elastic.v5/bulk_processor.go index c833e9a15..523ca9fda 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/bulk_processor.go +++ b/vendor/gopkg.in/olivere/elastic.v5/bulk_processor.go @@ -1,4 +1,4 @@ -// Copyright 2012-2016 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,7 +9,7 @@ import ( "sync/atomic" "time" - "gopkg.in/olivere/elastic.v3/backoff" + "golang.org/x/net/context" ) // BulkProcessorService allows to easily process bulk requests. It allows setting @@ -129,9 +129,14 @@ func (s *BulkProcessorService) Stats(wantStats bool) *BulkProcessorService { // You can interoperate with the BulkProcessor returned by Do, e.g. Start and // Stop (or Close) it. // +// Context is an optional context that is passed into the bulk request +// service calls. In contrast to other operations, this context is used in +// a long running process. You could use it to pass e.g. loggers, but you +// shouldn't use it for cancellation. +// // Calling Do several times returns new BulkProcessors. You probably don't // want to do this. BulkProcessorService implements just a builder pattern. -func (s *BulkProcessorService) Do() (*BulkProcessor, error) { +func (s *BulkProcessorService) Do(ctx context.Context) (*BulkProcessor, error) { p := newBulkProcessor( s.c, s.beforeFn, @@ -145,7 +150,7 @@ func (s *BulkProcessorService) Do() (*BulkProcessor, error) { s.initialTimeout, s.maxTimeout) - err := p.Start() + err := p.Start(ctx) if err != nil { return nil, err } @@ -270,7 +275,7 @@ func newBulkProcessor( // Start starts the bulk processor. If the processor is already started, // nil is returned. -func (p *BulkProcessor) Start() error { +func (p *BulkProcessor) Start(ctx context.Context) error { p.startedMu.Lock() defer p.startedMu.Unlock() @@ -292,7 +297,7 @@ func (p *BulkProcessor) Start() error { for i := 0; i < p.numWorkers; i++ { p.workerWg.Add(1) p.workers[i] = newBulkWorker(p, i) - go p.workers[i].work() + go p.workers[i].work(ctx) } // Start the ticker for flush (if enabled) @@ -420,7 +425,7 @@ func newBulkWorker(p *BulkProcessor, i int) *bulkWorker { // work waits for bulk requests and manual flush calls on the respective // channels and is invoked as a goroutine when the bulk processor is started. -func (w *bulkWorker) work() { +func (w *bulkWorker) work(ctx context.Context) { defer func() { w.p.workerWg.Done() close(w.flushAckC) @@ -435,20 +440,20 @@ func (w *bulkWorker) work() { // Received a new request w.service.Add(req) if w.commitRequired() { - w.commit() // TODO swallow errors here? + w.commit(ctx) // TODO swallow errors here? } } else { // Channel closed: Stop. stop = true if w.service.NumberOfActions() > 0 { - w.commit() // TODO swallow errors here? + w.commit(ctx) // TODO swallow errors here? } } case <-w.flushC: // Commit outstanding requests if w.service.NumberOfActions() > 0 { - w.commit() // TODO swallow errors here? + w.commit(ctx) // TODO swallow errors here? } w.flushAckC <- struct{}{} } @@ -457,19 +462,19 @@ func (w *bulkWorker) work() { // commit commits the bulk requests in the given service, // invoking callbacks as specified. -func (w *bulkWorker) commit() error { +func (w *bulkWorker) commit(ctx context.Context) error { var res *BulkResponse // commitFunc will commit bulk requests and, on failure, be retried // via exponential backoff commitFunc := func() error { var err error - res, err = w.service.Do() + res, err = w.service.Do(ctx) return err } // notifyFunc will be called if retry fails - notifyFunc := func(err error, d time.Duration) { - w.p.c.errorf("elastic: bulk processor %q failed but will retry in %v: %v", w.p.name, d, err) + notifyFunc := func(err error) { + w.p.c.errorf("elastic: bulk processor %q failed but will retry: %v", w.p.name, err) } id := atomic.AddInt64(&w.p.executionId, 1) @@ -490,8 +495,8 @@ func (w *bulkWorker) commit() error { } // Commit bulk requests - policy := backoff.NewExponentialBackoff(w.p.initialTimeout, w.p.maxTimeout).SendStop(true) - err := backoff.RetryNotify(commitFunc, policy, notifyFunc) + policy := NewExponentialBackoff(w.p.initialTimeout, w.p.maxTimeout) + err := RetryNotify(commitFunc, policy, notifyFunc) w.updateStats(res) if err != nil { w.p.c.errorf("elastic: bulk processor %q failed: %v", w.p.name, err) diff --git a/vendor/gopkg.in/olivere/elastic.v3/bulk_request.go b/vendor/gopkg.in/olivere/elastic.v5/bulk_request.go similarity index 69% rename from vendor/gopkg.in/olivere/elastic.v3/bulk_request.go rename to vendor/gopkg.in/olivere/elastic.v5/bulk_request.go index 315b535ca..ce3bf0768 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/bulk_request.go +++ b/vendor/gopkg.in/olivere/elastic.v5/bulk_request.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ import ( // -- Bulkable request (index/update/delete) -- -// Generic interface to bulkable requests. +// BulkableRequest is a generic interface to bulkable requests. type BulkableRequest interface { fmt.Stringer Source() ([]string, error) diff --git a/vendor/gopkg.in/olivere/elastic.v3/bulk_update_request.go b/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request.go similarity index 79% rename from vendor/gopkg.in/olivere/elastic.v3/bulk_update_request.go rename to vendor/gopkg.in/olivere/elastic.v5/bulk_update_request.go index 8c899c9d8..b0dbf0917 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/bulk_update_request.go +++ b/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request.go @@ -10,9 +10,9 @@ import ( "strings" ) -// Bulk request to update a document in Elasticsearch. +// BulkUpdateRequest is a request to update a document in Elasticsearch. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html // for details. type BulkUpdateRequest struct { BulkableRequest @@ -23,15 +23,14 @@ type BulkUpdateRequest struct { routing string parent string script *Script + scriptedUpsert *bool version int64 // default is MATCH_ANY versionType string // default is "internal" retryOnConflict *int - refresh *bool upsert interface{} docAsUpsert *bool + detectNoop *bool doc interface{} - ttl int64 - timestamp string source []string } @@ -79,8 +78,8 @@ func (r *BulkUpdateRequest) Parent(parent string) *BulkUpdateRequest { } // Script specifies an update script. -// See https://www.elastic.co/guide/en/elasticsearch/reference/2.x/docs-bulk.html#bulk-update -// and https://www.elastic.co/guide/en/elasticsearch/reference/2.x/modules-scripting.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html#bulk-update +// and https://www.elastic.co/guide/en/elasticsearch/reference/5.2/modules-scripting.html // for details. func (r *BulkUpdateRequest) Script(script *Script) *BulkUpdateRequest { r.script = script @@ -88,6 +87,16 @@ func (r *BulkUpdateRequest) Script(script *Script) *BulkUpdateRequest { return r } +// ScripedUpsert specifies if your script will run regardless of +// whether the document exists or not. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-update.html#_literal_scripted_upsert_literal +func (r *BulkUpdateRequest) ScriptedUpsert(upsert bool) *BulkUpdateRequest { + r.scriptedUpsert = &upsert + r.source = nil + return r +} + // RetryOnConflict specifies how often to retry in case of a version conflict. func (r *BulkUpdateRequest) RetryOnConflict(retryOnConflict int) *BulkUpdateRequest { r.retryOnConflict = &retryOnConflict @@ -111,15 +120,6 @@ func (r *BulkUpdateRequest) VersionType(versionType string) *BulkUpdateRequest { return r } -// Refresh indicates whether to update the shards immediately after -// the request has been processed. Updated documents will appear -// in search immediately at the cost of slower bulk performance. -func (r *BulkUpdateRequest) Refresh(refresh bool) *BulkUpdateRequest { - r.refresh = &refresh - r.source = nil - return r -} - // Doc specifies the updated document. func (r *BulkUpdateRequest) Doc(doc interface{}) *BulkUpdateRequest { r.doc = doc @@ -130,7 +130,7 @@ func (r *BulkUpdateRequest) Doc(doc interface{}) *BulkUpdateRequest { // DocAsUpsert indicates whether the contents of Doc should be used as // the Upsert value. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/2.x/docs-update.html#_literal_doc_as_upsert_literal +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-update.html#_literal_doc_as_upsert_literal // for details. func (r *BulkUpdateRequest) DocAsUpsert(docAsUpsert bool) *BulkUpdateRequest { r.docAsUpsert = &docAsUpsert @@ -138,6 +138,15 @@ func (r *BulkUpdateRequest) DocAsUpsert(docAsUpsert bool) *BulkUpdateRequest { return r } +// DetectNoop specifies whether changes that don't affect the document +// should be ignored (true) or unignored (false). This is enabled by default +// in Elasticsearch. +func (r *BulkUpdateRequest) DetectNoop(detectNoop bool) *BulkUpdateRequest { + r.detectNoop = &detectNoop + r.source = nil + return r +} + // Upsert specifies the document to use for upserts. It will be used for // create if the original document does not exist. func (r *BulkUpdateRequest) Upsert(doc interface{}) *BulkUpdateRequest { @@ -146,22 +155,6 @@ func (r *BulkUpdateRequest) Upsert(doc interface{}) *BulkUpdateRequest { return r } -// Ttl specifies the time to live, and optional expiry time. -// This is deprecated as of 2.0.0-beta2. -func (r *BulkUpdateRequest) Ttl(ttl int64) *BulkUpdateRequest { - r.ttl = ttl - r.source = nil - return r -} - -// Timestamp specifies a timestamp for the document. -// This is deprecated as of 2.0.0-beta2. -func (r *BulkUpdateRequest) Timestamp(timestamp string) *BulkUpdateRequest { - r.timestamp = timestamp - r.source = nil - return r -} - // String returns the on-wire representation of the update request, // concatenated as a single string. func (r *BulkUpdateRequest) String() string { @@ -193,9 +186,9 @@ func (r *BulkUpdateRequest) getSourceAsString(data interface{}) (string, error) // Source returns the on-wire representation of the update request, // split into an action-and-meta-data line and an (optional) source line. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html // for details. -func (r BulkUpdateRequest) Source() ([]string, error) { +func (r *BulkUpdateRequest) Source() ([]string, error) { // { "update" : { "_index" : "test", "_type" : "type1", "_id" : "1", ... } } // { "doc" : { "field1" : "value1", ... } } // or @@ -226,21 +219,12 @@ func (r BulkUpdateRequest) Source() ([]string, error) { if r.parent != "" { updateCommand["_parent"] = r.parent } - if r.timestamp != "" { - updateCommand["_timestamp"] = r.timestamp - } - if r.ttl > 0 { - updateCommand["_ttl"] = r.ttl - } if r.version > 0 { updateCommand["_version"] = r.version } if r.versionType != "" { updateCommand["_version_type"] = r.versionType } - if r.refresh != nil { - updateCommand["refresh"] = *r.refresh - } if r.retryOnConflict != nil { updateCommand["_retry_on_conflict"] = *r.retryOnConflict } @@ -256,9 +240,15 @@ func (r BulkUpdateRequest) Source() ([]string, error) { if r.docAsUpsert != nil { source["doc_as_upsert"] = *r.docAsUpsert } + if r.detectNoop != nil { + source["detect_noop"] = *r.detectNoop + } if r.upsert != nil { source["upsert"] = r.upsert } + if r.scriptedUpsert != nil { + source["scripted_upsert"] = *r.scriptedUpsert + } if r.doc != nil { // {"doc":{...}} source["doc"] = r.doc diff --git a/vendor/gopkg.in/olivere/elastic.v3/canonicalize.go b/vendor/gopkg.in/olivere/elastic.v5/canonicalize.go similarity index 81% rename from vendor/gopkg.in/olivere/elastic.v3/canonicalize.go rename to vendor/gopkg.in/olivere/elastic.v5/canonicalize.go index 1473f1466..a436f03b6 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/canonicalize.go +++ b/vendor/gopkg.in/olivere/elastic.v5/canonicalize.go @@ -8,21 +8,17 @@ import "net/url" // canonicalize takes a list of URLs and returns its canonicalized form, i.e. // remove anything but scheme, userinfo, host, path, and port. -// It also removes all trailing slashes. It also skips invalid URLs or -// URLs that do not use protocol http or https. +// It also removes all trailing slashes. Invalid URLs or URLs that do not +// use protocol http or https are skipped. // // Example: // http://127.0.0.1:9200/?query=1 -> http://127.0.0.1:9200 // http://127.0.0.1:9200/db1/ -> http://127.0.0.1:9200/db1 -// 127.0.0.1:9200 -> http://127.0.0.1:9200 func canonicalize(rawurls ...string) []string { var canonicalized []string for _, rawurl := range rawurls { u, err := url.Parse(rawurl) if err == nil { - if len(u.Scheme) == 0 { - u.Scheme = DefaultScheme - } if u.Scheme == "http" || u.Scheme == "https" { // Trim trailing slashes for len(u.Path) > 0 && u.Path[len(u.Path)-1] == '/' { diff --git a/vendor/gopkg.in/olivere/elastic.v3/clear_scroll.go b/vendor/gopkg.in/olivere/elastic.v5/clear_scroll.go similarity index 88% rename from vendor/gopkg.in/olivere/elastic.v3/clear_scroll.go rename to vendor/gopkg.in/olivere/elastic.v5/clear_scroll.go index 2ad9ae6ff..9c9fa4f7c 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/clear_scroll.go +++ b/vendor/gopkg.in/olivere/elastic.v5/clear_scroll.go @@ -8,11 +8,13 @@ import ( "fmt" "net/url" "strings" + + "golang.org/x/net/context" ) // ClearScrollService clears one or more scroll contexts by their ids. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#_clear_scroll_api +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-scroll.html#_clear_scroll_api // for details. type ClearScrollService struct { client *Client @@ -67,7 +69,7 @@ func (s *ClearScrollService) Validate() error { } // Do executes the operation. -func (s *ClearScrollService) Do() (*ClearScrollResponse, error) { +func (s *ClearScrollService) Do(ctx context.Context) (*ClearScrollResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -83,7 +85,7 @@ func (s *ClearScrollService) Do() (*ClearScrollResponse, error) { body := strings.Join(s.scrollId, ",") // Get HTTP response - res, err := s.client.PerformRequest("DELETE", path, params, body) + res, err := s.client.PerformRequest(ctx, "DELETE", path, params, body) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/client.go b/vendor/gopkg.in/olivere/elastic.v5/client.go similarity index 80% rename from vendor/gopkg.in/olivere/elastic.v3/client.go rename to vendor/gopkg.in/olivere/elastic.v5/client.go index fe0fa2254..5d6fd17b6 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/client.go +++ b/vendor/gopkg.in/olivere/elastic.v5/client.go @@ -9,7 +9,6 @@ import ( "encoding/json" "errors" "fmt" - "math/rand" "net/http" "net/http/httputil" "net/url" @@ -17,13 +16,16 @@ import ( "strings" "sync" "time" + + "golang.org/x/net/context" + "golang.org/x/net/context/ctxhttp" ) const ( // Version is the current version of Elastic. - Version = "3.0.43" + Version = "5.0.31" - // DefaultUrl is the default endpoint of Elasticsearch on the local machine. + // DefaultURL is the default endpoint of Elasticsearch on the local machine. // It is used e.g. when initializing a new Client without a specific URL. DefaultURL = "http://127.0.0.1:9200" @@ -67,11 +69,6 @@ const ( // process, DefaultSnifferTimeoutStartup is used. DefaultSnifferTimeout = 2 * time.Second - // DefaultMaxRetries is the number of retries for a single request after - // Elastic will give up and return an error. It is zero by default, so - // retry is disabled by default. - DefaultMaxRetries = 0 - // DefaultSendGetBodyAs is the HTTP method to use when elastic is sending // a GET request with a body. DefaultSendGetBodyAs = "GET" @@ -94,6 +91,9 @@ var ( // ErrTimeout is raised when a request timed out, e.g. when WaitForStatus // didn't return in time. ErrTimeout = errors.New("timeout") + + // noRetries is a retrier that does not retry. + noRetries = NewStopRetrier() ) // ClientOptionFunc is a function that configures a Client. @@ -108,31 +108,32 @@ type Client struct { conns []*conn // all connections cindex int // index into conns - mu sync.RWMutex // guards the next block - urls []string // set of URLs passed initially to the client - running bool // true if the client's background processes are running - errorlog Logger // error log for critical messages - infolog Logger // information log for e.g. response times - tracelog Logger // trace log for debugging - maxRetries int // max. number of retries - scheme string // http or https - healthcheckEnabled bool // healthchecks enabled or disabled - healthcheckTimeoutStartup time.Duration // time the healthcheck waits for a response from Elasticsearch on startup - healthcheckTimeout time.Duration // time the healthcheck waits for a response from Elasticsearch - healthcheckInterval time.Duration // interval between healthchecks - healthcheckStop chan bool // notify healthchecker to stop, and notify back - snifferEnabled bool // sniffer enabled or disabled - snifferTimeoutStartup time.Duration // time the sniffer waits for a response from nodes info API on startup - snifferTimeout time.Duration // time the sniffer waits for a response from nodes info API - snifferInterval time.Duration // interval between sniffing - snifferStop chan bool // notify sniffer to stop, and notify back - decoder Decoder // used to decode data sent from Elasticsearch - basicAuth bool // indicates whether to send HTTP Basic Auth credentials - basicAuthUsername string // username for HTTP Basic Auth - basicAuthPassword string // password for HTTP Basic Auth - sendGetBodyAs string // override for when sending a GET with a body - requiredPlugins []string // list of required plugins - gzipEnabled bool // gzip compression enabled or disabled (default) + mu sync.RWMutex // guards the next block + urls []string // set of URLs passed initially to the client + running bool // true if the client's background processes are running + errorlog Logger // error log for critical messages + infolog Logger // information log for e.g. response times + tracelog Logger // trace log for debugging + scheme string // http or https + healthcheckEnabled bool // healthchecks enabled or disabled + healthcheckTimeoutStartup time.Duration // time the healthcheck waits for a response from Elasticsearch on startup + healthcheckTimeout time.Duration // time the healthcheck waits for a response from Elasticsearch + healthcheckInterval time.Duration // interval between healthchecks + healthcheckStop chan bool // notify healthchecker to stop, and notify back + snifferEnabled bool // sniffer enabled or disabled + snifferTimeoutStartup time.Duration // time the sniffer waits for a response from nodes info API on startup + snifferTimeout time.Duration // time the sniffer waits for a response from nodes info API + snifferInterval time.Duration // interval between sniffing + snifferCallback SnifferCallback // callback to modify the sniffing decision + snifferStop chan bool // notify sniffer to stop, and notify back + decoder Decoder // used to decode data sent from Elasticsearch + basicAuth bool // indicates whether to send HTTP Basic Auth credentials + basicAuthUsername string // username for HTTP Basic Auth + basicAuthPassword string // password for HTTP Basic Auth + sendGetBodyAs string // override for when sending a GET with a body + requiredPlugins []string // list of required plugins + gzipEnabled bool // gzip compression enabled or disabled (default) + retrier Retrier // strategy for retries } // NewClient creates a new client to work with Elasticsearch. @@ -148,14 +149,13 @@ type Client struct { // // client, err := elastic.NewClient( // elastic.SetURL("http://127.0.0.1:9200", "http://127.0.0.1:9201"), -// elastic.SetMaxRetries(10), // elastic.SetBasicAuth("user", "secret")) // // If no URL is configured, Elastic uses DefaultURL by default. // // If the sniffer is enabled (the default), the new client then sniffes // the cluster via the Nodes Info API -// (see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-info.html#cluster-nodes-info). +// (see https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-nodes-info.html#cluster-nodes-info). // It uses the URLs specified by the caller. The caller is responsible // to only pass a list of URLs of nodes that belong to the same cluster. // This sniffing process is run on startup and periodically. @@ -174,7 +174,10 @@ type Client struct { // // Connections are automatically marked as dead or healthy while // making requests to Elasticsearch. When a request fails, Elastic will -// retry up to a maximum number of retries configured with SetMaxRetries. +// call into the Retry strategy which can be specified with SetRetry. +// The Retry strategy is also responsible for handling backoff i.e. the time +// to wait before starting the next request. There are various standard +// backoff implementations, e.g. ExponentialBackoff or SimpleBackoff. // Retries are disabled by default. // // If no HttpClient is configured, then http.DefaultClient is used. @@ -191,7 +194,6 @@ func NewClient(options ...ClientOptionFunc) (*Client, error) { cindex: -1, scheme: DefaultScheme, decoder: &DefaultDecoder{}, - maxRetries: DefaultMaxRetries, healthcheckEnabled: DefaultHealthcheckEnabled, healthcheckTimeoutStartup: DefaultHealthcheckTimeoutStartup, healthcheckTimeout: DefaultHealthcheckTimeout, @@ -201,9 +203,11 @@ func NewClient(options ...ClientOptionFunc) (*Client, error) { snifferTimeoutStartup: DefaultSnifferTimeoutStartup, snifferTimeout: DefaultSnifferTimeout, snifferInterval: DefaultSnifferInterval, + snifferCallback: nopSnifferCallback, snifferStop: make(chan bool), sendGetBodyAs: DefaultSendGetBodyAs, gzipEnabled: DefaultGzipEnabled, + retrier: noRetries, // no retries by default } // Run the options on it @@ -213,11 +217,25 @@ func NewClient(options ...ClientOptionFunc) (*Client, error) { } } + // Use a default URL and normalize them if len(c.urls) == 0 { c.urls = []string{DefaultURL} } c.urls = canonicalize(c.urls...) + // If the URLs have auth info, use them here as an alternative to SetBasicAuth + if !c.basicAuth { + for _, urlStr := range c.urls { + u, err := url.Parse(urlStr) + if err == nil && u.User != nil { + c.basicAuth = true + c.basicAuthUsername = u.User.Username() + c.basicAuthPassword, _ = u.User.Password() + break + } + } + } + // Check if we can make a request to any of the specified URLs if c.healthcheckEnabled { if err := c.startupHealthcheck(c.healthcheckTimeoutStartup); err != nil { @@ -293,7 +311,6 @@ func NewSimpleClient(options ...ClientOptionFunc) (*Client, error) { cindex: -1, scheme: DefaultScheme, decoder: &DefaultDecoder{}, - maxRetries: 1, healthcheckEnabled: false, healthcheckTimeoutStartup: off, healthcheckTimeout: off, @@ -303,9 +320,11 @@ func NewSimpleClient(options ...ClientOptionFunc) (*Client, error) { snifferTimeoutStartup: off, snifferTimeout: off, snifferInterval: off, + snifferCallback: nopSnifferCallback, snifferStop: make(chan bool), sendGetBodyAs: DefaultSendGetBodyAs, gzipEnabled: DefaultGzipEnabled, + retrier: noRetries, // no retries by default } // Run the options on it @@ -315,11 +334,25 @@ func NewSimpleClient(options ...ClientOptionFunc) (*Client, error) { } } + // Use a default URL and normalize them if len(c.urls) == 0 { c.urls = []string{DefaultURL} } c.urls = canonicalize(c.urls...) + // If the URLs have auth info, use them here as an alternative to SetBasicAuth + if !c.basicAuth { + for _, urlStr := range c.urls { + u, err := url.Parse(urlStr) + if err == nil && u.User != nil { + c.basicAuth = true + c.basicAuthUsername = u.User.Username() + c.basicAuthPassword, _ = u.User.Password() + break + } + } + } + for _, url := range c.urls { c.conns = append(c.conns, newConn(url, url)) } @@ -434,6 +467,27 @@ func SetSnifferInterval(interval time.Duration) ClientOptionFunc { } } +// SnifferCallback defines the protocol for sniffing decisions. +type SnifferCallback func(*NodesInfoNode) bool + +// nopSnifferCallback is the default sniffer callback: It accepts +// all nodes the sniffer finds. +var nopSnifferCallback = func(*NodesInfoNode) bool { return true } + +// SetSnifferCallback allows the caller to modify sniffer decisions. +// When setting the callback, the given SnifferCallback is called for +// each (healthy) node found during the sniffing process. +// If the callback returns false, the node is ignored: No requests +// are routed to it. +func SetSnifferCallback(f SnifferCallback) ClientOptionFunc { + return func(c *Client) error { + if f != nil { + c.snifferCallback = f + } + return nil + } +} + // SetHealthcheck enables or disables healthchecks (enabled by default). func SetHealthcheck(enabled bool) ClientOptionFunc { return func(c *Client) error { @@ -476,12 +530,24 @@ func SetHealthcheckInterval(interval time.Duration) ClientOptionFunc { // SetMaxRetries sets the maximum number of retries before giving up when // performing a HTTP request to Elasticsearch. +// +// Deprecated: Replace with a Retry implementation. func SetMaxRetries(maxRetries int) ClientOptionFunc { return func(c *Client) error { if maxRetries < 0 { return errors.New("MaxRetries must be greater than or equal to 0") + } else if maxRetries == 0 { + c.retrier = noRetries + } else { + // Create a Retrier that will wait for 100ms (+/- jitter) between requests. + // This resembles the old behavior with maxRetries. + ticks := make([]int, maxRetries) + for i := 0; i < len(ticks); i++ { + ticks[i] = 100 + } + backoff := NewSimpleBackoff(ticks...) + c.retrier = NewBackoffRetrier(backoff) } - c.maxRetries = maxRetries return nil } } @@ -546,7 +612,7 @@ func SetTraceLog(logger Logger) ClientOptionFunc { } } -// SendGetBodyAs specifies the HTTP method to use when sending a GET request +// SetSendGetBodyAs specifies the HTTP method to use when sending a GET request // with a body. It is GET by default. func SetSendGetBodyAs(httpMethod string) ClientOptionFunc { return func(c *Client) error { @@ -555,6 +621,18 @@ func SetSendGetBodyAs(httpMethod string) ClientOptionFunc { } } +// SetRetrier specifies the retry strategy that handles errors during +// HTTP request/response with Elasticsearch. +func SetRetrier(retrier Retrier) ClientOptionFunc { + return func(c *Client) error { + if retrier == nil { + retrier = noRetries // no retries by default + } + c.retrier = retrier + return nil + } +} + // String returns a string representation of the client status. func (c *Client) String() string { c.connsMu.Lock() @@ -681,9 +759,10 @@ func (c *Client) dumpResponse(resp *http.Response) { func (c *Client) sniffer() { c.mu.RLock() timeout := c.snifferTimeout + interval := c.snifferInterval c.mu.RUnlock() - ticker := time.NewTicker(timeout) + ticker := time.NewTicker(interval) defer ticker.Stop() for { @@ -711,8 +790,8 @@ func (c *Client) sniff(timeout time.Duration) error { } // Use all available URLs provided to sniff the cluster. + var urls []string urlsMap := make(map[string]bool) - urls := make([]string, 0) // Add all URLs provided on startup for _, url := range c.urls { @@ -763,7 +842,7 @@ func (c *Client) sniff(timeout time.Duration) error { // from the result of calling Nodes Info API. Otherwise, an empty array // is returned. func (c *Client) sniffNode(url string) []*conn { - nodes := make([]*conn, 0) + var nodes []*conn // Call the Nodes Info API at /_nodes/http req, err := NewRequest("GET", url+"/_nodes/http") @@ -792,19 +871,13 @@ func (c *Client) sniffNode(url string) []*conn { var info NodesInfoResponse if err := json.NewDecoder(res.Body).Decode(&info); err == nil { if len(info.Nodes) > 0 { - switch c.scheme { - case "https": - for nodeID, node := range info.Nodes { - url := c.extractHostname("https", node.HTTPSAddress) - if url != "" { - nodes = append(nodes, newConn(nodeID, url)) - } - } - default: - for nodeID, node := range info.Nodes { - url := c.extractHostname("http", node.HTTPAddress) - if url != "" { - nodes = append(nodes, newConn(nodeID, url)) + for nodeID, node := range info.Nodes { + if c.snifferCallback(node) { + if node.HTTP != nil && len(node.HTTP.PublishAddress) > 0 { + url := c.extractHostname(c.scheme, node.HTTP.PublishAddress) + if url != "" { + nodes = append(nodes, newConn(nodeID, url)) + } } } } @@ -839,11 +912,10 @@ func (c *Client) extractHostname(scheme, address string) string { func (c *Client) updateConns(conns []*conn) { c.connsMu.Lock() - newConns := make([]*conn, 0) - // Build up new connections: // If we find an existing connection, use that (including no. of failures etc.). // If we find a new connection, add it. + var newConns []*conn for _, conn := range conns { var found bool for _, oldConn := range c.conns { @@ -870,9 +942,10 @@ func (c *Client) updateConns(conns []*conn) { func (c *Client) healthchecker() { c.mu.RLock() timeout := c.healthcheckTimeout + interval := c.healthcheckInterval c.mu.RUnlock() - ticker := time.NewTicker(timeout) + ticker := time.NewTicker(interval) defer ticker.Stop() for { @@ -906,34 +979,52 @@ func (c *Client) healthcheck(timeout time.Duration, force bool) { conns := c.conns c.connsMu.RUnlock() - timeoutInMillis := int64(timeout / time.Millisecond) - for _, conn := range conns { - params := make(url.Values) - params.Set("timeout", fmt.Sprintf("%dms", timeoutInMillis)) - req, err := NewRequest("HEAD", conn.URL()+"/?"+params.Encode()) - if err == nil { + // Run the HEAD request against ES with a timeout + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + // Goroutine executes the HTTP request, returns an error and sets status + var status int + errc := make(chan error, 1) + go func(url string) { + req, err := NewRequest("HEAD", url) + if err != nil { + errc <- err + return + } if basicAuth { req.SetBasicAuth(basicAuthUsername, basicAuthPassword) } res, err := c.c.Do((*http.Request)(req)) - if err == nil { + if res != nil { + status = res.StatusCode if res.Body != nil { - defer res.Body.Close() + res.Body.Close() } - if res.StatusCode >= 200 && res.StatusCode < 300 { - conn.MarkAsAlive() - } else { - conn.MarkAsDead() - c.errorf("elastic: %s is dead [status=%d]", conn.URL(), res.StatusCode) - } - } else { - c.errorf("elastic: %s is dead", conn.URL()) - conn.MarkAsDead() } - } else { + errc <- err + }(conn.URL()) + + // Wait for the Goroutine (or its timeout) + select { + case <-ctx.Done(): // timeout c.errorf("elastic: %s is dead", conn.URL()) conn.MarkAsDead() + break + case err := <-errc: + if err != nil { + c.errorf("elastic: %s is dead", conn.URL()) + conn.MarkAsDead() + break + } + if status >= 200 && status < 300 { + conn.MarkAsAlive() + } else { + conn.MarkAsDead() + c.errorf("elastic: %s is dead [status=%d]", conn.URL(), status) + } + break } } } @@ -987,11 +1078,11 @@ func (c *Client) next() (*conn, error) { i := 0 numConns := len(c.conns) for { - i += 1 + i++ if i > numConns { break // we visited all conns: they all seem to be dead } - c.cindex += 1 + c.cindex++ if c.cindex >= numConns { c.cindex = 0 } @@ -1031,17 +1122,16 @@ func (c *Client) mustActiveConn() error { } // PerformRequest does a HTTP request to Elasticsearch. -// It returns a response and an error on failure. +// It returns a response (which might be nil) and an error on failure. // // Optionally, a list of HTTP error codes to ignore can be passed. // This is necessary for services that expect e.g. HTTP status 404 as a // valid outcome (Exists, IndicesExists, IndicesTypeExists). -func (c *Client) PerformRequest(method, path string, params url.Values, body interface{}, ignoreErrors ...int) (*Response, error) { +func (c *Client) PerformRequest(ctx context.Context, method, path string, params url.Values, body interface{}, ignoreErrors ...int) (*Response, error) { start := time.Now().UTC() c.mu.RLock() timeout := c.healthcheckTimeout - retries := c.maxRetries basicAuth := c.basicAuth basicAuthUsername := c.basicAuthUsername basicAuthPassword := c.basicAuthPassword @@ -1054,10 +1144,7 @@ func (c *Client) PerformRequest(method, path string, params url.Values, body int var req *Request var resp *Response var retried bool - - // We wait between retries, using simple exponential back-off. - // TODO: Make this configurable, including the jitter. - retryWaitMsec := int64(100 + (rand.Intn(20) - 10)) + var n int // Change method if sendGetBodyAs is specified. if method == "GET" && body != nil && sendGetBodyAs != "GET" { @@ -1073,17 +1160,20 @@ func (c *Client) PerformRequest(method, path string, params url.Values, body int // Get a connection conn, err = c.next() if err == ErrNoClient { + n++ if !retried { // Force a healtcheck as all connections seem to be dead. c.healthcheck(timeout, false) } - retries -= 1 - if retries <= 0 { + wait, ok, rerr := c.retrier.Retry(ctx, n, nil, nil, err) + if rerr != nil { + return nil, rerr + } + if !ok { return nil, err } retried = true - time.Sleep(time.Duration(retryWaitMsec) * time.Millisecond) - retryWaitMsec += retryWaitMsec + time.Sleep(wait) continue // try again } if err != nil { @@ -1114,17 +1204,26 @@ func (c *Client) PerformRequest(method, path string, params url.Values, body int c.dumpRequest((*http.Request)(req)) // Get response - res, err := c.c.Do((*http.Request)(req)) + res, err := ctxhttp.Do(ctx, c.c, (*http.Request)(req)) + if err == context.Canceled || err == context.DeadlineExceeded { + // Proceed, but don't mark the node as dead + return nil, err + } if err != nil { - retries -= 1 - if retries <= 0 { + n++ + wait, ok, rerr := c.retrier.Retry(ctx, n, (*http.Request)(req), res, err) + if rerr != nil { + c.errorf("elastic: %s is dead", conn.URL()) + conn.MarkAsDead() + return nil, rerr + } + if !ok { c.errorf("elastic: %s is dead", conn.URL()) conn.MarkAsDead() return nil, err } retried = true - time.Sleep(time.Duration(retryWaitMsec) * time.Millisecond) - retryWaitMsec += retryWaitMsec + time.Sleep(wait) continue // try again } if res.Body != nil { @@ -1134,7 +1233,9 @@ func (c *Client) PerformRequest(method, path string, params url.Values, body int // Check for errors if err := checkResponse((*http.Request)(req), res, ignoreErrors...); err != nil { // No retry if request succeeded - return nil, err + // We still try to return a response. + resp, _ = c.newResponse(res) + return resp, err } // Tracing @@ -1213,28 +1314,11 @@ func (c *Client) BulkProcessor() *BulkProcessorService { return NewBulkProcessorService(c) } -// Reindex returns a service that will reindex documents from a source -// index into a target index. +// Reindex copies data from a source index into a destination index. // -// Notice that this Reindexer is an Elastic-specific solution that pre-dated -// the Reindex API introduced in Elasticsearch 2.3.0 (see ReindexTask). -// -// See http://www.elastic.co/guide/en/elasticsearch/guide/current/reindex.html -// for more information about reindexing. -func (c *Client) Reindex(sourceIndex, targetIndex string) *Reindexer { - return NewReindexer(c, sourceIndex, CopyToTargetIndex(targetIndex)) -} - -// ReindexTask copies data from a source index into a destination index. -// -// The Reindex API has been introduced in Elasticsearch 2.3.0. Notice that -// there is a Elastic-specific Reindexer that pre-dates the Reindex API from -// Elasticsearch. If you rely on that, use the ReindexerService via -// Client.Reindex. -// -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-reindex.html // for details on the Reindex API. -func (c *Client) ReindexTask() *ReindexService { +func (c *Client) Reindex() *ReindexService { return NewReindexService(c) } @@ -1279,12 +1363,6 @@ func (c *Client) Explain(index, typ, id string) *ExplainService { return NewExplainService(c).Index(index).Type(typ).Id(id) } -// Percolate allows to send a document and return matching queries. -// See http://www.elastic.co/guide/en/elasticsearch/reference/current/search-percolate.html. -func (c *Client) Percolate() *PercolateService { - return NewPercolateService(c) -} - // TODO Search Template // TODO Search Shards API // TODO Search Exists API @@ -1300,15 +1378,8 @@ func (c *Client) Exists() *ExistsService { return NewExistsService(c) } -// Scan through documents. Use this to iterate inside a server process -// where the results will be processed without returning them to a client. -func (c *Client) Scan(indices ...string) *ScanService { - return NewScanService(c).Index(indices...) -} - // Scroll through documents. Use this to efficiently scroll through results -// while returning the results to a client. Use Scan when you don't need -// to return requests to a client (i.e. not paginating via request/response). +// while returning the results to a client. func (c *Client) Scroll(indices ...string) *ScrollService { return NewScrollService(c).Index(indices...) } @@ -1335,6 +1406,17 @@ func (c *Client) IndexExists(indices ...string) *IndicesExistsService { return NewIndicesExistsService(c).Index(indices) } +// ShrinkIndex returns a service to shrink one index into another. +func (c *Client) ShrinkIndex(source, target string) *IndicesShrinkService { + return NewIndicesShrinkService(c).Source(source).Target(target) +} + +// RolloverIndex rolls an alias over to a new index when the existing index +// is considered to be too large or too old. +func (c *Client) RolloverIndex(alias string) *IndicesRolloverService { + return NewIndicesRolloverService(c).Alias(alias) +} + // TypeExists allows to check if one or more types exist in one or more indices. func (c *Client) TypeExists() *IndicesExistsTypeService { return NewIndicesExistsTypeService(c) @@ -1372,10 +1454,10 @@ func (c *Client) IndexPutSettings(indices ...string) *IndicesPutSettingsService return NewIndicesPutSettingsService(c).Index(indices...) } -// Optimize asks Elasticsearch to optimize one or more indices. -// Optimize is deprecated as of Elasticsearch 2.1 and replaced by Forcemerge. -func (c *Client) Optimize(indices ...string) *OptimizeService { - return NewOptimizeService(c).Index(indices...) +// IndexAnalyze performs the analysis process on a text and returns the +// token breakdown of the text. +func (c *Client) IndexAnalyze() *IndicesAnalyzeService { + return NewIndicesAnalyzeService(c) } // Forcemerge optimizes one or more indices. @@ -1457,19 +1539,9 @@ func (c *Client) PutMapping() *IndicesPutMappingService { return NewIndicesPutMappingService(c) } -// GetWarmer gets one or more warmers by name. -func (c *Client) GetWarmer() *IndicesGetWarmerService { - return NewIndicesGetWarmerService(c) -} - -// PutWarmer registers a warmer. -func (c *Client) PutWarmer() *IndicesPutWarmerService { - return NewIndicesPutWarmerService(c) -} - -// DeleteWarmer deletes one or more warmers. -func (c *Client) DeleteWarmer() *IndicesDeleteWarmerService { - return NewIndicesDeleteWarmerService(c) +// GetFieldMapping gets mapping for fields. +func (c *Client) GetFieldMapping() *IndicesGetFieldMappingService { + return NewIndicesGetFieldMappingService(c) } // -- cat APIs -- @@ -1489,6 +1561,30 @@ func (c *Client) DeleteWarmer() *IndicesDeleteWarmerService { // TODO cat shards // TODO cat segments +// -- Ingest APIs -- + +// IngestPutPipeline adds pipelines and updates existing pipelines in +// the cluster. +func (c *Client) IngestPutPipeline(id string) *IngestPutPipelineService { + return NewIngestPutPipelineService(c).Id(id) +} + +// IngestGetPipeline returns pipelines based on ID. +func (c *Client) IngestGetPipeline(ids ...string) *IngestGetPipelineService { + return NewIngestGetPipelineService(c).Id(ids...) +} + +// IngestDeletePipeline deletes a pipeline by ID. +func (c *Client) IngestDeletePipeline(id string) *IngestDeletePipelineService { + return NewIngestDeletePipelineService(c).Id(id) +} + +// IngestSimulatePipeline executes a specific pipeline against the set of +// documents provided in the body of the request. +func (c *Client) IngestSimulatePipeline() *IngestSimulatePipelineService { + return NewIngestSimulatePipelineService(c) +} + // -- Cluster APIs -- // ClusterHealth retrieves the health of the cluster. @@ -1511,6 +1607,11 @@ func (c *Client) NodesInfo() *NodesInfoService { return NewNodesInfoService(c) } +// NodesStats retrieves one or more or all of the cluster nodes statistics. +func (c *Client) NodesStats() *NodesStatsService { + return NewNodesStatsService(c) +} + // TasksCancel cancels tasks running on the specified nodes. func (c *Client) TasksCancel() *TasksCancelService { return NewTasksCancelService(c) @@ -1544,7 +1645,7 @@ func (c *Client) TasksList() *TasksListService { // ElasticsearchVersion returns the version number of Elasticsearch // running on the given URL. func (c *Client) ElasticsearchVersion(url string) (string, error) { - res, _, err := c.Ping(url).Do() + res, _, err := c.Ping(url).Do(context.Background()) if err != nil { return "", err } @@ -1553,12 +1654,12 @@ func (c *Client) ElasticsearchVersion(url string) (string, error) { // IndexNames returns the names of all indices in the cluster. func (c *Client) IndexNames() ([]string, error) { - res, err := c.IndexGetSettings().Index("_all").Do() + res, err := c.IndexGetSettings().Index("_all").Do(context.Background()) if err != nil { return nil, err } var names []string - for name, _ := range res { + for name := range res { names = append(names, name) } return names, nil @@ -1580,7 +1681,7 @@ func (c *Client) Ping(url string) *PingService { // If the cluster will have the given state within the timeout, nil is returned. // If the request timed out, ErrTimeout is returned. func (c *Client) WaitForStatus(status string, timeout string) error { - health, err := c.ClusterHealth().WaitForStatus(status).Timeout(timeout).Do() + health, err := c.ClusterHealth().WaitForStatus(status).Timeout(timeout).Do(context.Background()) if err != nil { return err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/cluster_health.go b/vendor/gopkg.in/olivere/elastic.v5/cluster_health.go similarity index 86% rename from vendor/gopkg.in/olivere/elastic.v3/cluster_health.go rename to vendor/gopkg.in/olivere/elastic.v5/cluster_health.go index fae7c4d91..caf15fe87 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/cluster_health.go +++ b/vendor/gopkg.in/olivere/elastic.v5/cluster_health.go @@ -9,25 +9,27 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // ClusterHealthService allows to get a very simple status on the health of the cluster. // -// See http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html +// See http://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-health.html // for details. type ClusterHealthService struct { - client *Client - pretty bool - indices []string - level string - local *bool - masterTimeout string - timeout string - waitForActiveShards *int - waitForNodes string - waitForRelocatingShards *int - waitForStatus string + client *Client + pretty bool + indices []string + level string + local *bool + masterTimeout string + timeout string + waitForActiveShards *int + waitForNodes string + waitForNoRelocatingShards *bool + waitForStatus string } // NewClusterHealthService creates a new ClusterHealthService. @@ -82,9 +84,9 @@ func (s *ClusterHealthService) WaitForNodes(waitForNodes string) *ClusterHealthS return s } -// WaitForRelocatingShards can be used to wait until the specified number of relocating shards is finished. -func (s *ClusterHealthService) WaitForRelocatingShards(waitForRelocatingShards int) *ClusterHealthService { - s.waitForRelocatingShards = &waitForRelocatingShards +// WaitForNoRelocatingShards can be used to wait until all shard relocations are finished. +func (s *ClusterHealthService) WaitForNoRelocatingShards(waitForNoRelocatingShards bool) *ClusterHealthService { + s.waitForNoRelocatingShards = &waitForNoRelocatingShards return s } @@ -150,8 +152,8 @@ func (s *ClusterHealthService) buildURL() (string, url.Values, error) { if s.waitForNodes != "" { params.Set("wait_for_nodes", s.waitForNodes) } - if s.waitForRelocatingShards != nil { - params.Set("wait_for_relocating_shards", fmt.Sprintf("%v", s.waitForRelocatingShards)) + if s.waitForNoRelocatingShards != nil { + params.Set("wait_for_no_relocating_shards", fmt.Sprintf("%v", *s.waitForNoRelocatingShards)) } if s.waitForStatus != "" { params.Set("wait_for_status", s.waitForStatus) @@ -165,7 +167,7 @@ func (s *ClusterHealthService) Validate() error { } // Do executes the operation. -func (s *ClusterHealthService) Do() (*ClusterHealthResponse, error) { +func (s *ClusterHealthService) Do(ctx context.Context) (*ClusterHealthResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -178,7 +180,7 @@ func (s *ClusterHealthService) Do() (*ClusterHealthResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/cluster_state.go b/vendor/gopkg.in/olivere/elastic.v5/cluster_state.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v3/cluster_state.go rename to vendor/gopkg.in/olivere/elastic.v5/cluster_state.go index e59c835a5..3458efc48 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/cluster_state.go +++ b/vendor/gopkg.in/olivere/elastic.v5/cluster_state.go @@ -9,12 +9,14 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // ClusterStateService allows to get a comprehensive state information of the whole cluster. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-state.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-state.html // for details. type ClusterStateService struct { client *Client @@ -151,7 +153,7 @@ func (s *ClusterStateService) Validate() error { } // Do executes the operation. -func (s *ClusterStateService) Do() (*ClusterStateResponse, error) { +func (s *ClusterStateService) Do(ctx context.Context) (*ClusterStateResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -164,7 +166,7 @@ func (s *ClusterStateService) Do() (*ClusterStateResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } @@ -258,7 +260,7 @@ type shardRouting struct { RelocatingNode string `json:"relocating_node"` Shard int `json:"shard"` Index string `json:"index"` - Version int64 `json:"state"` + Version int64 `json:"version"` RestoreSource *RestoreSource `json:"restore_source"` AllocationId *allocationId `json:"allocation_id"` UnassignedInfo *unassignedInfo `json:"unassigned_info"` diff --git a/vendor/gopkg.in/olivere/elastic.v3/cluster_stats.go b/vendor/gopkg.in/olivere/elastic.v5/cluster_stats.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v3/cluster_stats.go rename to vendor/gopkg.in/olivere/elastic.v5/cluster_stats.go index 09c1d8ca0..e71a561fc 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/cluster_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v5/cluster_stats.go @@ -9,10 +9,13 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) -// ClusterStatsService is documented at http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/cluster-stats.html. +// ClusterStatsService is documented at +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-stats.html. type ClusterStatsService struct { client *Client pretty bool @@ -93,7 +96,7 @@ func (s *ClusterStatsService) Validate() error { } // Do executes the operation. -func (s *ClusterStatsService) Do() (*ClusterStatsResponse, error) { +func (s *ClusterStatsService) Do(ctx context.Context) (*ClusterStatsResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -106,7 +109,7 @@ func (s *ClusterStatsService) Do() (*ClusterStatsResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/connection.go b/vendor/gopkg.in/olivere/elastic.v5/connection.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v3/connection.go rename to vendor/gopkg.in/olivere/elastic.v5/connection.go index b8b5bf8aa..0f27a8756 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/connection.go +++ b/vendor/gopkg.in/olivere/elastic.v5/connection.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/count.go b/vendor/gopkg.in/olivere/elastic.v5/count.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v3/count.go rename to vendor/gopkg.in/olivere/elastic.v5/count.go index 804458274..459ea0bff 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/count.go +++ b/vendor/gopkg.in/olivere/elastic.v5/count.go @@ -9,7 +9,9 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // CountService is a convenient service for determining the @@ -256,7 +258,7 @@ func (s *CountService) Validate() error { } // Do executes the operation. -func (s *CountService) Do() (int64, error) { +func (s *CountService) Do(ctx context.Context) (int64, error) { // Check pre-conditions if err := s.Validate(); err != nil { return 0, err @@ -285,7 +287,7 @@ func (s *CountService) Do() (int64, error) { } // Get HTTP response - res, err := s.client.PerformRequest("POST", path, params, body) + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) if err != nil { return 0, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/decoder.go b/vendor/gopkg.in/olivere/elastic.v5/decoder.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/decoder.go rename to vendor/gopkg.in/olivere/elastic.v5/decoder.go index 765a5be30..9cd2cf720 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/decoder.go +++ b/vendor/gopkg.in/olivere/elastic.v5/decoder.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/delete.go b/vendor/gopkg.in/olivere/elastic.v5/delete.go similarity index 72% rename from vendor/gopkg.in/olivere/elastic.v3/delete.go rename to vendor/gopkg.in/olivere/elastic.v5/delete.go index bf78ce8ff..01ca5e289 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/delete.go +++ b/vendor/gopkg.in/olivere/elastic.v5/delete.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,28 +8,29 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // DeleteService allows to delete a typed JSON document from a specified // index based on its id. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-delete.html // for details. type DeleteService struct { - client *Client - pretty bool - id string - index string - typ string - routing string - timeout string - version interface{} - versionType string - consistency string - parent string - refresh *bool - replication string + client *Client + pretty bool + id string + index string + typ string + routing string + timeout string + version interface{} + versionType string + waitForActiveShards string + parent string + refresh string } // NewDeleteService creates a new DeleteService. @@ -57,12 +58,6 @@ func (s *DeleteService) Index(index string) *DeleteService { return s } -// Replication specifies a replication type. -func (s *DeleteService) Replication(replication string) *DeleteService { - s.replication = replication - return s -} - // Routing is a specific routing value. func (s *DeleteService) Routing(routing string) *DeleteService { s.routing = routing @@ -87,9 +82,13 @@ func (s *DeleteService) VersionType(versionType string) *DeleteService { return s } -// Consistency defines a specific write consistency setting for the operation. -func (s *DeleteService) Consistency(consistency string) *DeleteService { - s.consistency = consistency +// WaitForActiveShards sets the number of shard copies that must be active +// before proceeding with the delete operation. Defaults to 1, meaning the +// primary shard only. Set to `all` for all shard copies, otherwise set to +// any non-negative value less than or equal to the total number of copies +// for the shard (number of replicas + 1). +func (s *DeleteService) WaitForActiveShards(waitForActiveShards string) *DeleteService { + s.waitForActiveShards = waitForActiveShards return s } @@ -100,8 +99,8 @@ func (s *DeleteService) Parent(parent string) *DeleteService { } // Refresh the index after performing the operation. -func (s *DeleteService) Refresh(refresh bool) *DeleteService { - s.refresh = &refresh +func (s *DeleteService) Refresh(refresh string) *DeleteService { + s.refresh = refresh return s } @@ -128,11 +127,8 @@ func (s *DeleteService) buildURL() (string, url.Values, error) { if s.pretty { params.Set("pretty", "1") } - if s.refresh != nil { - params.Set("refresh", fmt.Sprintf("%v", *s.refresh)) - } - if s.replication != "" { - params.Set("replication", s.replication) + if s.refresh != "" { + params.Set("refresh", s.refresh) } if s.routing != "" { params.Set("routing", s.routing) @@ -146,8 +142,8 @@ func (s *DeleteService) buildURL() (string, url.Values, error) { if s.versionType != "" { params.Set("version_type", s.versionType) } - if s.consistency != "" { - params.Set("consistency", s.consistency) + if s.waitForActiveShards != "" { + params.Set("wait_for_active_shards", s.waitForActiveShards) } if s.parent != "" { params.Set("parent", s.parent) @@ -174,7 +170,7 @@ func (s *DeleteService) Validate() error { } // Do executes the operation. -func (s *DeleteService) Do() (*DeleteResponse, error) { +func (s *DeleteService) Do(ctx context.Context) (*DeleteResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -187,7 +183,7 @@ func (s *DeleteService) Do() (*DeleteResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("DELETE", path, params, nil) + res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/delete_by_query.go b/vendor/gopkg.in/olivere/elastic.v5/delete_by_query.go new file mode 100644 index 000000000..25ae53ba1 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/delete_by_query.go @@ -0,0 +1,649 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "fmt" + "net/url" + "strings" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// DeleteByQueryService deletes documents that match a query. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-delete-by-query.html. +type DeleteByQueryService struct { + client *Client + index []string + typ []string + query Query + body interface{} + xSource []string + xSourceExclude []string + xSourceInclude []string + analyzer string + analyzeWildcard *bool + allowNoIndices *bool + conflicts string + defaultOperator string + df string + docvalueFields []string + expandWildcards string + explain *bool + from *int + ignoreUnavailable *bool + lenient *bool + lowercaseExpandedTerms *bool + preference string + q string + refresh string + requestCache *bool + requestsPerSecond *int + routing []string + scroll string + scrollSize *int + searchTimeout string + searchType string + size *int + sort []string + stats []string + storedFields []string + suggestField string + suggestMode string + suggestSize *int + suggestText string + terminateAfter *int + timeout string + trackScores *bool + version *bool + waitForActiveShards string + waitForCompletion *bool + pretty bool +} + +// NewDeleteByQueryService creates a new DeleteByQueryService. +// You typically use the client's DeleteByQuery to get a reference to +// the service. +func NewDeleteByQueryService(client *Client) *DeleteByQueryService { + builder := &DeleteByQueryService{ + client: client, + } + return builder +} + +// Index sets the indices on which to perform the delete operation. +func (s *DeleteByQueryService) Index(index ...string) *DeleteByQueryService { + s.index = append(s.index, index...) + return s +} + +// Type limits the delete operation to the given types. +func (s *DeleteByQueryService) Type(typ ...string) *DeleteByQueryService { + s.typ = append(s.typ, typ...) + return s +} + +// XSource is true or false to return the _source field or not, +// or a list of fields to return. +func (s *DeleteByQueryService) XSource(xSource ...string) *DeleteByQueryService { + s.xSource = append(s.xSource, xSource...) + return s +} + +// XSourceExclude represents a list of fields to exclude from the returned _source field. +func (s *DeleteByQueryService) XSourceExclude(xSourceExclude ...string) *DeleteByQueryService { + s.xSourceExclude = append(s.xSourceExclude, xSourceExclude...) + return s +} + +// XSourceInclude represents a list of fields to extract and return from the _source field. +func (s *DeleteByQueryService) XSourceInclude(xSourceInclude ...string) *DeleteByQueryService { + s.xSourceInclude = append(s.xSourceInclude, xSourceInclude...) + return s +} + +// Analyzer to use for the query string. +func (s *DeleteByQueryService) Analyzer(analyzer string) *DeleteByQueryService { + s.analyzer = analyzer + return s +} + +// AnalyzeWildcard specifies whether wildcard and prefix queries should be +// analyzed (default: false). +func (s *DeleteByQueryService) AnalyzeWildcard(analyzeWildcard bool) *DeleteByQueryService { + s.analyzeWildcard = &analyzeWildcard + return s +} + +// AllowNoIndices indicates whether to ignore if a wildcard indices +// expression resolves into no concrete indices (including the _all string +// or when no indices have been specified). +func (s *DeleteByQueryService) AllowNoIndices(allow bool) *DeleteByQueryService { + s.allowNoIndices = &allow + return s +} + +// Conflicts indicates what to do when the process detects version conflicts. +// Possible values are "proceed" and "abort". +func (s *DeleteByQueryService) Conflicts(conflicts string) *DeleteByQueryService { + s.conflicts = conflicts + return s +} + +// AbortOnVersionConflict aborts the request on version conflicts. +// It is an alias to setting Conflicts("abort"). +func (s *DeleteByQueryService) AbortOnVersionConflict() *DeleteByQueryService { + s.conflicts = "abort" + return s +} + +// ProceedOnVersionConflict aborts the request on version conflicts. +// It is an alias to setting Conflicts("proceed"). +func (s *DeleteByQueryService) ProceedOnVersionConflict() *DeleteByQueryService { + s.conflicts = "proceed" + return s +} + +// DefaultOperator for query string query (AND or OR). +func (s *DeleteByQueryService) DefaultOperator(defaultOperator string) *DeleteByQueryService { + s.defaultOperator = defaultOperator + return s +} + +// DF is the field to use as default where no field prefix is given in the query string. +func (s *DeleteByQueryService) DF(defaultField string) *DeleteByQueryService { + s.df = defaultField + return s +} + +// DefaultField is the field to use as default where no field prefix is given in the query string. +// It is an alias to the DF func. +func (s *DeleteByQueryService) DefaultField(defaultField string) *DeleteByQueryService { + s.df = defaultField + return s +} + +// DocvalueFields specifies the list of fields to return as the docvalue representation of a field for each hit. +func (s *DeleteByQueryService) DocvalueFields(docvalueFields ...string) *DeleteByQueryService { + s.docvalueFields = docvalueFields + return s +} + +// ExpandWildcards indicates whether to expand wildcard expression to +// concrete indices that are open, closed or both. It can be "open" or "closed". +func (s *DeleteByQueryService) ExpandWildcards(expand string) *DeleteByQueryService { + s.expandWildcards = expand + return s +} + +// Explain specifies whether to return detailed information about score +// computation as part of a hit. +func (s *DeleteByQueryService) Explain(explain bool) *DeleteByQueryService { + s.explain = &explain + return s +} + +// From is the starting offset (default: 0). +func (s *DeleteByQueryService) From(from int) *DeleteByQueryService { + s.from = &from + return s +} + +// IgnoreUnavailable indicates whether specified concrete indices should be +// ignored when unavailable (missing or closed). +func (s *DeleteByQueryService) IgnoreUnavailable(ignore bool) *DeleteByQueryService { + s.ignoreUnavailable = &ignore + return s +} + +// Lenient specifies whether format-based query failures +// (such as providing text to a numeric field) should be ignored. +func (s *DeleteByQueryService) Lenient(lenient bool) *DeleteByQueryService { + s.lenient = &lenient + return s +} + +// LowercaseExpandedTerms specifies whether query terms should be lowercased. +func (s *DeleteByQueryService) LowercaseExpandedTerms(lowercaseExpandedTerms bool) *DeleteByQueryService { + s.lowercaseExpandedTerms = &lowercaseExpandedTerms + return s +} + +// Preference specifies the node or shard the operation should be performed on +// (default: random). +func (s *DeleteByQueryService) Preference(preference string) *DeleteByQueryService { + s.preference = preference + return s +} + +// Q specifies the query in Lucene query string syntax. You can also use +// Query to programmatically specify the query. +func (s *DeleteByQueryService) Q(query string) *DeleteByQueryService { + s.q = query + return s +} + +// QueryString is an alias to Q. Notice that you can also use Query to +// programmatically set the query. +func (s *DeleteByQueryService) QueryString(query string) *DeleteByQueryService { + s.q = query + return s +} + +// Query sets the query programmatically. +func (s *DeleteByQueryService) Query(query Query) *DeleteByQueryService { + s.query = query + return s +} + +// Refresh indicates whether the effected indexes should be refreshed. +func (s *DeleteByQueryService) Refresh(refresh string) *DeleteByQueryService { + s.refresh = refresh + return s +} + +// RequestCache specifies if request cache should be used for this request +// or not, defaults to index level setting. +func (s *DeleteByQueryService) RequestCache(requestCache bool) *DeleteByQueryService { + s.requestCache = &requestCache + return s +} + +// RequestsPerSecond sets the throttle on this request in sub-requests per second. +// -1 means set no throttle as does "unlimited" which is the only non-float this accepts. +func (s *DeleteByQueryService) RequestsPerSecond(requestsPerSecond int) *DeleteByQueryService { + s.requestsPerSecond = &requestsPerSecond + return s +} + +// Routing is a list of specific routing values. +func (s *DeleteByQueryService) Routing(routing ...string) *DeleteByQueryService { + s.routing = append(s.routing, routing...) + return s +} + +// Scroll specifies how long a consistent view of the index should be maintained +// for scrolled search. +func (s *DeleteByQueryService) Scroll(scroll string) *DeleteByQueryService { + s.scroll = scroll + return s +} + +// ScrollSize is the size on the scroll request powering the update_by_query. +func (s *DeleteByQueryService) ScrollSize(scrollSize int) *DeleteByQueryService { + s.scrollSize = &scrollSize + return s +} + +// SearchTimeout defines an explicit timeout for each search request. +// Defaults to no timeout. +func (s *DeleteByQueryService) SearchTimeout(searchTimeout string) *DeleteByQueryService { + s.searchTimeout = searchTimeout + return s +} + +// SearchType is the search operation type. Possible values are +// "query_then_fetch" and "dfs_query_then_fetch". +func (s *DeleteByQueryService) SearchType(searchType string) *DeleteByQueryService { + s.searchType = searchType + return s +} + +// Size represents the number of hits to return (default: 10). +func (s *DeleteByQueryService) Size(size int) *DeleteByQueryService { + s.size = &size + return s +} + +// Sort is a list of : pairs. +func (s *DeleteByQueryService) Sort(sort ...string) *DeleteByQueryService { + s.sort = append(s.sort, sort...) + return s +} + +// SortByField adds a sort order. +func (s *DeleteByQueryService) SortByField(field string, ascending bool) *DeleteByQueryService { + if ascending { + s.sort = append(s.sort, fmt.Sprintf("%s:asc", field)) + } else { + s.sort = append(s.sort, fmt.Sprintf("%s:desc", field)) + } + return s +} + +// Stats specifies specific tag(s) of the request for logging and statistical purposes. +func (s *DeleteByQueryService) Stats(stats ...string) *DeleteByQueryService { + s.stats = append(s.stats, stats...) + return s +} + +// StoredFields specifies the list of stored fields to return as part of a hit. +func (s *DeleteByQueryService) StoredFields(storedFields ...string) *DeleteByQueryService { + s.storedFields = storedFields + return s +} + +// SuggestField specifies which field to use for suggestions. +func (s *DeleteByQueryService) SuggestField(suggestField string) *DeleteByQueryService { + s.suggestField = suggestField + return s +} + +// SuggestMode specifies the suggest mode. Possible values are +// "missing", "popular", and "always". +func (s *DeleteByQueryService) SuggestMode(suggestMode string) *DeleteByQueryService { + s.suggestMode = suggestMode + return s +} + +// SuggestSize specifies how many suggestions to return in response. +func (s *DeleteByQueryService) SuggestSize(suggestSize int) *DeleteByQueryService { + s.suggestSize = &suggestSize + return s +} + +// SuggestText specifies the source text for which the suggestions should be returned. +func (s *DeleteByQueryService) SuggestText(suggestText string) *DeleteByQueryService { + s.suggestText = suggestText + return s +} + +// TerminateAfter indicates the maximum number of documents to collect +// for each shard, upon reaching which the query execution will terminate early. +func (s *DeleteByQueryService) TerminateAfter(terminateAfter int) *DeleteByQueryService { + s.terminateAfter = &terminateAfter + return s +} + +// Timeout is the time each individual bulk request should wait for shards +// that are unavailable. +func (s *DeleteByQueryService) Timeout(timeout string) *DeleteByQueryService { + s.timeout = timeout + return s +} + +// TimeoutInMillis sets the timeout in milliseconds. +func (s *DeleteByQueryService) TimeoutInMillis(timeoutInMillis int) *DeleteByQueryService { + s.timeout = fmt.Sprintf("%dms", timeoutInMillis) + return s +} + +// TrackScores indicates whether to calculate and return scores even if +// they are not used for sorting. +func (s *DeleteByQueryService) TrackScores(trackScores bool) *DeleteByQueryService { + s.trackScores = &trackScores + return s +} + +// Version specifies whether to return document version as part of a hit. +func (s *DeleteByQueryService) Version(version bool) *DeleteByQueryService { + s.version = &version + return s +} + +// WaitForActiveShards sets the number of shard copies that must be active before proceeding +// with the update by query operation. Defaults to 1, meaning the primary shard only. +// Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal +// to the total number of copies for the shard (number of replicas + 1). +func (s *DeleteByQueryService) WaitForActiveShards(waitForActiveShards string) *DeleteByQueryService { + s.waitForActiveShards = waitForActiveShards + return s +} + +// WaitForCompletion indicates if the request should block until the reindex is complete. +func (s *DeleteByQueryService) WaitForCompletion(waitForCompletion bool) *DeleteByQueryService { + s.waitForCompletion = &waitForCompletion + return s +} + +// Pretty indents the JSON output from Elasticsearch. +func (s *DeleteByQueryService) Pretty(pretty bool) *DeleteByQueryService { + s.pretty = pretty + return s +} + +// Body specifies the body of the request. It overrides data being specified via SearchService. +func (s *DeleteByQueryService) Body(body string) *DeleteByQueryService { + s.body = body + return s +} + +// buildURL builds the URL for the operation. +func (s *DeleteByQueryService) buildURL() (string, url.Values, error) { + // Build URL + var err error + var path string + if len(s.typ) > 0 { + path, err = uritemplates.Expand("/{index}/{type}/_delete_by_query", map[string]string{ + "index": strings.Join(s.index, ","), + "type": strings.Join(s.typ, ","), + }) + } else { + path, err = uritemplates.Expand("/{index}/_delete_by_query", map[string]string{ + "index": strings.Join(s.index, ","), + }) + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if len(s.xSource) > 0 { + params.Set("_source", strings.Join(s.xSource, ",")) + } + if len(s.xSourceExclude) > 0 { + params.Set("_source_exclude", strings.Join(s.xSourceExclude, ",")) + } + if len(s.xSourceInclude) > 0 { + params.Set("_source_include", strings.Join(s.xSourceInclude, ",")) + } + if s.analyzer != "" { + params.Set("analyzer", s.analyzer) + } + if s.analyzeWildcard != nil { + params.Set("analyze_wildcard", fmt.Sprintf("%v", *s.analyzeWildcard)) + } + if s.defaultOperator != "" { + params.Set("default_operator", s.defaultOperator) + } + if s.df != "" { + params.Set("df", s.df) + } + if s.explain != nil { + params.Set("explain", fmt.Sprintf("%v", *s.explain)) + } + if len(s.storedFields) > 0 { + params.Set("stored_fields", strings.Join(s.storedFields, ",")) + } + if len(s.docvalueFields) > 0 { + params.Set("docvalue_fields", strings.Join(s.docvalueFields, ",")) + } + if s.from != nil { + params.Set("from", fmt.Sprintf("%d", *s.from)) + } + if s.ignoreUnavailable != nil { + params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) + } + if s.allowNoIndices != nil { + params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) + } + if s.conflicts != "" { + params.Set("conflicts", s.conflicts) + } + if s.expandWildcards != "" { + params.Set("expand_wildcards", s.expandWildcards) + } + if s.lenient != nil { + params.Set("lenient", fmt.Sprintf("%v", *s.lenient)) + } + if s.lowercaseExpandedTerms != nil { + params.Set("lowercase_expanded_terms", fmt.Sprintf("%v", *s.lowercaseExpandedTerms)) + } + if s.preference != "" { + params.Set("preference", s.preference) + } + if s.q != "" { + params.Set("q", s.q) + } + if len(s.routing) > 0 { + params.Set("routing", strings.Join(s.routing, ",")) + } + if s.scroll != "" { + params.Set("scroll", s.scroll) + } + if s.searchType != "" { + params.Set("search_type", s.searchType) + } + if s.searchTimeout != "" { + params.Set("search_timeout", s.searchTimeout) + } + if s.size != nil { + params.Set("size", fmt.Sprintf("%d", *s.size)) + } + if len(s.sort) > 0 { + params.Set("sort", strings.Join(s.sort, ",")) + } + if s.terminateAfter != nil { + params.Set("terminate_after", fmt.Sprintf("%v", *s.terminateAfter)) + } + if len(s.stats) > 0 { + params.Set("stats", strings.Join(s.stats, ",")) + } + if s.suggestField != "" { + params.Set("suggest_field", s.suggestField) + } + if s.suggestMode != "" { + params.Set("suggest_mode", s.suggestMode) + } + if s.suggestSize != nil { + params.Set("suggest_size", fmt.Sprintf("%v", *s.suggestSize)) + } + if s.suggestText != "" { + params.Set("suggest_text", s.suggestText) + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + if s.trackScores != nil { + params.Set("track_scores", fmt.Sprintf("%v", *s.trackScores)) + } + if s.version != nil { + params.Set("version", fmt.Sprintf("%v", *s.version)) + } + if s.requestCache != nil { + params.Set("request_cache", fmt.Sprintf("%v", *s.requestCache)) + } + if s.refresh != "" { + params.Set("refresh", s.refresh) + } + if s.waitForActiveShards != "" { + params.Set("wait_for_active_shards", s.waitForActiveShards) + } + if s.scrollSize != nil { + params.Set("scroll_size", fmt.Sprintf("%d", *s.scrollSize)) + } + if s.waitForCompletion != nil { + params.Set("wait_for_completion", fmt.Sprintf("%v", *s.waitForCompletion)) + } + if s.requestsPerSecond != nil { + params.Set("requests_per_second", fmt.Sprintf("%v", *s.requestsPerSecond)) + } + if s.pretty { + params.Set("pretty", fmt.Sprintf("%v", s.pretty)) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *DeleteByQueryService) Validate() error { + var invalid []string + if len(s.index) == 0 { + invalid = append(invalid, "Index") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the delete-by-query operation. +func (s *DeleteByQueryService) Do(ctx context.Context) (*BulkIndexByScrollResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Set body if there is a query set + var body interface{} + if s.body != nil { + body = s.body + } else if s.query != nil { + src, err := s.query.Source() + if err != nil { + return nil, err + } + body = map[string]interface{}{ + "query": src, + } + } + + // Get response + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + if err != nil { + return nil, err + } + + // Return result + ret := new(BulkIndexByScrollResponse) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// BulkIndexByScrollResponse is the outcome of executing Do with +// DeleteByQueryService and UpdateByQueryService. +type BulkIndexByScrollResponse struct { + Took int64 `json:"took"` + TimedOut bool `json:"timed_out"` + Total int64 `json:"total"` + Updated int64 `json:"updated"` + Created int64 `json:"created"` + Deleted int64 `json:"deleted"` + Batches int64 `json:"batches"` + VersionConflicts int64 `json:"version_conflicts"` + Noops int64 `json:"noops"` + Retries struct { + Bulk int64 `json:"bulk"` + Search int64 `json:"search"` + } `json:"retries"` + Throttled string `json:"throttled"` + ThrottledMillis int64 `json:"throttled_millis"` + RequestsPerSecond float64 `json:"requests_per_second"` + Canceled string `json:"canceled"` + ThrottledUntil string `json:"throttled_until"` + ThrottledUntilMillis int64 `json:"throttled_until_millis"` + Failures []bulkIndexByScrollResponseFailure `json:"failures"` +} + +type bulkIndexByScrollResponseFailure struct { + Index string `json:"index,omitempty"` + Type string `json:"type,omitempty"` + Id string `json:"id,omitempty"` + Status int `json:"status,omitempty"` + Shard int `json:"shard,omitempty"` + Node int `json:"node,omitempty"` + // TOOD "cause" contains exception details + // TOOD "reason" contains exception details +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/delete_template.go b/vendor/gopkg.in/olivere/elastic.v5/delete_template.go similarity index 77% rename from vendor/gopkg.in/olivere/elastic.v3/delete_template.go rename to vendor/gopkg.in/olivere/elastic.v5/delete_template.go index 971637f59..87c2312bf 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/delete_template.go +++ b/vendor/gopkg.in/olivere/elastic.v5/delete_template.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,11 +8,13 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // DeleteTemplateService deletes a search template. More information can -// be found at http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html. +// be found at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html. type DeleteTemplateService struct { client *Client pretty bool @@ -81,7 +83,7 @@ func (s *DeleteTemplateService) Validate() error { } // Do executes the operation. -func (s *DeleteTemplateService) Do() (*DeleteTemplateResponse, error) { +func (s *DeleteTemplateService) Do(ctx context.Context) (*AcknowledgedResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -94,24 +96,15 @@ func (s *DeleteTemplateService) Do() (*DeleteTemplateResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("DELETE", path, params, nil) + res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil) if err != nil { return nil, err } // Return operation response - ret := new(DeleteTemplateResponse) + ret := new(AcknowledgedResponse) if err := s.client.decoder.Decode(res.Body, ret); err != nil { return nil, err } return ret, nil } - -// DeleteTemplateResponse is the response of DeleteTemplateService.Do. -type DeleteTemplateResponse struct { - Found bool `json:"found"` - Index string `json:"_index"` - Type string `json:"_type"` - Id string `json:"_id"` - Version int `json:"_version"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/doc.go b/vendor/gopkg.in/olivere/elastic.v5/doc.go similarity index 89% rename from vendor/gopkg.in/olivere/elastic.v3/doc.go rename to vendor/gopkg.in/olivere/elastic.v5/doc.go index 336a734de..ea16d6698 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/doc.go +++ b/vendor/gopkg.in/olivere/elastic.v5/doc.go @@ -1,10 +1,10 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. /* Package elastic provides an interface to the Elasticsearch server -(http://www.elasticsearch.org/). +(https://www.elastic.co/products/elasticsearch). The first thing you do is to create a Client. If you have Elasticsearch installed and running with its default settings @@ -35,7 +35,7 @@ methods to prepare the query and a Do function to execute it against the Elasticsearch REST interface and return a response. Here is an example of the IndexExists service that checks if a given index already exists. - exists, err := client.IndexExists("twitter").Do() + exists, err := client.IndexExists("twitter").Do(context.Background()) if err != nil { // Handle error } diff --git a/vendor/gopkg.in/olivere/elastic.v3/errors.go b/vendor/gopkg.in/olivere/elastic.v5/errors.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v3/errors.go rename to vendor/gopkg.in/olivere/elastic.v5/errors.go index 93c2c6de5..009123531 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/errors.go +++ b/vendor/gopkg.in/olivere/elastic.v5/errors.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/exists.go b/vendor/gopkg.in/olivere/elastic.v5/exists.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v3/exists.go rename to vendor/gopkg.in/olivere/elastic.v5/exists.go index 7a42d53c9..f9e9a1679 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/exists.go +++ b/vendor/gopkg.in/olivere/elastic.v5/exists.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,12 +9,14 @@ import ( "net/http" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // ExistsService checks for the existence of a document using HEAD. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-get.html // for details. type ExistsService struct { client *Client @@ -24,7 +26,7 @@ type ExistsService struct { typ string preference string realtime *bool - refresh *bool + refresh string routing string parent string } @@ -68,8 +70,8 @@ func (s *ExistsService) Realtime(realtime bool) *ExistsService { } // Refresh the shard containing the document before performing the operation. -func (s *ExistsService) Refresh(refresh bool) *ExistsService { - s.refresh = &refresh +func (s *ExistsService) Refresh(refresh string) *ExistsService { + s.refresh = refresh return s } @@ -111,8 +113,8 @@ func (s *ExistsService) buildURL() (string, url.Values, error) { if s.realtime != nil { params.Set("realtime", fmt.Sprintf("%v", *s.realtime)) } - if s.refresh != nil { - params.Set("refresh", fmt.Sprintf("%v", *s.refresh)) + if s.refresh != "" { + params.Set("refresh", s.refresh) } if s.routing != "" { params.Set("routing", s.routing) @@ -145,7 +147,7 @@ func (s *ExistsService) Validate() error { } // Do executes the operation. -func (s *ExistsService) Do() (bool, error) { +func (s *ExistsService) Do(ctx context.Context) (bool, error) { // Check pre-conditions if err := s.Validate(); err != nil { return false, err @@ -158,7 +160,7 @@ func (s *ExistsService) Do() (bool, error) { } // Get HTTP response - res, err := s.client.PerformRequest("HEAD", path, params, nil, 404) + res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404) if err != nil { return false, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/explain.go b/vendor/gopkg.in/olivere/elastic.v5/explain.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v3/explain.go rename to vendor/gopkg.in/olivere/elastic.v5/explain.go index 617e8462e..72e60a9d7 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/explain.go +++ b/vendor/gopkg.in/olivere/elastic.v5/explain.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -6,24 +6,17 @@ package elastic import ( "fmt" - "log" "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" -) + "golang.org/x/net/context" -var ( - _ = fmt.Print - _ = log.Print - _ = strings.Index - _ = uritemplates.Expand - _ = url.Parse + "gopkg.in/olivere/elastic.v5/uritemplates" ) // ExplainService computes a score explanation for a query and // a specific document. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-explain.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-explain.html. type ExplainService struct { client *Client pretty bool @@ -285,7 +278,7 @@ func (s *ExplainService) Validate() error { } // Do executes the operation. -func (s *ExplainService) Do() (*ExplainResponse, error) { +func (s *ExplainService) Do(ctx context.Context) (*ExplainResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -306,7 +299,7 @@ func (s *ExplainService) Do() (*ExplainResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, body) + res, err := s.client.PerformRequest(ctx, "GET", path, params, body) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/fetch_source_context.go b/vendor/gopkg.in/olivere/elastic.v5/fetch_source_context.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v3/fetch_source_context.go rename to vendor/gopkg.in/olivere/elastic.v5/fetch_source_context.go index e13c9eb47..59a453c9e 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/fetch_source_context.go +++ b/vendor/gopkg.in/olivere/elastic.v5/fetch_source_context.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/field_stats.go b/vendor/gopkg.in/olivere/elastic.v5/field_stats.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v3/field_stats.go rename to vendor/gopkg.in/olivere/elastic.v5/field_stats.go index fc8d084cd..303122edc 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/field_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v5/field_stats.go @@ -10,7 +10,9 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) const ( @@ -21,7 +23,7 @@ const ( // FieldStatsService allows finding statistical properties of a field without executing a search, // but looking up measurements that are natively available in the Lucene index. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-stats.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-field-stats.html // for details type FieldStatsService struct { client *Client @@ -166,7 +168,7 @@ func (s *FieldStatsService) Validate() error { } // Do executes the operation. -func (s *FieldStatsService) Do() (*FieldStatsResponse, error) { +func (s *FieldStatsService) Do(ctx context.Context) (*FieldStatsResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -187,7 +189,7 @@ func (s *FieldStatsService) Do() (*FieldStatsResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("POST", path, params, body, http.StatusNotFound) + res, err := s.client.PerformRequest(ctx, "POST", path, params, body, http.StatusNotFound) if err != nil { return nil, err } @@ -243,11 +245,14 @@ type IndexFieldStats struct { // FieldStats contains stats of an individual field type FieldStats struct { + Type string `json:"type"` MaxDoc int64 `json:"max_doc"` DocCount int64 `json:"doc_count"` Density int64 `json:"density"` SumDocFrequeny int64 `json:"sum_doc_freq"` SumTotalTermFrequency int64 `json:"sum_total_term_freq"` + Searchable bool `json:"searchable"` + Aggregatable bool `json:"aggregatable"` MinValue interface{} `json:"min_value"` MinValueAsString string `json:"min_value_as_string"` MaxValue interface{} `json:"max_value"` diff --git a/vendor/gopkg.in/olivere/elastic.v3/geo_point.go b/vendor/gopkg.in/olivere/elastic.v5/geo_point.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v3/geo_point.go rename to vendor/gopkg.in/olivere/elastic.v5/geo_point.go index a09351ca2..fb243671d 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/geo_point.go +++ b/vendor/gopkg.in/olivere/elastic.v5/geo_point.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/get.go b/vendor/gopkg.in/olivere/elastic.v5/get.go similarity index 73% rename from vendor/gopkg.in/olivere/elastic.v3/get.go rename to vendor/gopkg.in/olivere/elastic.v5/get.go index 4e255ada6..6d45aa575 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/get.go +++ b/vendor/gopkg.in/olivere/elastic.v5/get.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,13 +10,15 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // GetService allows to get a typed JSON document from the index based // on its id. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-get.html // for details. type GetService struct { client *Client @@ -26,8 +28,8 @@ type GetService struct { id string routing string preference string - fields []string - refresh *bool + storedFields []string + refresh string realtime *bool fsc *FetchSourceContext version interface{} @@ -44,17 +46,6 @@ func NewGetService(client *Client) *GetService { } } -/* -// String returns a string representation of the GetService request. -func (s *GetService) String() string { - return fmt.Sprintf("[%v][%v][%v]: routing [%v]", - s.index, - s.typ, - s.id, - s.routing) -} -*/ - // Index is the name of the index. func (s *GetService) Index(index string) *GetService { s.index = index @@ -92,12 +83,9 @@ func (s *GetService) Preference(preference string) *GetService { return s } -// Fields is a list of fields to return in the response. -func (s *GetService) Fields(fields ...string) *GetService { - if s.fields == nil { - s.fields = make([]string, 0) - } - s.fields = append(s.fields, fields...) +// StoredFields is a list of fields to return in the response. +func (s *GetService) StoredFields(storedFields ...string) *GetService { + s.storedFields = append(s.storedFields, storedFields...) return s } @@ -116,8 +104,8 @@ func (s *GetService) FetchSourceContext(fetchSourceContext *FetchSourceContext) } // Refresh the shard containing the document before performing the operation. -func (s *GetService) Refresh(refresh bool) *GetService { - s.refresh = &refresh +func (s *GetService) Refresh(refresh string) *GetService { + s.refresh = refresh return s } @@ -196,11 +184,11 @@ func (s *GetService) buildURL() (string, url.Values, error) { if s.preference != "" { params.Set("preference", s.preference) } - if len(s.fields) > 0 { - params.Set("fields", strings.Join(s.fields, ",")) + if len(s.storedFields) > 0 { + params.Set("stored_fields", strings.Join(s.storedFields, ",")) } - if s.refresh != nil { - params.Set("refresh", fmt.Sprintf("%v", *s.refresh)) + if s.refresh != "" { + params.Set("refresh", s.refresh) } if s.version != nil { params.Set("version", fmt.Sprintf("%v", s.version)) @@ -223,7 +211,7 @@ func (s *GetService) buildURL() (string, url.Values, error) { } // Do executes the operation. -func (s *GetService) Do() (*GetResult, error) { +func (s *GetService) Do(ctx context.Context) (*GetResult, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -236,7 +224,7 @@ func (s *GetService) Do() (*GetResult, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } @@ -253,18 +241,16 @@ func (s *GetService) Do() (*GetResult, error) { // GetResult is the outcome of GetService.Do. type GetResult struct { - Index string `json:"_index"` // index meta field - Type string `json:"_type"` // type meta field - Id string `json:"_id"` // id meta field - Uid string `json:"_uid"` // uid meta field (see MapperService.java for all meta fields) - Timestamp int64 `json:"_timestamp"` // timestamp meta field - TTL int64 `json:"_ttl"` // ttl meta field - Routing string `json:"_routing"` // routing meta field - Parent string `json:"_parent"` // parent meta field - Version *int64 `json:"_version"` // version number, when Version is set to true in SearchService - Source *json.RawMessage `json:"_source,omitempty"` - Found bool `json:"found,omitempty"` - Fields map[string]interface{} `json:"fields,omitempty"` + Index string `json:"_index"` // index meta field + Type string `json:"_type"` // type meta field + Id string `json:"_id"` // id meta field + Uid string `json:"_uid"` // uid meta field (see MapperService.java for all meta fields) + Routing string `json:"_routing"` // routing meta field + Parent string `json:"_parent"` // parent meta field + Version *int64 `json:"_version"` // version number, when Version is set to true in SearchService + Source *json.RawMessage `json:"_source,omitempty"` + Found bool `json:"found,omitempty"` + Fields map[string]interface{} `json:"fields,omitempty"` //Error string `json:"error,omitempty"` // used only in MultiGet // TODO double-check that MultiGet now returns details error information Error *ErrorDetails `json:"error,omitempty"` // only used in MultiGet diff --git a/vendor/gopkg.in/olivere/elastic.v3/get_template.go b/vendor/gopkg.in/olivere/elastic.v5/get_template.go similarity index 85% rename from vendor/gopkg.in/olivere/elastic.v3/get_template.go rename to vendor/gopkg.in/olivere/elastic.v5/get_template.go index e5c11f029..96dfad240 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/get_template.go +++ b/vendor/gopkg.in/olivere/elastic.v5/get_template.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,11 +8,13 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // GetTemplateService reads a search template. -// It is documented at http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html. +// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html. type GetTemplateService struct { client *Client pretty bool @@ -81,7 +83,7 @@ func (s *GetTemplateService) Validate() error { } // Do executes the operation and returns the template. -func (s *GetTemplateService) Do() (*GetTemplateResponse, error) { +func (s *GetTemplateService) Do(ctx context.Context) (*GetTemplateResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -94,7 +96,7 @@ func (s *GetTemplateService) Do() (*GetTemplateResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/highlight.go b/vendor/gopkg.in/olivere/elastic.v5/highlight.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/highlight.go rename to vendor/gopkg.in/olivere/elastic.v5/highlight.go index 44501a731..d28f03c3a 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/highlight.go +++ b/vendor/gopkg.in/olivere/elastic.v5/highlight.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -6,7 +6,7 @@ package elastic // Highlight allows highlighting search results on one or more fields. // For details, see: -// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-highlighting.html type Highlight struct { fields []*HighlighterField tagsSchema *string @@ -19,7 +19,7 @@ type Highlight struct { encoder *string requireFieldMatch *bool boundaryMaxScan *int - boundaryChars []rune + boundaryChars *string highlighterType *string fragmenter *string highlightQuery Query @@ -32,11 +32,7 @@ type Highlight struct { func NewHighlight() *Highlight { hl := &Highlight{ - fields: make([]*HighlighterField, 0), - preTags: make([]string, 0), - postTags: make([]string, 0), - boundaryChars: make([]rune, 0), - options: make(map[string]interface{}), + options: make(map[string]interface{}), } return hl } @@ -102,8 +98,8 @@ func (hl *Highlight) BoundaryMaxScan(boundaryMaxScan int) *Highlight { return hl } -func (hl *Highlight) BoundaryChars(boundaryChars ...rune) *Highlight { - hl.boundaryChars = append(hl.boundaryChars, boundaryChars...) +func (hl *Highlight) BoundaryChars(boundaryChars string) *Highlight { + hl.boundaryChars = &boundaryChars return hl } @@ -179,8 +175,8 @@ func (hl *Highlight) Source() (interface{}, error) { if hl.boundaryMaxScan != nil { source["boundary_max_scan"] = *hl.boundaryMaxScan } - if hl.boundaryChars != nil && len(hl.boundaryChars) > 0 { - source["boundary_chars"] = hl.boundaryChars + if hl.boundaryChars != nil { + source["boundary_chars"] = *hl.boundaryChars } if hl.highlighterType != nil { source["type"] = *hl.highlighterType @@ -211,7 +207,7 @@ func (hl *Highlight) Source() (interface{}, error) { if hl.fields != nil && len(hl.fields) > 0 { if hl.useExplicitFieldOrder { // Use a slice for the fields - fields := make([]map[string]interface{}, 0) + var fields []map[string]interface{} for _, field := range hl.fields { src, err := field.Source() if err != nil { diff --git a/vendor/gopkg.in/olivere/elastic.v3/index.go b/vendor/gopkg.in/olivere/elastic.v5/index.go similarity index 74% rename from vendor/gopkg.in/olivere/elastic.v3/index.go rename to vendor/gopkg.in/olivere/elastic.v5/index.go index f31e7b010..86663c5b1 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/index.go +++ b/vendor/gopkg.in/olivere/elastic.v5/index.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,33 +8,35 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndexService adds or updates a typed JSON document in a specified index, // making it searchable. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html // for details. type IndexService struct { - client *Client - pretty bool - id string - index string - typ string - parent string - replication string - routing string - timeout string - timestamp string - ttl string - version interface{} - opType string - versionType string - refresh *bool - consistency string - bodyJson interface{} - bodyString string + client *Client + pretty bool + id string + index string + typ string + parent string + routing string + timeout string + timestamp string + ttl string + version interface{} + opType string + versionType string + refresh string + waitForActiveShards string + pipeline string + bodyJson interface{} + bodyString string } // NewIndexService creates a new IndexService. @@ -62,15 +64,25 @@ func (s *IndexService) Type(typ string) *IndexService { return s } -// Consistency is an explicit write consistency setting for the operation. -func (s *IndexService) Consistency(consistency string) *IndexService { - s.consistency = consistency +// WaitForActiveShards sets the number of shard copies that must be active +// before proceeding with the index operation. Defaults to 1, meaning the +// primary shard only. Set to `all` for all shard copies, otherwise set to +// any non-negative value less than or equal to the total number of copies +// for the shard (number of replicas + 1). +func (s *IndexService) WaitForActiveShards(waitForActiveShards string) *IndexService { + s.waitForActiveShards = waitForActiveShards + return s +} + +// Pipeline specifies the pipeline id to preprocess incoming documents with. +func (s *IndexService) Pipeline(pipeline string) *IndexService { + s.pipeline = pipeline return s } // Refresh the index after performing the operation. -func (s *IndexService) Refresh(refresh bool) *IndexService { - s.refresh = &refresh +func (s *IndexService) Refresh(refresh string) *IndexService { + s.refresh = refresh return s } @@ -104,12 +116,6 @@ func (s *IndexService) Parent(parent string) *IndexService { return s } -// Replication is a specific replication type. -func (s *IndexService) Replication(replication string) *IndexService { - s.replication = replication - return s -} - // Routing is a specific routing value. func (s *IndexService) Routing(routing string) *IndexService { s.routing = routing @@ -167,7 +173,7 @@ func (s *IndexService) buildURL() (string, string, url.Values, error) { }) } else { // Automatic ID generation - // See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#index-creation + // See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html#index-creation method = "POST" path, err = uritemplates.Expand("/{index}/{type}/", map[string]string{ "index": s.index, @@ -183,11 +189,11 @@ func (s *IndexService) buildURL() (string, string, url.Values, error) { if s.pretty { params.Set("pretty", "1") } - if s.consistency != "" { - params.Set("consistency", s.consistency) + if s.waitForActiveShards != "" { + params.Set("wait_for_active_shards", s.waitForActiveShards) } - if s.refresh != nil { - params.Set("refresh", fmt.Sprintf("%v", *s.refresh)) + if s.refresh != "" { + params.Set("refresh", s.refresh) } if s.opType != "" { params.Set("op_type", s.opType) @@ -195,8 +201,8 @@ func (s *IndexService) buildURL() (string, string, url.Values, error) { if s.parent != "" { params.Set("parent", s.parent) } - if s.replication != "" { - params.Set("replication", s.replication) + if s.pipeline != "" { + params.Set("pipeline", s.pipeline) } if s.routing != "" { params.Set("routing", s.routing) @@ -238,7 +244,7 @@ func (s *IndexService) Validate() error { } // Do executes the operation. -func (s *IndexService) Do() (*IndexResponse, error) { +func (s *IndexService) Do(ctx context.Context) (*IndexResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -259,7 +265,7 @@ func (s *IndexService) Do() (*IndexResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest(method, path, params, body) + res, err := s.client.PerformRequest(ctx, method, path, params, body) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_analyze.go b/vendor/gopkg.in/olivere/elastic.v5/indices_analyze.go new file mode 100644 index 000000000..8caea7718 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_analyze.go @@ -0,0 +1,280 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "fmt" + "net/url" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// IndicesAnalyzeService performs the analysis process on a text and returns +// the tokens breakdown of the text. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-analyze.html +// for detail. +type IndicesAnalyzeService struct { + client *Client + pretty bool + index string + request *IndicesAnalyzeRequest + format string + preferLocal *bool + bodyJson interface{} + bodyString string +} + +// NewIndicesAnalyzeService creates a new IndicesAnalyzeService. +func NewIndicesAnalyzeService(client *Client) *IndicesAnalyzeService { + return &IndicesAnalyzeService{ + client: client, + request: new(IndicesAnalyzeRequest), + } +} + +// Index is the name of the index to scope the operation. +func (s *IndicesAnalyzeService) Index(index string) *IndicesAnalyzeService { + s.index = index + return s +} + +// Format of the output. +func (s *IndicesAnalyzeService) Format(format string) *IndicesAnalyzeService { + s.format = format + return s +} + +// PreferLocal, when true, specifies that a local shard should be used +// if available. When false, a random shard is used (default: true). +func (s *IndicesAnalyzeService) PreferLocal(preferLocal bool) *IndicesAnalyzeService { + s.preferLocal = &preferLocal + return s +} + +// Request passes the analyze request to use. +func (s *IndicesAnalyzeService) Request(request *IndicesAnalyzeRequest) *IndicesAnalyzeService { + if request == nil { + s.request = new(IndicesAnalyzeRequest) + } else { + s.request = request + } + return s +} + +// Analyzer is the name of the analyzer to use. +func (s *IndicesAnalyzeService) Analyzer(analyzer string) *IndicesAnalyzeService { + s.request.Analyzer = analyzer + return s +} + +// Attributes is a list of token attributes to output; this parameter works +// only with explain=true. +func (s *IndicesAnalyzeService) Attributes(attributes ...string) *IndicesAnalyzeService { + s.request.Attributes = attributes + return s +} + +// CharFilter is a list of character filters to use for the analysis. +func (s *IndicesAnalyzeService) CharFilter(charFilter ...string) *IndicesAnalyzeService { + s.request.CharFilter = charFilter + return s +} + +// Explain, when true, outputs more advanced details (default: false). +func (s *IndicesAnalyzeService) Explain(explain bool) *IndicesAnalyzeService { + s.request.Explain = explain + return s +} + +// Field specifies to use a specific analyzer configured for this field (instead of passing the analyzer name). +func (s *IndicesAnalyzeService) Field(field string) *IndicesAnalyzeService { + s.request.Field = field + return s +} + +// Filter is a list of filters to use for the analysis. +func (s *IndicesAnalyzeService) Filter(filter ...string) *IndicesAnalyzeService { + s.request.Filter = filter + return s +} + +// Text is the text on which the analysis should be performed (when request body is not used). +func (s *IndicesAnalyzeService) Text(text ...string) *IndicesAnalyzeService { + s.request.Text = text + return s +} + +// Tokenizer is the name of the tokenizer to use for the analysis. +func (s *IndicesAnalyzeService) Tokenizer(tokenizer string) *IndicesAnalyzeService { + s.request.Tokenizer = tokenizer + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *IndicesAnalyzeService) Pretty(pretty bool) *IndicesAnalyzeService { + s.pretty = pretty + return s +} + +// BodyJson is the text on which the analysis should be performed. +func (s *IndicesAnalyzeService) BodyJson(body interface{}) *IndicesAnalyzeService { + s.bodyJson = body + return s +} + +// BodyString is the text on which the analysis should be performed. +func (s *IndicesAnalyzeService) BodyString(body string) *IndicesAnalyzeService { + s.bodyString = body + return s +} + +// buildURL builds the URL for the operation. +func (s *IndicesAnalyzeService) buildURL() (string, url.Values, error) { + // Build URL + var err error + var path string + + if s.index == "" { + path = "/_analyze" + } else { + path, err = uritemplates.Expand("/{index}/_analyze", map[string]string{ + "index": s.index, + }) + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + if s.format != "" { + params.Set("format", s.format) + } + if s.preferLocal != nil { + params.Set("prefer_local", fmt.Sprintf("%v", *s.preferLocal)) + } + + return path, params, nil +} + +// Do will execute the request with the given context. +func (s *IndicesAnalyzeService) Do(ctx context.Context) (*IndicesAnalyzeResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Setup HTTP request body + var body interface{} + if s.bodyJson != nil { + body = s.bodyJson + } else if s.bodyString != "" { + body = s.bodyString + } else { + // Request parameters are deprecated in 5.1.1, and we must use a JSON + // structure in the body to pass the parameters. + // See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-analyze.html + body = s.request + } + + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + if err != nil { + return nil, err + } + + ret := new(IndicesAnalyzeResponse) + if err = s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + + return ret, nil +} + +func (s *IndicesAnalyzeService) Validate() error { + var invalid []string + if s.bodyJson == nil && s.bodyString == "" { + if len(s.request.Text) == 0 { + invalid = append(invalid, "Text") + } + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// IndicesAnalyzeRequest specifies the parameters of the analyze request. +type IndicesAnalyzeRequest struct { + Text []string `json:"text,omitempty"` + Analyzer string `json:"analyzer,omitempty"` + Tokenizer string `json:"tokenizer,omitempty"` + Filter []string `json:"filter,omitempty"` + CharFilter []string `json:"char_filter,omitempty"` + Field string `json:"field,omitempty"` + Explain bool `json:"explain,omitempty"` + Attributes []string `json:"attributes,omitempty"` +} + +type IndicesAnalyzeResponse struct { + Tokens []IndicesAnalyzeResponseToken `json:"tokens"` // json part for normal message + Detail IndicesAnalyzeResponseDetail `json:"detail"` // json part for verbose message of explain request +} + +type IndicesAnalyzeResponseToken struct { + Token string `json:"token"` + StartOffset int `json:"start_offset"` + EndOffset int `json:"end_offset"` + Type string `json:"type"` + Position int `json:"position"` +} + +type IndicesAnalyzeResponseDetail struct { + CustomAnalyzer bool `json:"custom_analyzer"` + Charfilters []interface{} `json:"charfilters"` + Analyzer struct { + Name string `json:"name"` + Tokens []struct { + Token string `json:"token"` + StartOffset int `json:"start_offset"` + EndOffset int `json:"end_offset"` + Type string `json:"type"` + Position int `json:"position"` + Bytes string `json:"bytes"` + PositionLength int `json:"positionLength"` + } `json:"tokens"` + } `json:"analyzer"` + Tokenizer struct { + Name string `json:"name"` + Tokens []struct { + Token string `json:"token"` + StartOffset int `json:"start_offset"` + EndOffset int `json:"end_offset"` + Type string `json:"type"` + Position int `json:"position"` + } `json:"tokens"` + } `json:"tokenizer"` + Tokenfilters []struct { + Name string `json:"name"` + Tokens []struct { + Token string `json:"token"` + StartOffset int `json:"start_offset"` + EndOffset int `json:"end_offset"` + Type string `json:"type"` + Position int `json:"position"` + Keyword bool `json:"keyword"` + } `json:"tokens"` + } `json:"tokenfilters"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_close.go b/vendor/gopkg.in/olivere/elastic.v5/indices_close.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/indices_close.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_close.go index e515c7e0e..35399418b 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_close.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_close.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,12 +8,14 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesCloseService closes an index. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-open-close.html // for details. type IndicesCloseService struct { client *Client @@ -120,7 +122,7 @@ func (s *IndicesCloseService) Validate() error { } // Do executes the operation. -func (s *IndicesCloseService) Do() (*IndicesCloseResponse, error) { +func (s *IndicesCloseService) Do(ctx context.Context) (*IndicesCloseResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -133,7 +135,7 @@ func (s *IndicesCloseService) Do() (*IndicesCloseResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_create.go b/vendor/gopkg.in/olivere/elastic.v5/indices_create.go similarity index 85% rename from vendor/gopkg.in/olivere/elastic.v3/indices_create.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_create.go index 80ff33b02..43fe776ef 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_create.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_create.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,12 +8,14 @@ import ( "errors" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesCreateService creates a new index. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-create-index.html // for details. type IndicesCreateService struct { client *Client @@ -75,7 +77,7 @@ func (b *IndicesCreateService) Pretty(pretty bool) *IndicesCreateService { } // Do executes the operation. -func (b *IndicesCreateService) Do() (*IndicesCreateResult, error) { +func (b *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, error) { if b.index == "" { return nil, errors.New("missing index name") } @@ -108,7 +110,7 @@ func (b *IndicesCreateService) Do() (*IndicesCreateResult, error) { } // Get response - res, err := b.client.PerformRequest("PUT", path, params, body) + res, err := b.client.PerformRequest(ctx, "PUT", path, params, body) if err != nil { return nil, err } @@ -124,5 +126,6 @@ func (b *IndicesCreateService) Do() (*IndicesCreateResult, error) { // IndicesCreateResult is the outcome of creating a new index. type IndicesCreateResult struct { - Acknowledged bool `json:"acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_delete.go b/vendor/gopkg.in/olivere/elastic.v5/indices_delete.go similarity index 88% rename from vendor/gopkg.in/olivere/elastic.v3/indices_delete.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_delete.go index e93f1fb81..c5d7d351c 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_delete.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_delete.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,12 +9,14 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesDeleteService allows to delete existing indices. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-delete-index.html // for details. type IndicesDeleteService struct { client *Client @@ -94,7 +96,7 @@ func (s *IndicesDeleteService) Validate() error { } // Do executes the operation. -func (s *IndicesDeleteService) Do() (*IndicesDeleteResponse, error) { +func (s *IndicesDeleteService) Do(ctx context.Context) (*IndicesDeleteResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -107,7 +109,7 @@ func (s *IndicesDeleteService) Do() (*IndicesDeleteResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("DELETE", path, params, nil) + res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_delete_template.go b/vendor/gopkg.in/olivere/elastic.v5/indices_delete_template.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v3/indices_delete_template.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_delete_template.go index 76bedf706..7e5ceb546 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_delete_template.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_delete_template.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,11 +8,13 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesDeleteTemplateService deletes index templates. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/indices-templates.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-templates.html. type IndicesDeleteTemplateService struct { client *Client pretty bool @@ -89,7 +91,7 @@ func (s *IndicesDeleteTemplateService) Validate() error { } // Do executes the operation. -func (s *IndicesDeleteTemplateService) Do() (*IndicesDeleteTemplateResponse, error) { +func (s *IndicesDeleteTemplateService) Do(ctx context.Context) (*IndicesDeleteTemplateResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -102,7 +104,7 @@ func (s *IndicesDeleteTemplateService) Do() (*IndicesDeleteTemplateResponse, err } // Get HTTP response - res, err := s.client.PerformRequest("DELETE", path, params, nil) + res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_exists.go b/vendor/gopkg.in/olivere/elastic.v5/indices_exists.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/indices_exists.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_exists.go index 92f9974f2..c1cb8e846 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_exists.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_exists.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,12 +10,14 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesExistsService checks if an index or indices exist or not. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-exists.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-exists.html // for details. type IndicesExistsService struct { client *Client @@ -119,7 +121,7 @@ func (s *IndicesExistsService) Validate() error { } // Do executes the operation. -func (s *IndicesExistsService) Do() (bool, error) { +func (s *IndicesExistsService) Do(ctx context.Context) (bool, error) { // Check pre-conditions if err := s.Validate(); err != nil { return false, err @@ -132,7 +134,7 @@ func (s *IndicesExistsService) Do() (bool, error) { } // Get HTTP response - res, err := s.client.PerformRequest("HEAD", path, params, nil, 404) + res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404) if err != nil { return false, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_exists_template.go b/vendor/gopkg.in/olivere/elastic.v5/indices_exists_template.go similarity index 86% rename from vendor/gopkg.in/olivere/elastic.v3/indices_exists_template.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_exists_template.go index 7587a8786..97008a31d 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_exists_template.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_exists_template.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,11 +9,13 @@ import ( "net/http" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesExistsTemplateService checks if a given template exists. -// See http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#indices-templates-exists +// See http://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-templates.html#indices-templates-exists // for documentation. type IndicesExistsTemplateService struct { client *Client @@ -82,7 +84,7 @@ func (s *IndicesExistsTemplateService) Validate() error { } // Do executes the operation. -func (s *IndicesExistsTemplateService) Do() (bool, error) { +func (s *IndicesExistsTemplateService) Do(ctx context.Context) (bool, error) { // Check pre-conditions if err := s.Validate(); err != nil { return false, err @@ -95,7 +97,7 @@ func (s *IndicesExistsTemplateService) Do() (bool, error) { } // Get HTTP response - res, err := s.client.PerformRequest("HEAD", path, params, nil, 404) + res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404) if err != nil { return false, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_exists_type.go b/vendor/gopkg.in/olivere/elastic.v5/indices_exists_type.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v3/indices_exists_type.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_exists_type.go index 631f773fe..e8f8a7bbf 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_exists_type.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_exists_type.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,12 +10,14 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesExistsTypeService checks if one or more types exist in one or more indices. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-types-exists.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-types-exists.html // for details. type IndicesExistsTypeService struct { client *Client @@ -32,8 +34,6 @@ type IndicesExistsTypeService struct { func NewIndicesExistsTypeService(client *Client) *IndicesExistsTypeService { return &IndicesExistsTypeService{ client: client, - index: make([]string, 0), - typ: make([]string, 0), } } @@ -87,7 +87,7 @@ func (s *IndicesExistsTypeService) Pretty(pretty bool) *IndicesExistsTypeService // buildURL builds the URL for the operation. func (s *IndicesExistsTypeService) buildURL() (string, url.Values, error) { // Build URL - path, err := uritemplates.Expand("/{index}/{type}", map[string]string{ + path, err := uritemplates.Expand("/{index}/_mapping/{type}", map[string]string{ "index": strings.Join(s.index, ","), "type": strings.Join(s.typ, ","), }) @@ -131,7 +131,7 @@ func (s *IndicesExistsTypeService) Validate() error { } // Do executes the operation. -func (s *IndicesExistsTypeService) Do() (bool, error) { +func (s *IndicesExistsTypeService) Do(ctx context.Context) (bool, error) { // Check pre-conditions if err := s.Validate(); err != nil { return false, err @@ -144,7 +144,7 @@ func (s *IndicesExistsTypeService) Do() (bool, error) { } // Get HTTP response - res, err := s.client.PerformRequest("HEAD", path, params, nil, 404) + res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404) if err != nil { return false, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_flush.go b/vendor/gopkg.in/olivere/elastic.v5/indices_flush.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/indices_flush.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_flush.go index 282c4de55..8afad814a 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_flush.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_flush.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,14 +9,16 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // Flush allows to flush one or more indices. The flush process of an index // basically frees memory from the index by flushing data to the index // storage and clearing the internal transaction log. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-flush.html // for details. type IndicesFlushService struct { client *Client @@ -135,7 +137,7 @@ func (s *IndicesFlushService) Validate() error { } // Do executes the service. -func (s *IndicesFlushService) Do() (*IndicesFlushResponse, error) { +func (s *IndicesFlushService) Do(ctx context.Context) (*IndicesFlushResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -148,7 +150,7 @@ func (s *IndicesFlushService) Do() (*IndicesFlushResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_forcemerge.go b/vendor/gopkg.in/olivere/elastic.v5/indices_forcemerge.go similarity index 88% rename from vendor/gopkg.in/olivere/elastic.v3/indices_forcemerge.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_forcemerge.go index 69c155471..46b180173 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_forcemerge.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_forcemerge.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,7 +9,9 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesForcemergeService allows to force merging of one or more indices. @@ -17,7 +19,7 @@ import ( // within each shard. The force merge operation allows to reduce the number // of segments by merging them. // -// See http://www.elastic.co/guide/en/elasticsearch/reference/2.1/indices-forcemerge.html +// See http://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-forcemerge.html // for more information. type IndicesForcemergeService struct { client *Client @@ -30,7 +32,6 @@ type IndicesForcemergeService struct { maxNumSegments interface{} onlyExpungeDeletes *bool operationThreading interface{} - waitForMerge *bool } // NewIndicesForcemergeService creates a new IndicesForcemergeService. @@ -99,13 +100,6 @@ func (s *IndicesForcemergeService) OperationThreading(operationThreading interfa return s } -// WaitForMerge specifies whether the request should block until the -// merge process is finished (default: true). -func (s *IndicesForcemergeService) WaitForMerge(waitForMerge bool) *IndicesForcemergeService { - s.waitForMerge = &waitForMerge - return s -} - // Pretty indicates that the JSON response be indented and human readable. func (s *IndicesForcemergeService) Pretty(pretty bool) *IndicesForcemergeService { s.pretty = pretty @@ -155,9 +149,6 @@ func (s *IndicesForcemergeService) buildURL() (string, url.Values, error) { if s.operationThreading != nil { params.Set("operation_threading", fmt.Sprintf("%v", s.operationThreading)) } - if s.waitForMerge != nil { - params.Set("wait_for_merge", fmt.Sprintf("%v", *s.waitForMerge)) - } return path, params, nil } @@ -167,7 +158,7 @@ func (s *IndicesForcemergeService) Validate() error { } // Do executes the operation. -func (s *IndicesForcemergeService) Do() (*IndicesForcemergeResponse, error) { +func (s *IndicesForcemergeService) Do(ctx context.Context) (*IndicesForcemergeResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -180,7 +171,7 @@ func (s *IndicesForcemergeService) Do() (*IndicesForcemergeResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_get.go b/vendor/gopkg.in/olivere/elastic.v5/indices_get.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/indices_get.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_get.go index 3d3a8a911..e576d5577 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_get.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_get.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,12 +9,14 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesGetService retrieves information about one or more indices. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-index.html // for more details. type IndicesGetService struct { client *Client @@ -166,7 +168,7 @@ func (s *IndicesGetService) Validate() error { } // Do executes the operation. -func (s *IndicesGetService) Do() (map[string]*IndicesGetResponse, error) { +func (s *IndicesGetService) Do(ctx context.Context) (map[string]*IndicesGetResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -179,7 +181,7 @@ func (s *IndicesGetService) Do() (map[string]*IndicesGetResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_get_aliases.go b/vendor/gopkg.in/olivere/elastic.v5/indices_get_aliases.go similarity index 63% rename from vendor/gopkg.in/olivere/elastic.v3/indices_get_aliases.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_get_aliases.go index 42755f9f2..2f827f721 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_get_aliases.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_get_aliases.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,65 +9,71 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) +// AliasesService returns the aliases associated with one or more indices. +// See http://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-aliases.html. type AliasesService struct { - client *Client - indices []string - pretty bool + client *Client + index []string + pretty bool } +// NewAliasesService instantiates a new AliasesService. func NewAliasesService(client *Client) *AliasesService { builder := &AliasesService{ - client: client, - indices: make([]string, 0), + client: client, } return builder } +// Pretty asks Elasticsearch to indent the returned JSON. func (s *AliasesService) Pretty(pretty bool) *AliasesService { s.pretty = pretty return s } -func (s *AliasesService) Index(indices ...string) *AliasesService { - s.indices = append(s.indices, indices...) +// Index adds one or more indices. +func (s *AliasesService) Index(index ...string) *AliasesService { + s.index = append(s.index, index...) return s } -func (s *AliasesService) Do() (*AliasesResult, error) { +// buildURL builds the URL for the operation. +func (s *AliasesService) buildURL() (string, url.Values, error) { var err error + var path string - // Build url - path := "/" - - // Indices part - indexPart := make([]string, 0) - for _, index := range s.indices { - index, err = uritemplates.Expand("{index}", map[string]string{ - "index": index, + if len(s.index) > 0 { + path, err = uritemplates.Expand("/{index}/_aliases", map[string]string{ + "index": strings.Join(s.index, ","), }) - if err != nil { - return nil, err - } - indexPart = append(indexPart, index) + } else { + path = "/_aliases" + } + if err != nil { + return "", url.Values{}, err } - path += strings.Join(indexPart, ",") - // TODO Add types here - - // Search - path += "/_aliases" - - // Parameters - params := make(url.Values) + // Add query string parameters + params := url.Values{} if s.pretty { params.Set("pretty", fmt.Sprintf("%v", s.pretty)) } + return path, params, nil +} + +func (s *AliasesService) Do(ctx context.Context) (*AliasesResult, error) { + path, params, err := s.buildURL() + if err != nil { + return nil, err + } // Get response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } @@ -131,8 +137,7 @@ type aliasResult struct { } func (ar AliasesResult) IndicesByAlias(aliasName string) []string { - indices := make([]string, 0) - + var indices []string for indexName, indexInfo := range ar.Indices { for _, aliasInfo := range indexInfo.Aliases { if aliasInfo.AliasName == aliasName { @@ -140,7 +145,6 @@ func (ar AliasesResult) IndicesByAlias(aliasName string) []string { } } } - return indices } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_get_field_mapping.go b/vendor/gopkg.in/olivere/elastic.v5/indices_get_field_mapping.go new file mode 100644 index 000000000..88e654907 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_get_field_mapping.go @@ -0,0 +1,184 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "fmt" + "net/url" + "strings" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// IndicesGetFieldMappingService retrieves the mapping definitions for the fields in an index +// or index/type. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-field-mapping.html +// for details. +type IndicesGetFieldMappingService struct { + client *Client + pretty bool + index []string + typ []string + field []string + local *bool + ignoreUnavailable *bool + allowNoIndices *bool + expandWildcards string +} + +// NewGetFieldMappingService is an alias for NewIndicesGetFieldMappingService. +// Use NewIndicesGetFieldMappingService. +func NewGetFieldMappingService(client *Client) *IndicesGetFieldMappingService { + return NewIndicesGetFieldMappingService(client) +} + +// NewIndicesGetFieldMappingService creates a new IndicesGetFieldMappingService. +func NewIndicesGetFieldMappingService(client *Client) *IndicesGetFieldMappingService { + return &IndicesGetFieldMappingService{ + client: client, + } +} + +// Index is a list of index names. +func (s *IndicesGetFieldMappingService) Index(indices ...string) *IndicesGetFieldMappingService { + s.index = append(s.index, indices...) + return s +} + +// Type is a list of document types. +func (s *IndicesGetFieldMappingService) Type(types ...string) *IndicesGetFieldMappingService { + s.typ = append(s.typ, types...) + return s +} + +// Field is a list of fields. +func (s *IndicesGetFieldMappingService) Field(fields ...string) *IndicesGetFieldMappingService { + s.field = append(s.field, fields...) + return s +} + +// AllowNoIndices indicates whether to ignore if a wildcard indices +// expression resolves into no concrete indices. +// This includes `_all` string or when no indices have been specified. +func (s *IndicesGetFieldMappingService) AllowNoIndices(allowNoIndices bool) *IndicesGetFieldMappingService { + s.allowNoIndices = &allowNoIndices + return s +} + +// ExpandWildcards indicates whether to expand wildcard expression to +// concrete indices that are open, closed or both.. +func (s *IndicesGetFieldMappingService) ExpandWildcards(expandWildcards string) *IndicesGetFieldMappingService { + s.expandWildcards = expandWildcards + return s +} + +// Local indicates whether to return local information, do not retrieve +// the state from master node (default: false). +func (s *IndicesGetFieldMappingService) Local(local bool) *IndicesGetFieldMappingService { + s.local = &local + return s +} + +// IgnoreUnavailable indicates whether specified concrete indices should be +// ignored when unavailable (missing or closed). +func (s *IndicesGetFieldMappingService) IgnoreUnavailable(ignoreUnavailable bool) *IndicesGetFieldMappingService { + s.ignoreUnavailable = &ignoreUnavailable + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *IndicesGetFieldMappingService) Pretty(pretty bool) *IndicesGetFieldMappingService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *IndicesGetFieldMappingService) buildURL() (string, url.Values, error) { + var index, typ, field []string + + if len(s.index) > 0 { + index = s.index + } else { + index = []string{"_all"} + } + + if len(s.typ) > 0 { + typ = s.typ + } else { + typ = []string{"_all"} + } + + if len(s.field) > 0 { + field = s.field + } else { + field = []string{"*"} + } + + // Build URL + path, err := uritemplates.Expand("/{index}/_mapping/{type}/field/{field}", map[string]string{ + "index": strings.Join(index, ","), + "type": strings.Join(typ, ","), + "field": strings.Join(field, ","), + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + if s.ignoreUnavailable != nil { + params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) + } + if s.allowNoIndices != nil { + params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) + } + if s.expandWildcards != "" { + params.Set("expand_wildcards", s.expandWildcards) + } + if s.local != nil { + params.Set("local", fmt.Sprintf("%v", *s.local)) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *IndicesGetFieldMappingService) Validate() error { + return nil +} + +// Do executes the operation. It returns mapping definitions for an index +// or index/type. +func (s *IndicesGetFieldMappingService) Do(ctx context.Context) (map[string]interface{}, error) { + var ret map[string]interface{} + + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + if err != nil { + return nil, err + } + + // Return operation response + if err := s.client.decoder.Decode(res.Body, &ret); err != nil { + return nil, err + } + return ret, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_get_mapping.go b/vendor/gopkg.in/olivere/elastic.v5/indices_get_mapping.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/indices_get_mapping.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_get_mapping.go index d1e633351..d5a1d3d3f 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_get_mapping.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_get_mapping.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,13 +9,15 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesGetMappingService retrieves the mapping definitions for an index or // index/type. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-mapping.html // for details. type IndicesGetMappingService struct { client *Client @@ -142,7 +144,7 @@ func (s *IndicesGetMappingService) Validate() error { // Do executes the operation. It returns mapping definitions for an index // or index/type. -func (s *IndicesGetMappingService) Do() (map[string]interface{}, error) { +func (s *IndicesGetMappingService) Do(ctx context.Context) (map[string]interface{}, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -155,7 +157,7 @@ func (s *IndicesGetMappingService) Do() (map[string]interface{}, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_get_settings.go b/vendor/gopkg.in/olivere/elastic.v5/indices_get_settings.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/indices_get_settings.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_get_settings.go index 84311323c..1d1733b4f 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_get_settings.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_get_settings.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,13 +9,15 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesGetSettingsService allows to retrieve settings of one // or more indices. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-settings.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-settings.html // for more details. type IndicesGetSettingsService struct { client *Client @@ -150,7 +152,7 @@ func (s *IndicesGetSettingsService) Validate() error { } // Do executes the operation. -func (s *IndicesGetSettingsService) Do() (map[string]*IndicesGetSettingsResponse, error) { +func (s *IndicesGetSettingsService) Do(ctx context.Context) (map[string]*IndicesGetSettingsResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -163,7 +165,7 @@ func (s *IndicesGetSettingsService) Do() (map[string]*IndicesGetSettingsResponse } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_get_template.go b/vendor/gopkg.in/olivere/elastic.v5/indices_get_template.go similarity index 88% rename from vendor/gopkg.in/olivere/elastic.v3/indices_get_template.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_get_template.go index 756e0ee5a..5da39df0d 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_get_template.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_get_template.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,11 +9,13 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesGetTemplateService returns an index template. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/indices-templates.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-templates.html. type IndicesGetTemplateService struct { client *Client pretty bool @@ -91,7 +93,7 @@ func (s *IndicesGetTemplateService) Validate() error { } // Do executes the operation. -func (s *IndicesGetTemplateService) Do() (map[string]*IndicesGetTemplateResponse, error) { +func (s *IndicesGetTemplateService) Do(ctx context.Context) (map[string]*IndicesGetTemplateResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -104,7 +106,7 @@ func (s *IndicesGetTemplateService) Do() (map[string]*IndicesGetTemplateResponse } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_open.go b/vendor/gopkg.in/olivere/elastic.v5/indices_open.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/indices_open.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_open.go index e9da08876..26fa477f1 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_open.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_open.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,12 +8,14 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesOpenService opens an index. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-open-close.html // for details. type IndicesOpenService struct { client *Client @@ -124,7 +126,7 @@ func (s *IndicesOpenService) Validate() error { } // Do executes the operation. -func (s *IndicesOpenService) Do() (*IndicesOpenResponse, error) { +func (s *IndicesOpenService) Do(ctx context.Context) (*IndicesOpenResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -137,7 +139,7 @@ func (s *IndicesOpenService) Do() (*IndicesOpenResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_put_alias.go b/vendor/gopkg.in/olivere/elastic.v5/indices_put_alias.go new file mode 100644 index 000000000..4b3047c6f --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_put_alias.go @@ -0,0 +1,296 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "fmt" + "net/url" + "strings" + + "golang.org/x/net/context" +) + +// -- Actions -- + +// AliasAction is an action to apply to an alias, e.g. "add" or "remove". +type AliasAction interface { + Source() (interface{}, error) +} + +// AliasAddAction is an action to add to an alias. +type AliasAddAction struct { + index []string // index name(s) + alias string // alias name + filter Query + routing string + searchRouting string + indexRouting string +} + +// NewAliasAddAction returns an action to add an alias. +func NewAliasAddAction(alias string) *AliasAddAction { + return &AliasAddAction{ + alias: alias, + } +} + +// Index associates one or more indices to the alias. +func (a *AliasAddAction) Index(index ...string) *AliasAddAction { + a.index = append(a.index, index...) + return a +} + +func (a *AliasAddAction) removeBlankIndexNames() { + var indices []string + for _, index := range a.index { + if len(index) > 0 { + indices = append(indices, index) + } + } + a.index = indices +} + +// Filter associates a filter to the alias. +func (a *AliasAddAction) Filter(filter Query) *AliasAddAction { + a.filter = filter + return a +} + +// Routing associates a routing value to the alias. +// This basically sets index and search routing to the same value. +func (a *AliasAddAction) Routing(routing string) *AliasAddAction { + a.routing = routing + return a +} + +// IndexRouting associates an index routing value to the alias. +func (a *AliasAddAction) IndexRouting(routing string) *AliasAddAction { + a.indexRouting = routing + return a +} + +// SearchRouting associates a search routing value to the alias. +func (a *AliasAddAction) SearchRouting(routing ...string) *AliasAddAction { + a.searchRouting = strings.Join(routing, ",") + return a +} + +// Validate checks if the operation is valid. +func (a *AliasAddAction) Validate() error { + var invalid []string + if len(a.alias) == 0 { + invalid = append(invalid, "Alias") + } + if len(a.index) == 0 { + invalid = append(invalid, "Index") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Source returns the JSON-serializable data. +func (a *AliasAddAction) Source() (interface{}, error) { + a.removeBlankIndexNames() + if err := a.Validate(); err != nil { + return nil, err + } + src := make(map[string]interface{}) + act := make(map[string]interface{}) + src["add"] = act + act["alias"] = a.alias + switch len(a.index) { + case 1: + act["index"] = a.index[0] + default: + act["indices"] = a.index + } + if a.filter != nil { + f, err := a.filter.Source() + if err != nil { + return nil, err + } + act["filter"] = f + } + if len(a.routing) > 0 { + act["routing"] = a.routing + } + if len(a.indexRouting) > 0 { + act["index_routing"] = a.indexRouting + } + if len(a.searchRouting) > 0 { + act["search_routing"] = a.searchRouting + } + return src, nil +} + +// AliasRemoveAction is an action to remove an alias. +type AliasRemoveAction struct { + index []string // index name(s) + alias string // alias name +} + +// NewAliasRemoveAction returns an action to remove an alias. +func NewAliasRemoveAction(alias string) *AliasRemoveAction { + return &AliasRemoveAction{ + alias: alias, + } +} + +// Index associates one or more indices to the alias. +func (a *AliasRemoveAction) Index(index ...string) *AliasRemoveAction { + a.index = append(a.index, index...) + return a +} + +func (a *AliasRemoveAction) removeBlankIndexNames() { + var indices []string + for _, index := range a.index { + if len(index) > 0 { + indices = append(indices, index) + } + } + a.index = indices +} + +// Validate checks if the operation is valid. +func (a *AliasRemoveAction) Validate() error { + var invalid []string + if len(a.alias) == 0 { + invalid = append(invalid, "Alias") + } + if len(a.index) == 0 { + invalid = append(invalid, "Index") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Source returns the JSON-serializable data. +func (a *AliasRemoveAction) Source() (interface{}, error) { + a.removeBlankIndexNames() + if err := a.Validate(); err != nil { + return nil, err + } + src := make(map[string]interface{}) + act := make(map[string]interface{}) + src["remove"] = act + act["alias"] = a.alias + switch len(a.index) { + case 1: + act["index"] = a.index[0] + default: + act["indices"] = a.index + } + return src, nil +} + +// -- Service -- + +// AliasService enables users to add or remove an alias. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-aliases.html +// for details. +type AliasService struct { + client *Client + actions []AliasAction + pretty bool +} + +// NewAliasService implements a service to manage aliases. +func NewAliasService(client *Client) *AliasService { + builder := &AliasService{ + client: client, + } + return builder +} + +// Pretty asks Elasticsearch to indent the HTTP response. +func (s *AliasService) Pretty(pretty bool) *AliasService { + s.pretty = pretty + return s +} + +// Add adds an alias to an index. +func (s *AliasService) Add(indexName string, aliasName string) *AliasService { + action := NewAliasAddAction(aliasName).Index(indexName) + s.actions = append(s.actions, action) + return s +} + +// Add adds an alias to an index and associates a filter to the alias. +func (s *AliasService) AddWithFilter(indexName string, aliasName string, filter Query) *AliasService { + action := NewAliasAddAction(aliasName).Index(indexName).Filter(filter) + s.actions = append(s.actions, action) + return s +} + +// Remove removes an alias. +func (s *AliasService) Remove(indexName string, aliasName string) *AliasService { + action := NewAliasRemoveAction(aliasName).Index(indexName) + s.actions = append(s.actions, action) + return s +} + +// Action accepts one or more AliasAction instances which can be +// of type AliasAddAction or AliasRemoveAction. +func (s *AliasService) Action(action ...AliasAction) *AliasService { + s.actions = append(s.actions, action...) + return s +} + +// buildURL builds the URL for the operation. +func (s *AliasService) buildURL() (string, url.Values, error) { + path := "/_aliases" + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", fmt.Sprintf("%v", s.pretty)) + } + return path, params, nil +} + +// Do executes the command. +func (s *AliasService) Do(ctx context.Context) (*AliasResult, error) { + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Body with actions + body := make(map[string]interface{}) + var actions []interface{} + for _, action := range s.actions { + src, err := action.Source() + if err != nil { + return nil, err + } + actions = append(actions, src) + } + body["actions"] = actions + + // Get response + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + if err != nil { + return nil, err + } + + // Return results + ret := new(AliasResult) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// -- Result of an alias request. + +// AliasResult is the outcome of calling Do on AliasService. +type AliasResult struct { + Acknowledged bool `json:"acknowledged"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_put_mapping.go b/vendor/gopkg.in/olivere/elastic.v5/indices_put_mapping.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v3/indices_put_mapping.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_put_mapping.go index 5b2f99bae..0437c443b 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_put_mapping.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_put_mapping.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,13 +9,15 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesPutMappingService allows to register specific mapping definition // for a specific type. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-put-mapping.html // for details. type IndicesPutMappingService struct { client *Client @@ -180,7 +182,7 @@ func (s *IndicesPutMappingService) Validate() error { } // Do executes the operation. -func (s *IndicesPutMappingService) Do() (*PutMappingResponse, error) { +func (s *IndicesPutMappingService) Do(ctx context.Context) (*PutMappingResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -201,7 +203,7 @@ func (s *IndicesPutMappingService) Do() (*PutMappingResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("PUT", path, params, body) + res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_put_settings.go b/vendor/gopkg.in/olivere/elastic.v5/indices_put_settings.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/indices_put_settings.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_put_settings.go index f96e37aba..4f246761c 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_put_settings.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_put_settings.go @@ -1,4 +1,4 @@ -// Copyright 2012-2016 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,14 +9,16 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesPutSettingsService changes specific index level settings in // real time. // // See the documentation at -// https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html. +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-update-settings.html. type IndicesPutSettingsService struct { client *Client pretty bool @@ -143,7 +145,7 @@ func (s *IndicesPutSettingsService) Validate() error { } // Do executes the operation. -func (s *IndicesPutSettingsService) Do() (*IndicesPutSettingsResponse, error) { +func (s *IndicesPutSettingsService) Do(ctx context.Context) (*IndicesPutSettingsResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -164,7 +166,7 @@ func (s *IndicesPutSettingsService) Do() (*IndicesPutSettingsResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("PUT", path, params, body) + res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_put_template.go b/vendor/gopkg.in/olivere/elastic.v5/indices_put_template.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/indices_put_template.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_put_template.go index cd8a5faea..53d0027df 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_put_template.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_put_template.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,11 +8,13 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesPutTemplateService creates or updates index mappings. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/indices-templates.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-templates.html. type IndicesPutTemplateService struct { client *Client pretty bool @@ -138,7 +140,7 @@ func (s *IndicesPutTemplateService) Validate() error { } // Do executes the operation. -func (s *IndicesPutTemplateService) Do() (*IndicesPutTemplateResponse, error) { +func (s *IndicesPutTemplateService) Do(ctx context.Context) (*IndicesPutTemplateResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -159,7 +161,7 @@ func (s *IndicesPutTemplateService) Do() (*IndicesPutTemplateResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("PUT", path, params, body) + res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_refresh.go b/vendor/gopkg.in/olivere/elastic.v5/indices_refresh.go new file mode 100644 index 000000000..53cee2a63 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_refresh.go @@ -0,0 +1,105 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "fmt" + "net/url" + "strings" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// RefreshService explicitly refreshes one or more indices. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-refresh.html. +type RefreshService struct { + client *Client + index []string + force *bool + pretty bool +} + +// NewRefreshService creates a new instance of RefreshService. +func NewRefreshService(client *Client) *RefreshService { + builder := &RefreshService{ + client: client, + } + return builder +} + +// Index specifies the indices to refresh. +func (s *RefreshService) Index(index ...string) *RefreshService { + s.index = append(s.index, index...) + return s +} + +// Force forces a refresh. +func (s *RefreshService) Force(force bool) *RefreshService { + s.force = &force + return s +} + +// Pretty asks Elasticsearch to return indented JSON. +func (s *RefreshService) Pretty(pretty bool) *RefreshService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *RefreshService) buildURL() (string, url.Values, error) { + var err error + var path string + + if len(s.index) > 0 { + path, err = uritemplates.Expand("/{index}/_refresh", map[string]string{ + "index": strings.Join(s.index, ","), + }) + } else { + path = "/_refresh" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.force != nil { + params.Set("force", fmt.Sprintf("%v", *s.force)) + } + if s.pretty { + params.Set("pretty", fmt.Sprintf("%v", s.pretty)) + } + return path, params, nil +} + +// Do executes the request. +func (s *RefreshService) Do(ctx context.Context) (*RefreshResult, error) { + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get response + res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) + if err != nil { + return nil, err + } + + // Return result + ret := new(RefreshResult) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// -- Result of a refresh request. + +// RefreshResult is the outcome of RefreshService.Do. +type RefreshResult struct { + Shards shardsInfo `json:"_shards,omitempty"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_rollover.go b/vendor/gopkg.in/olivere/elastic.v5/indices_rollover.go new file mode 100644 index 000000000..b6af63561 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_rollover.go @@ -0,0 +1,268 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "encoding/json" + "fmt" + "net/url" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// IndicesRolloverService rolls an alias over to a new index when the +// existing index is considered to be too large or too old. +// +// It is documented at +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-rollover-index.html. +type IndicesRolloverService struct { + client *Client + pretty bool + dryRun bool + newIndex string + alias string + masterTimeout string + timeout string + waitForActiveShards string + conditions map[string]interface{} + settings map[string]interface{} + mappings map[string]interface{} + bodyJson interface{} + bodyString string +} + +// NewIndicesRolloverService creates a new IndicesRolloverService. +func NewIndicesRolloverService(client *Client) *IndicesRolloverService { + return &IndicesRolloverService{ + client: client, + conditions: make(map[string]interface{}), + settings: make(map[string]interface{}), + mappings: make(map[string]interface{}), + } +} + +// Alias is the name of the alias to rollover. +func (s *IndicesRolloverService) Alias(alias string) *IndicesRolloverService { + s.alias = alias + return s +} + +// NewIndex is the name of the rollover index. +func (s *IndicesRolloverService) NewIndex(newIndex string) *IndicesRolloverService { + s.newIndex = newIndex + return s +} + +// MasterTimeout specifies the timeout for connection to master. +func (s *IndicesRolloverService) MasterTimeout(masterTimeout string) *IndicesRolloverService { + s.masterTimeout = masterTimeout + return s +} + +// Timeout sets an explicit operation timeout. +func (s *IndicesRolloverService) Timeout(timeout string) *IndicesRolloverService { + s.timeout = timeout + return s +} + +// WaitForActiveShards sets the number of active shards to wait for on the +// newly created rollover index before the operation returns. +func (s *IndicesRolloverService) WaitForActiveShards(waitForActiveShards string) *IndicesRolloverService { + s.waitForActiveShards = waitForActiveShards + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *IndicesRolloverService) Pretty(pretty bool) *IndicesRolloverService { + s.pretty = pretty + return s +} + +// DryRun, when set, specifies that only conditions are checked without +// performing the actual rollover. +func (s *IndicesRolloverService) DryRun(dryRun bool) *IndicesRolloverService { + s.dryRun = dryRun + return s +} + +// Conditions allows to specify all conditions as a dictionary. +func (s *IndicesRolloverService) Conditions(conditions map[string]interface{}) *IndicesRolloverService { + s.conditions = conditions + return s +} + +// AddCondition adds a condition to the rollover decision. +func (s *IndicesRolloverService) AddCondition(name string, value interface{}) *IndicesRolloverService { + s.conditions[name] = value + return s +} + +// AddMaxIndexAgeCondition adds a condition to set the max index age. +func (s *IndicesRolloverService) AddMaxIndexAgeCondition(time string) *IndicesRolloverService { + s.conditions["max_age"] = time + return s +} + +// AddMaxIndexDocsCondition adds a condition to set the max documents in the index. +func (s *IndicesRolloverService) AddMaxIndexDocsCondition(docs int64) *IndicesRolloverService { + s.conditions["max_docs"] = docs + return s +} + +// Settings adds the index settings. +func (s *IndicesRolloverService) Settings(settings map[string]interface{}) *IndicesRolloverService { + s.settings = settings + return s +} + +// AddSetting adds an index setting. +func (s *IndicesRolloverService) AddSetting(name string, value interface{}) *IndicesRolloverService { + s.settings[name] = value + return s +} + +// Mappings adds the index mappings. +func (s *IndicesRolloverService) Mappings(mappings map[string]interface{}) *IndicesRolloverService { + s.mappings = mappings + return s +} + +// AddMapping adds a mapping for the given type. +func (s *IndicesRolloverService) AddMapping(typ string, mapping interface{}) *IndicesRolloverService { + s.mappings[typ] = mapping + return s +} + +// BodyJson sets the conditions that needs to be met for executing rollover, +// specified as a serializable JSON instance which is sent as the body of +// the request. +func (s *IndicesRolloverService) BodyJson(body interface{}) *IndicesRolloverService { + s.bodyJson = body + return s +} + +// BodyString sets the conditions that needs to be met for executing rollover, +// specified as a string which is sent as the body of the request. +func (s *IndicesRolloverService) BodyString(body string) *IndicesRolloverService { + s.bodyString = body + return s +} + +// getBody returns the body of the request, if not explicitly set via +// BodyJson or BodyString. +func (s *IndicesRolloverService) getBody() interface{} { + body := make(map[string]interface{}) + if len(s.conditions) > 0 { + body["conditions"] = s.conditions + } + if len(s.settings) > 0 { + body["settings"] = s.settings + } + if len(s.mappings) > 0 { + body["mappings"] = s.mappings + } + return body +} + +// buildURL builds the URL for the operation. +func (s *IndicesRolloverService) buildURL() (string, url.Values, error) { + // Build URL + var err error + var path string + if s.newIndex != "" { + path, err = uritemplates.Expand("/{alias}/_rollover/{new_index}", map[string]string{ + "alias": s.alias, + "new_index": s.newIndex, + }) + } else { + path, err = uritemplates.Expand("/{alias}/_rollover", map[string]string{ + "alias": s.alias, + }) + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + if s.dryRun { + params.Set("dry_run", "1") + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + if s.waitForActiveShards != "" { + params.Set("wait_for_active_shards", s.waitForActiveShards) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *IndicesRolloverService) Validate() error { + var invalid []string + if s.alias == "" { + invalid = append(invalid, "Alias") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *IndicesRolloverService) Do(ctx context.Context) (*IndicesRolloverResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Setup HTTP request body + var body interface{} + if s.bodyJson != nil { + body = s.bodyJson + } else if s.bodyString != "" { + body = s.bodyString + } else { + body = s.getBody() + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(IndicesRolloverResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// IndicesRolloverResponse is the response of IndicesRolloverService.Do. +type IndicesRolloverResponse struct { + OldIndex string `json:"old_index"` + NewIndex string `json:"new_index"` + RolledOver bool `json:"rolled_over"` + DryRun bool `json:"dry_run"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Conditions map[string]bool `json:"conditions"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_shrink.go b/vendor/gopkg.in/olivere/elastic.v5/indices_shrink.go new file mode 100644 index 000000000..bfde8d96f --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_shrink.go @@ -0,0 +1,174 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "encoding/json" + "fmt" + "net/url" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// IndicesShrinkService allows you to shrink an existing index into a +// new index with fewer primary shards. +// +// For further details, see +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-shrink-index.html. +type IndicesShrinkService struct { + client *Client + pretty bool + source string + target string + masterTimeout string + timeout string + waitForActiveShards string + bodyJson interface{} + bodyString string +} + +// NewIndicesShrinkService creates a new IndicesShrinkService. +func NewIndicesShrinkService(client *Client) *IndicesShrinkService { + return &IndicesShrinkService{ + client: client, + } +} + +// Source is the name of the source index to shrink. +func (s *IndicesShrinkService) Source(source string) *IndicesShrinkService { + s.source = source + return s +} + +// Target is the name of the target index to shrink into. +func (s *IndicesShrinkService) Target(target string) *IndicesShrinkService { + s.target = target + return s +} + +// MasterTimeout specifies the timeout for connection to master. +func (s *IndicesShrinkService) MasterTimeout(masterTimeout string) *IndicesShrinkService { + s.masterTimeout = masterTimeout + return s +} + +// Timeout is an explicit operation timeout. +func (s *IndicesShrinkService) Timeout(timeout string) *IndicesShrinkService { + s.timeout = timeout + return s +} + +// WaitForActiveShards sets the number of active shards to wait for on +// the shrunken index before the operation returns. +func (s *IndicesShrinkService) WaitForActiveShards(waitForActiveShards string) *IndicesShrinkService { + s.waitForActiveShards = waitForActiveShards + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *IndicesShrinkService) Pretty(pretty bool) *IndicesShrinkService { + s.pretty = pretty + return s +} + +// BodyJson is the configuration for the target index (`settings` and `aliases`) +// defined as a JSON-serializable instance to be sent as the request body. +func (s *IndicesShrinkService) BodyJson(body interface{}) *IndicesShrinkService { + s.bodyJson = body + return s +} + +// BodyString is the configuration for the target index (`settings` and `aliases`) +// defined as a string to send as the request body. +func (s *IndicesShrinkService) BodyString(body string) *IndicesShrinkService { + s.bodyString = body + return s +} + +// buildURL builds the URL for the operation. +func (s *IndicesShrinkService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/{source}/_shrink/{target}", map[string]string{ + "source": s.source, + "target": s.target, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + if s.waitForActiveShards != "" { + params.Set("wait_for_active_shards", s.waitForActiveShards) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *IndicesShrinkService) Validate() error { + var invalid []string + if s.source == "" { + invalid = append(invalid, "Source") + } + if s.target == "" { + invalid = append(invalid, "Target") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *IndicesShrinkService) Do(ctx context.Context) (*IndicesShrinkResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Setup HTTP request body + var body interface{} + if s.bodyJson != nil { + body = s.bodyJson + } else if s.bodyString != "" { + body = s.bodyString + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(IndicesShrinkResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// IndicesShrinkResponse is the response of IndicesShrinkService.Do. +type IndicesShrinkResponse struct { + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/indices_stats.go b/vendor/gopkg.in/olivere/elastic.v5/indices_stats.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v3/indices_stats.go rename to vendor/gopkg.in/olivere/elastic.v5/indices_stats.go index 5ba1adc31..b4f7bfd20 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/indices_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v5/indices_stats.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,11 +9,13 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // IndicesStatsService provides stats on various metrics of one or more -// indices. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-stats.html. +// indices. See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-stats.html. type IndicesStatsService struct { client *Client pretty bool @@ -166,7 +168,7 @@ func (s *IndicesStatsService) Validate() error { } // Do executes the operation. -func (s *IndicesStatsService) Do() (*IndicesStatsResponse, error) { +func (s *IndicesStatsService) Do(ctx context.Context) (*IndicesStatsResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -179,7 +181,7 @@ func (s *IndicesStatsService) Do() (*IndicesStatsResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/ingest_delete_pipeline.go b/vendor/gopkg.in/olivere/elastic.v5/ingest_delete_pipeline.go new file mode 100644 index 000000000..9fe97798a --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/ingest_delete_pipeline.go @@ -0,0 +1,124 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "encoding/json" + "fmt" + "net/url" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// IngestDeletePipelineService deletes pipelines by ID. +// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/delete-pipeline-api.html. +type IngestDeletePipelineService struct { + client *Client + pretty bool + id string + masterTimeout string + timeout string +} + +// NewIngestDeletePipelineService creates a new IngestDeletePipelineService. +func NewIngestDeletePipelineService(client *Client) *IngestDeletePipelineService { + return &IngestDeletePipelineService{ + client: client, + } +} + +// Id is documented as: Pipeline ID. +func (s *IngestDeletePipelineService) Id(id string) *IngestDeletePipelineService { + s.id = id + return s +} + +// MasterTimeout is documented as: Explicit operation timeout for connection to master node. +func (s *IngestDeletePipelineService) MasterTimeout(masterTimeout string) *IngestDeletePipelineService { + s.masterTimeout = masterTimeout + return s +} + +// Timeout is documented as: Explicit operation timeout. +func (s *IngestDeletePipelineService) Timeout(timeout string) *IngestDeletePipelineService { + s.timeout = timeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *IngestDeletePipelineService) Pretty(pretty bool) *IngestDeletePipelineService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *IngestDeletePipelineService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_ingest/pipeline/{id}", map[string]string{ + "id": s.id, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *IngestDeletePipelineService) Validate() error { + var invalid []string + if s.id == "" { + invalid = append(invalid, "Id") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *IngestDeletePipelineService) Do(ctx context.Context) (*IngestDeletePipelineResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(IngestDeletePipelineResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// IngestDeletePipelineResponse is the response of IngestDeletePipelineService.Do. +type IngestDeletePipelineResponse struct { + Acknowledged bool `json:"acknowledged"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/ingest_get_pipeline.go b/vendor/gopkg.in/olivere/elastic.v5/ingest_get_pipeline.go new file mode 100644 index 000000000..61199477c --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/ingest_get_pipeline.go @@ -0,0 +1,118 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "encoding/json" + "net/url" + "strings" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// IngestGetPipelineService returns pipelines based on ID. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/get-pipeline-api.html +// for documentation. +type IngestGetPipelineService struct { + client *Client + pretty bool + id []string + masterTimeout string +} + +// NewIngestGetPipelineService creates a new IngestGetPipelineService. +func NewIngestGetPipelineService(client *Client) *IngestGetPipelineService { + return &IngestGetPipelineService{ + client: client, + } +} + +// Id is a list of pipeline ids. Wildcards supported. +func (s *IngestGetPipelineService) Id(id ...string) *IngestGetPipelineService { + s.id = append(s.id, id...) + return s +} + +// MasterTimeout is an explicit operation timeout for connection to master node. +func (s *IngestGetPipelineService) MasterTimeout(masterTimeout string) *IngestGetPipelineService { + s.masterTimeout = masterTimeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *IngestGetPipelineService) Pretty(pretty bool) *IngestGetPipelineService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *IngestGetPipelineService) buildURL() (string, url.Values, error) { + var err error + var path string + + // Build URL + if len(s.id) > 0 { + path, err = uritemplates.Expand("/_ingest/pipeline/{id}", map[string]string{ + "id": strings.Join(s.id, ","), + }) + } else { + path = "/_ingest/pipeline" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *IngestGetPipelineService) Validate() error { + return nil +} + +// Do executes the operation. +func (s *IngestGetPipelineService) Do(ctx context.Context) (IngestGetPipelineResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + if err != nil { + return nil, err + } + + // Return operation response + var ret IngestGetPipelineResponse + if err := json.Unmarshal(res.Body, &ret); err != nil { + return nil, err + } + return ret, nil +} + +// IngestGetPipelineResponse is the response of IngestGetPipelineService.Do. +type IngestGetPipelineResponse map[string]*IngestGetPipeline + +type IngestGetPipeline struct { + ID string `json:"id"` + Config map[string]interface{} `json:"config"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/ingest_put_pipeline.go b/vendor/gopkg.in/olivere/elastic.v5/ingest_put_pipeline.go new file mode 100644 index 000000000..1ab423d5c --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/ingest_put_pipeline.go @@ -0,0 +1,152 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "encoding/json" + "fmt" + "net/url" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// IngestPutPipelineService adds pipelines and updates existing pipelines in +// the cluster. +// +// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/put-pipeline-api.html. +type IngestPutPipelineService struct { + client *Client + pretty bool + id string + masterTimeout string + timeout string + bodyJson interface{} + bodyString string +} + +// NewIngestPutPipelineService creates a new IngestPutPipelineService. +func NewIngestPutPipelineService(client *Client) *IngestPutPipelineService { + return &IngestPutPipelineService{ + client: client, + } +} + +// Id is the pipeline ID. +func (s *IngestPutPipelineService) Id(id string) *IngestPutPipelineService { + s.id = id + return s +} + +// MasterTimeout is an explicit operation timeout for connection to master node. +func (s *IngestPutPipelineService) MasterTimeout(masterTimeout string) *IngestPutPipelineService { + s.masterTimeout = masterTimeout + return s +} + +// Timeout specifies an explicit operation timeout. +func (s *IngestPutPipelineService) Timeout(timeout string) *IngestPutPipelineService { + s.timeout = timeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *IngestPutPipelineService) Pretty(pretty bool) *IngestPutPipelineService { + s.pretty = pretty + return s +} + +// BodyJson is the ingest definition, defined as a JSON-serializable document. +// Use e.g. a map[string]interface{} here. +func (s *IngestPutPipelineService) BodyJson(body interface{}) *IngestPutPipelineService { + s.bodyJson = body + return s +} + +// BodyString is the ingest definition, specified as a string. +func (s *IngestPutPipelineService) BodyString(body string) *IngestPutPipelineService { + s.bodyString = body + return s +} + +// buildURL builds the URL for the operation. +func (s *IngestPutPipelineService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_ingest/pipeline/{id}", map[string]string{ + "id": s.id, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *IngestPutPipelineService) Validate() error { + var invalid []string + if s.id == "" { + invalid = append(invalid, "Id") + } + if s.bodyString == "" && s.bodyJson == nil { + invalid = append(invalid, "BodyJson") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *IngestPutPipelineService) Do(ctx context.Context) (*IngestPutPipelineResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Setup HTTP request body + var body interface{} + if s.bodyJson != nil { + body = s.bodyJson + } else { + body = s.bodyString + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(IngestPutPipelineResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// IngestPutPipelineResponse is the response of IngestPutPipelineService.Do. +type IngestPutPipelineResponse struct { + Acknowledged bool `json:"acknowledged"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/ingest_simulate_pipeline.go b/vendor/gopkg.in/olivere/elastic.v5/ingest_simulate_pipeline.go new file mode 100644 index 000000000..7d41e353b --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/ingest_simulate_pipeline.go @@ -0,0 +1,157 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "encoding/json" + "fmt" + "net/url" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// IngestSimulatePipelineService executes a specific pipeline against the set of +// documents provided in the body of the request. +// +// The API is documented at +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/simulate-pipeline-api.html. +type IngestSimulatePipelineService struct { + client *Client + pretty bool + id string + verbose *bool + bodyJson interface{} + bodyString string +} + +// NewIngestSimulatePipelineService creates a new IngestSimulatePipeline. +func NewIngestSimulatePipelineService(client *Client) *IngestSimulatePipelineService { + return &IngestSimulatePipelineService{ + client: client, + } +} + +// Id specifies the pipeline ID. +func (s *IngestSimulatePipelineService) Id(id string) *IngestSimulatePipelineService { + s.id = id + return s +} + +// Verbose mode. Display data output for each processor in executed pipeline. +func (s *IngestSimulatePipelineService) Verbose(verbose bool) *IngestSimulatePipelineService { + s.verbose = &verbose + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *IngestSimulatePipelineService) Pretty(pretty bool) *IngestSimulatePipelineService { + s.pretty = pretty + return s +} + +// BodyJson is the ingest definition, defined as a JSON-serializable simulate +// definition. Use e.g. a map[string]interface{} here. +func (s *IngestSimulatePipelineService) BodyJson(body interface{}) *IngestSimulatePipelineService { + s.bodyJson = body + return s +} + +// BodyString is the simulate definition, defined as a string. +func (s *IngestSimulatePipelineService) BodyString(body string) *IngestSimulatePipelineService { + s.bodyString = body + return s +} + +// buildURL builds the URL for the operation. +func (s *IngestSimulatePipelineService) buildURL() (string, url.Values, error) { + var err error + var path string + + // Build URL + if s.id != "" { + path, err = uritemplates.Expand("/_ingest/pipeline/{id}/_simulate", map[string]string{ + "id": s.id, + }) + } else { + path = "/_ingest/pipeline/_simulate" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + if s.verbose != nil { + params.Set("verbose", fmt.Sprintf("%v", *s.verbose)) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *IngestSimulatePipelineService) Validate() error { + var invalid []string + if s.bodyString == "" && s.bodyJson == nil { + invalid = append(invalid, "BodyJson") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *IngestSimulatePipelineService) Do(ctx context.Context) (*IngestSimulatePipelineResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Setup HTTP request body + var body interface{} + if s.bodyJson != nil { + body = s.bodyJson + } else { + body = s.bodyString + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(IngestSimulatePipelineResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// IngestSimulatePipelineResponse is the response of IngestSimulatePipeline.Do. +type IngestSimulatePipelineResponse struct { + Docs []*IngestSimulateDocumentResult `json:"docs"` +} + +type IngestSimulateDocumentResult struct { + Doc map[string]interface{} `json:"doc"` + ProcessorResults []*IngestSimulateProcessorResult `json:"processor_results"` +} + +type IngestSimulateProcessorResult struct { + ProcessorTag string `json:"tag"` + Doc map[string]interface{} `json:"doc"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/inner_hit.go b/vendor/gopkg.in/olivere/elastic.v5/inner_hit.go similarity index 81% rename from vendor/gopkg.in/olivere/elastic.v3/inner_hit.go rename to vendor/gopkg.in/olivere/elastic.v5/inner_hit.go index 1330df1ee..c371fbf79 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/inner_hit.go +++ b/vendor/gopkg.in/olivere/elastic.v5/inner_hit.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -7,7 +7,7 @@ package elastic // InnerHit implements a simple join for parent/child, nested, and even // top-level documents in Elasticsearch. // It is an experimental feature for Elasticsearch versions 1.5 (or greater). -// See http://www.elastic.co/guide/en/elasticsearch/reference/1.5/search-request-inner-hits.html +// See http://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-inner-hits.html // for documentation. // // See the tests for SearchSource, HasChildFilter, HasChildQuery, @@ -66,18 +66,18 @@ func (hit *InnerHit) Version(version bool) *InnerHit { return hit } -func (hit *InnerHit) Field(fieldName string) *InnerHit { - hit.source.Field(fieldName) +func (hit *InnerHit) StoredField(storedFieldName string) *InnerHit { + hit.source.StoredField(storedFieldName) return hit } -func (hit *InnerHit) Fields(fieldNames ...string) *InnerHit { - hit.source.Fields(fieldNames...) +func (hit *InnerHit) StoredFields(storedFieldNames ...string) *InnerHit { + hit.source.StoredFields(storedFieldNames...) return hit } -func (hit *InnerHit) NoFields() *InnerHit { - hit.source.NoFields() +func (hit *InnerHit) NoStoredFields() *InnerHit { + hit.source.NoStoredFields() return hit } @@ -91,13 +91,13 @@ func (hit *InnerHit) FetchSourceContext(fetchSourceContext *FetchSourceContext) return hit } -func (hit *InnerHit) FieldDataFields(fieldDataFields ...string) *InnerHit { - hit.source.FieldDataFields(fieldDataFields...) +func (hit *InnerHit) DocvalueFields(docvalueFields ...string) *InnerHit { + hit.source.DocvalueFields(docvalueFields...) return hit } -func (hit *InnerHit) FieldDataField(fieldDataField string) *InnerHit { - hit.source.FieldDataField(fieldDataField) +func (hit *InnerHit) DocvalueField(docvalueField string) *InnerHit { + hit.source.DocvalueField(docvalueField) return hit } diff --git a/vendor/gopkg.in/olivere/elastic.v3/logger.go b/vendor/gopkg.in/olivere/elastic.v5/logger.go similarity index 80% rename from vendor/gopkg.in/olivere/elastic.v3/logger.go rename to vendor/gopkg.in/olivere/elastic.v5/logger.go index 0fb16b19f..095eb4cd4 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/logger.go +++ b/vendor/gopkg.in/olivere/elastic.v5/logger.go @@ -1,4 +1,4 @@ -// Copyright 2012-2016 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/mget.go b/vendor/gopkg.in/olivere/elastic.v5/mget.go similarity index 51% rename from vendor/gopkg.in/olivere/elastic.v3/mget.go rename to vendor/gopkg.in/olivere/elastic.v5/mget.go index fcb36dded..9e87abf3e 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/mget.go +++ b/vendor/gopkg.in/olivere/elastic.v5/mget.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -7,6 +7,9 @@ package elastic import ( "fmt" "net/url" + "strings" + + "golang.org/x/net/context" ) // MgetService allows to get multiple documents based on an index, @@ -14,38 +17,56 @@ import ( // a docs array with all the fetched documents, each element similar // in structure to a document provided by the Get API. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-multi-get.html // for details. type MgetService struct { - client *Client - pretty bool - preference string - realtime *bool - refresh *bool - items []*MultiGetItem + client *Client + pretty bool + preference string + realtime *bool + refresh string + routing string + storedFields []string + items []*MultiGetItem } +// NewMgetService initializes a new Multi GET API request call. func NewMgetService(client *Client) *MgetService { builder := &MgetService{ client: client, - items: make([]*MultiGetItem, 0), } return builder } -func (b *MgetService) Preference(preference string) *MgetService { - b.preference = preference - return b +// Preference specifies the node or shard the operation should be performed +// on (default: random). +func (s *MgetService) Preference(preference string) *MgetService { + s.preference = preference + return s } -func (b *MgetService) Refresh(refresh bool) *MgetService { - b.refresh = &refresh - return b +// Refresh the shard containing the document before performing the operation. +func (s *MgetService) Refresh(refresh string) *MgetService { + s.refresh = refresh + return s } -func (b *MgetService) Realtime(realtime bool) *MgetService { - b.realtime = &realtime - return b +// Realtime specifies whether to perform the operation in realtime or search mode. +func (s *MgetService) Realtime(realtime bool) *MgetService { + s.realtime = &realtime + return s +} + +// Routing is the specific routing value. +func (s *MgetService) Routing(routing string) *MgetService { + s.routing = routing + return s +} + +// StoredFields is a list of fields to return in the response. +func (s *MgetService) StoredFields(storedFields ...string) *MgetService { + s.storedFields = append(s.storedFields, storedFields...) + return s } // Pretty indicates that the JSON response be indented and human readable. @@ -54,15 +75,17 @@ func (s *MgetService) Pretty(pretty bool) *MgetService { return s } -func (b *MgetService) Add(items ...*MultiGetItem) *MgetService { - b.items = append(b.items, items...) - return b +// Add an item to the request. +func (s *MgetService) Add(items ...*MultiGetItem) *MgetService { + s.items = append(s.items, items...) + return s } -func (b *MgetService) Source() (interface{}, error) { +// Source returns the request body, which will be serialized into JSON. +func (s *MgetService) Source() (interface{}, error) { source := make(map[string]interface{}) - items := make([]interface{}, len(b.items)) - for i, item := range b.items { + items := make([]interface{}, len(s.items)) + for i, item := range s.items { src, err := item.Source() if err != nil { return nil, err @@ -73,36 +96,43 @@ func (b *MgetService) Source() (interface{}, error) { return source, nil } -func (b *MgetService) Do() (*MgetResponse, error) { +// Do executes the request. +func (s *MgetService) Do(ctx context.Context) (*MgetResponse, error) { // Build url path := "/_mget" params := make(url.Values) - if b.realtime != nil { - params.Add("realtime", fmt.Sprintf("%v", *b.realtime)) + if s.realtime != nil { + params.Add("realtime", fmt.Sprintf("%v", *s.realtime)) } - if b.preference != "" { - params.Add("preference", b.preference) + if s.preference != "" { + params.Add("preference", s.preference) } - if b.refresh != nil { - params.Add("refresh", fmt.Sprintf("%v", *b.refresh)) + if s.refresh != "" { + params.Add("refresh", s.refresh) + } + if s.routing != "" { + params.Set("routing", s.routing) + } + if len(s.storedFields) > 0 { + params.Set("stored_fields", strings.Join(s.storedFields, ",")) } // Set body - body, err := b.Source() + body, err := s.Source() if err != nil { return nil, err } // Get response - res, err := b.client.PerformRequest("GET", path, params, body) + res, err := s.client.PerformRequest(ctx, "GET", path, params, body) if err != nil { return nil, err } // Return result ret := new(MgetResponse) - if err := b.client.decoder.Decode(res.Body, ret); err != nil { + if err := s.client.decoder.Decode(res.Body, ret); err != nil { return nil, err } return ret, nil @@ -112,45 +142,48 @@ func (b *MgetService) Do() (*MgetResponse, error) { // MultiGetItem is a single document to retrieve via the MgetService. type MultiGetItem struct { - index string - typ string - id string - routing string - fields []string - version *int64 // see org.elasticsearch.common.lucene.uid.Versions - versionType string // see org.elasticsearch.index.VersionType - fsc *FetchSourceContext + index string + typ string + id string + routing string + storedFields []string + version *int64 // see org.elasticsearch.common.lucene.uid.Versions + versionType string // see org.elasticsearch.index.VersionType + fsc *FetchSourceContext } +// NewMultiGetItem initializes a new, single item for a Multi GET request. func NewMultiGetItem() *MultiGetItem { return &MultiGetItem{} } +// Index specifies the index name. func (item *MultiGetItem) Index(index string) *MultiGetItem { item.index = index return item } +// Type specifies the type name. func (item *MultiGetItem) Type(typ string) *MultiGetItem { item.typ = typ return item } +// Id specifies the identifier of the document. func (item *MultiGetItem) Id(id string) *MultiGetItem { item.id = id return item } +// Routing is the specific routing value. func (item *MultiGetItem) Routing(routing string) *MultiGetItem { item.routing = routing return item } -func (item *MultiGetItem) Fields(fields ...string) *MultiGetItem { - if item.fields == nil { - item.fields = make([]string, 0) - } - item.fields = append(item.fields, fields...) +// StoredFields is a list of fields to return in the response. +func (item *MultiGetItem) StoredFields(storedFields ...string) *MultiGetItem { + item.storedFields = append(item.storedFields, storedFields...) return item } @@ -170,6 +203,7 @@ func (item *MultiGetItem) VersionType(versionType string) *MultiGetItem { return item } +// FetchSource allows to specify source filtering. func (item *MultiGetItem) FetchSource(fetchSourceContext *FetchSourceContext) *MultiGetItem { item.fsc = fetchSourceContext return item @@ -195,12 +229,12 @@ func (item *MultiGetItem) Source() (interface{}, error) { } source["_source"] = src } - if item.fields != nil { - source["fields"] = item.fields - } if item.routing != "" { source["_routing"] = item.routing } + if len(item.storedFields) > 0 { + source["stored_fields"] = strings.Join(item.storedFields, ",") + } if item.version != nil { source["version"] = fmt.Sprintf("%d", *item.version) } @@ -213,6 +247,7 @@ func (item *MultiGetItem) Source() (interface{}, error) { // -- Result of a Multi Get request. +// MgetResponse is the outcome of a Multi GET API request. type MgetResponse struct { Docs []*GetResult `json:"docs,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v3/msearch.go b/vendor/gopkg.in/olivere/elastic.v5/msearch.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v3/msearch.go rename to vendor/gopkg.in/olivere/elastic.v5/msearch.go index ab0c7fd18..6866954d4 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/msearch.go +++ b/vendor/gopkg.in/olivere/elastic.v5/msearch.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,10 +9,11 @@ import ( "fmt" "net/url" "strings" + + "golang.org/x/net/context" ) // MultiSearch executes one or more searches in one roundtrip. -// See http://www.elasticsearch.org/guide/reference/api/multi-search/ type MultiSearchService struct { client *Client requests []*SearchRequest @@ -46,7 +47,7 @@ func (s *MultiSearchService) Pretty(pretty bool) *MultiSearchService { return s } -func (s *MultiSearchService) Do() (*MultiSearchResult, error) { +func (s *MultiSearchService) Do(ctx context.Context) (*MultiSearchResult, error) { // Build url path := "/_msearch" @@ -57,7 +58,7 @@ func (s *MultiSearchService) Do() (*MultiSearchResult, error) { } // Set body - lines := make([]string, 0) + var lines []string for _, sr := range s.requests { // Set default indices if not specified in the request if !sr.HasIndices() && len(s.indices) > 0 { @@ -78,7 +79,7 @@ func (s *MultiSearchService) Do() (*MultiSearchResult, error) { body := strings.Join(lines, "\n") + "\n" // Don't forget trailing \n // Get response - res, err := s.client.PerformRequest("GET", path, params, body) + res, err := s.client.PerformRequest(ctx, "GET", path, params, body) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/mtermvectors.go b/vendor/gopkg.in/olivere/elastic.v5/mtermvectors.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v3/mtermvectors.go rename to vendor/gopkg.in/olivere/elastic.v5/mtermvectors.go index 2dead3255..4017b9f32 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/mtermvectors.go +++ b/vendor/gopkg.in/olivere/elastic.v5/mtermvectors.go @@ -10,14 +10,16 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // MultiTermvectorService returns information and statistics on terms in the // fields of a particular document. The document could be stored in the // index or artificially provided by the user. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-multi-termvectors.html // for documentation. type MultiTermvectorService struct { client *Client @@ -254,7 +256,7 @@ func (s *MultiTermvectorService) Validate() error { } // Do executes the operation. -func (s *MultiTermvectorService) Do() (*MultiTermvectorResponse, error) { +func (s *MultiTermvectorService) Do(ctx context.Context) (*MultiTermvectorResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -277,7 +279,7 @@ func (s *MultiTermvectorService) Do() (*MultiTermvectorResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, body) + res, err := s.client.PerformRequest(ctx, "GET", path, params, body) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/nodes_info.go b/vendor/gopkg.in/olivere/elastic.v5/nodes_info.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v3/nodes_info.go rename to vendor/gopkg.in/olivere/elastic.v5/nodes_info.go index 29540f972..cb0f23e04 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/nodes_info.go +++ b/vendor/gopkg.in/olivere/elastic.v5/nodes_info.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -6,25 +6,18 @@ package elastic import ( "fmt" - "log" "net/url" "strings" "time" - "gopkg.in/olivere/elastic.v3/uritemplates" -) + "golang.org/x/net/context" -var ( - _ = fmt.Print - _ = log.Print - _ = strings.Index - _ = uritemplates.Expand - _ = url.Parse + "gopkg.in/olivere/elastic.v5/uritemplates" ) // NodesInfoService allows to retrieve one or more or all of the // cluster nodes information. -// It is documented at http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-info.html. +// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-nodes-info.html. type NodesInfoService struct { client *Client pretty bool @@ -108,7 +101,7 @@ func (s *NodesInfoService) Validate() error { } // Do executes the operation. -func (s *NodesInfoService) Do() (*NodesInfoResponse, error) { +func (s *NodesInfoService) Do(ctx context.Context) (*NodesInfoResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -121,7 +114,7 @@ func (s *NodesInfoService) Do() (*NodesInfoResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } @@ -171,7 +164,7 @@ type NodesInfoNode struct { Process *NodesInfoNodeProcess `json:"process"` // JVM information, e.g. VM version. - JVM *NodesInfoNodeProcess `json:"jvm"` + JVM *NodesInfoNodeJVM `json:"jvm"` // ThreadPool information. ThreadPool *NodesInfoNodeThreadPool `json:"thread_pool"` diff --git a/vendor/gopkg.in/olivere/elastic.v5/nodes_stats.go b/vendor/gopkg.in/olivere/elastic.v5/nodes_stats.go new file mode 100644 index 000000000..e93b39c40 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/nodes_stats.go @@ -0,0 +1,707 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "encoding/json" + "fmt" + "net/url" + "strings" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +// NodesStatsService returns node statistics. +// See http://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-nodes-stats.html +// for details. +type NodesStatsService struct { + client *Client + pretty bool + metric []string + indexMetric []string + nodeId []string + completionFields []string + fielddataFields []string + fields []string + groups *bool + human *bool + level string + timeout string + types []string +} + +// NewNodesStatsService creates a new NodesStatsService. +func NewNodesStatsService(client *Client) *NodesStatsService { + return &NodesStatsService{ + client: client, + } +} + +// Metric limits the information returned to the specified metrics. +func (s *NodesStatsService) Metric(metric ...string) *NodesStatsService { + s.metric = append(s.metric, metric...) + return s +} + +// IndexMetric limits the information returned for `indices` metric +// to the specific index metrics. Isn't used if `indices` (or `all`) +// metric isn't specified.. +func (s *NodesStatsService) IndexMetric(indexMetric ...string) *NodesStatsService { + s.indexMetric = append(s.indexMetric, indexMetric...) + return s +} + +// NodeId is a list of node IDs or names to limit the returned information; +// use `_local` to return information from the node you're connecting to, +// leave empty to get information from all nodes. +func (s *NodesStatsService) NodeId(nodeId ...string) *NodesStatsService { + s.nodeId = append(s.nodeId, nodeId...) + return s +} + +// CompletionFields is a list of fields for `fielddata` and `suggest` +// index metric (supports wildcards). +func (s *NodesStatsService) CompletionFields(completionFields ...string) *NodesStatsService { + s.completionFields = append(s.completionFields, completionFields...) + return s +} + +// FielddataFields is a list of fields for `fielddata` index metric (supports wildcards). +func (s *NodesStatsService) FielddataFields(fielddataFields ...string) *NodesStatsService { + s.fielddataFields = append(s.fielddataFields, fielddataFields...) + return s +} + +// Fields is a list of fields for `fielddata` and `completion` index metric (supports wildcards). +func (s *NodesStatsService) Fields(fields ...string) *NodesStatsService { + s.fields = append(s.fields, fields...) + return s +} + +// Groups is a list of search groups for `search` index metric. +func (s *NodesStatsService) Groups(groups bool) *NodesStatsService { + s.groups = &groups + return s +} + +// Human indicates whether to return time and byte values in human-readable format. +func (s *NodesStatsService) Human(human bool) *NodesStatsService { + s.human = &human + return s +} + +// Level specifies whether to return indices stats aggregated at node, index or shard level. +func (s *NodesStatsService) Level(level string) *NodesStatsService { + s.level = level + return s +} + +// Timeout specifies an explicit operation timeout. +func (s *NodesStatsService) Timeout(timeout string) *NodesStatsService { + s.timeout = timeout + return s +} + +// Types a list of document types for the `indexing` index metric. +func (s *NodesStatsService) Types(types ...string) *NodesStatsService { + s.types = append(s.types, types...) + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *NodesStatsService) Pretty(pretty bool) *NodesStatsService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *NodesStatsService) buildURL() (string, url.Values, error) { + var err error + var path string + + if len(s.nodeId) > 0 && len(s.metric) > 0 && len(s.indexMetric) > 0 { + path, err = uritemplates.Expand("/_nodes/{node_id}/stats/{metric}/{index_metric}", map[string]string{ + "index_metric": strings.Join(s.indexMetric, ","), + "node_id": strings.Join(s.nodeId, ","), + "metric": strings.Join(s.metric, ","), + }) + } else if len(s.nodeId) > 0 && len(s.metric) > 0 && len(s.indexMetric) == 0 { + path, err = uritemplates.Expand("/_nodes/{node_id}/stats/{metric}", map[string]string{ + "node_id": strings.Join(s.nodeId, ","), + "metric": strings.Join(s.metric, ","), + }) + } else if len(s.nodeId) > 0 && len(s.metric) == 0 && len(s.indexMetric) > 0 { + path, err = uritemplates.Expand("/_nodes/{node_id}/stats/_all/{index_metric}", map[string]string{ + "index_metric": strings.Join(s.indexMetric, ","), + "node_id": strings.Join(s.nodeId, ","), + }) + } else if len(s.nodeId) > 0 && len(s.metric) == 0 && len(s.indexMetric) == 0 { + path, err = uritemplates.Expand("/_nodes/{node_id}/stats", map[string]string{ + "node_id": strings.Join(s.nodeId, ","), + }) + } else if len(s.nodeId) == 0 && len(s.metric) > 0 && len(s.indexMetric) > 0 { + path, err = uritemplates.Expand("/_nodes/stats/{metric}/{index_metric}", map[string]string{ + "index_metric": strings.Join(s.indexMetric, ","), + "metric": strings.Join(s.metric, ","), + }) + } else if len(s.nodeId) == 0 && len(s.metric) > 0 && len(s.indexMetric) == 0 { + path, err = uritemplates.Expand("/_nodes/stats/{metric}", map[string]string{ + "metric": strings.Join(s.metric, ","), + }) + } else if len(s.nodeId) == 0 && len(s.metric) == 0 && len(s.indexMetric) > 0 { + path, err = uritemplates.Expand("/_nodes/stats/_all/{index_metric}", map[string]string{ + "index_metric": strings.Join(s.indexMetric, ","), + }) + } else { // if len(s.nodeId) == 0 && len(s.metric) == 0 && len(s.indexMetric) == 0 { + path = "/_nodes/stats" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + if len(s.completionFields) > 0 { + params.Set("completion_fields", strings.Join(s.completionFields, ",")) + } + if len(s.fielddataFields) > 0 { + params.Set("fielddata_fields", strings.Join(s.fielddataFields, ",")) + } + if len(s.fields) > 0 { + params.Set("fields", strings.Join(s.fields, ",")) + } + if s.groups != nil { + params.Set("groups", fmt.Sprintf("%v", *s.groups)) + } + if s.human != nil { + params.Set("human", fmt.Sprintf("%v", *s.human)) + } + if s.level != "" { + params.Set("level", s.level) + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + if len(s.types) > 0 { + params.Set("types", strings.Join(s.types, ",")) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *NodesStatsService) Validate() error { + return nil +} + +// Do executes the operation. +func (s *NodesStatsService) Do(ctx context.Context) (*NodesStatsResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(NodesStatsResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// NodesStatsResponse is the response of NodesStatsService.Do. +type NodesStatsResponse struct { + ClusterName string `json:"cluster_name"` + Nodes map[string]*NodesStatsNode `json:"nodes"` +} + +type NodesStatsNode struct { + // Timestamp when these stats we're gathered. + Timestamp int64 `json:"timestamp"` + // Name of the node, e.g. "Mister Fear" + Name string `json:"name"` + // TransportAddress, e.g. "127.0.0.1:9300" + TransportAddress string `json:"transport_address"` + // Host is the host name, e.g. "macbookair" + Host string `json:"host"` + // IP is an IP address, e.g. "192.168.1.2" + IP string `json:"ip"` + // Roles is a list of the roles of the node, e.g. master, data, ingest. + Roles []string `json:"roles"` + + // Attributes of the node. + Attributes map[string]interface{} `json:"attributes"` + + // Indices returns index information. + Indices *NodesStatsIndex `json:"indices"` + + // OS information, e.g. CPU and memory. + OS *NodesStatsNodeOS `json:"os"` + + // Process information, e.g. max file descriptors. + Process *NodesStatsNodeProcess `json:"process"` + + // JVM information, e.g. VM version. + JVM *NodesStatsNodeJVM `json:"jvm"` + + // ThreadPool information. + ThreadPool map[string]*NodesStatsNodeThreadPool `json:"thread_pool"` + + // FS returns information about the filesystem. + FS *NodesStatsNodeFS `json:"fs"` + + // Network information. + Transport *NodesStatsNodeTransport `json:"transport"` + + // HTTP information. + HTTP *NodesStatsNodeHTTP `json:"http"` + + // Breaker contains information about circuit breakers. + Breaker map[string]*NodesStatsBreaker `json:"breaker"` + + // ScriptStats information. + ScriptStats *NodesStatsScriptStats `json:"script"` + + // Discovery information. + Discovery *NodesStatsDiscovery `json:"discovery"` + + // Ingest information + Ingest *NodesStatsIngest `json:"ingest"` +} + +type NodesStatsIndex struct { + Docs *NodesStatsDocsStats `json:"docs"` + Store *NodesStatsStoreStats `json:"store"` + Indexing *NodesStatsIndexingStats `json:"indexing"` + Get *NodesStatsGetStats `json:"get"` + Search *NodesStatsSearchStats `json:"search"` + Merges *NodesStatsMergeStats `json:"merges"` + Refresh *NodesStatsRefreshStats `json:"refresh"` + Flush *NodesStatsFlushStats `json:"flush"` + Warmer *NodesStatsWarmerStats `json:"warmer"` + QueryCache *NodesStatsQueryCacheStats `json:"query_cache"` + Fielddata *NodesStatsFielddataStats `json:"fielddata"` + Percolate *NodesStatsPercolateStats `json:"percolate"` + Completion *NodesStatsCompletionStats `json:"completion"` + Segments *NodesStatsSegmentsStats `json:"segments"` + Translog *NodesStatsTranslogStats `json:"translog"` + Suggest *NodesStatsSuggestStats `json:"suggest"` + RequestCache *NodesStatsRequestCacheStats `json:"request_cache"` + Recovery NodesStatsRecoveryStats `json:"recovery"` + + Indices map[string]*NodesStatsIndex `json:"indices"` // for level=indices + Shards map[string]*NodesStatsIndex `json:"shards"` // for level=shards +} + +type NodesStatsDocsStats struct { + Count int64 `json:"count"` + Deleted int64 `json:"deleted"` +} + +type NodesStatsStoreStats struct { + Size string `json:"size"` + SizeInBytes int64 `json:"size_in_bytes"` + ThrottleTime string `json:"throttle_time"` + ThrottleTimeInMillis int64 `json:"throttle_time_in_millis"` +} + +type NodesStatsIndexingStats struct { + IndexTotal int64 `json:"index_total"` + IndexTime string `json:"index_time"` + IndexTimeInMillis int64 `json:"index_time_in_millis"` + IndexCurrent int64 `json:"index_current"` + IndexFailed int64 `json:"index_failed"` + DeleteTotal int64 `json:"delete_total"` + DeleteTime string `json:"delete_time"` + DeleteTimeInMillis int64 `json:"delete_time_in_millis"` + DeleteCurrent int64 `json:"delete_current"` + NoopUpdateTotal int64 `json:"noop_update_total"` + IsThrottled bool `json:"is_throttled"` + ThrottleTime string `json:"throttle_time"` + ThrottleTimeInMillis int64 `json:"throttle_time_in_millis"` + + Types map[string]*NodesStatsIndexingStats `json:"types"` // stats for individual types +} + +type NodesStatsGetStats struct { + Total int64 `json:"total"` + Time string `json:"get_time"` + TimeInMillis int64 `json:"time_in_millis"` + Exists int64 `json:"exists"` + ExistsTime string `json:"exists_time"` + ExistsTimeInMillis int64 `json:"exists_in_millis"` + Missing int64 `json:"missing"` + MissingTime string `json:"missing_time"` + MissingTimeInMillis int64 `json:"missing_in_millis"` + Current int64 `json:"current"` +} + +type NodesStatsSearchStats struct { + OpenContexts int64 `json:"open_contexts"` + QueryTotal int64 `json:"query_total"` + QueryTime string `json:"query_time"` + QueryTimeInMillis int64 `json:"query_time_in_millis"` + QueryCurrent int64 `json:"query_current"` + FetchTotal int64 `json:"fetch_total"` + FetchTime string `json:"fetch_time"` + FetchTimeInMillis int64 `json:"fetch_time_in_millis"` + FetchCurrent int64 `json:"fetch_current"` + ScrollTotal int64 `json:"scroll_total"` + ScrollTime string `json:"scroll_time"` + ScrollTimeInMillis int64 `json:"scroll_time_in_millis"` + ScrollCurrent int64 `json:"scroll_current"` + + Groups map[string]*NodesStatsSearchStats `json:"groups"` // stats for individual groups +} + +type NodesStatsMergeStats struct { + Current int64 `json:"current"` + CurrentDocs int64 `json:"current_docs"` + CurrentSize string `json:"current_size"` + CurrentSizeInBytes int64 `json:"current_size_in_bytes"` + Total int64 `json:"total"` + TotalTime string `json:"total_time"` + TotalTimeInMillis int64 `json:"total_time_in_millis"` + TotalDocs int64 `json:"total_docs"` + TotalSize string `json:"total_size"` + TotalSizeInBytes int64 `json:"total_size_in_bytes"` + TotalStoppedTime string `json:"total_stopped_time"` + TotalStoppedTimeInMillis int64 `json:"total_stopped_time_in_millis"` + TotalThrottledTime string `json:"total_throttled_time"` + TotalThrottledTimeInMillis int64 `json:"total_throttled_time_in_millis"` + TotalThrottleBytes string `json:"total_auto_throttle"` + TotalThrottleBytesInBytes int64 `json:"total_auto_throttle_in_bytes"` +} + +type NodesStatsRefreshStats struct { + Total int64 `json:"total"` + TotalTime string `json:"total_time"` + TotalTimeInMillis int64 `json:"total_time_in_millis"` +} + +type NodesStatsFlushStats struct { + Total int64 `json:"total"` + TotalTime string `json:"total_time"` + TotalTimeInMillis int64 `json:"total_time_in_millis"` +} + +type NodesStatsWarmerStats struct { + Current int64 `json:"current"` + Total int64 `json:"total"` + TotalTime string `json:"total_time"` + TotalTimeInMillis int64 `json:"total_time_in_millis"` +} + +type NodesStatsQueryCacheStats struct { + MemorySize string `json:"memory_size"` + MemorySizeInBytes int64 `json:"memory_size_in_bytes"` + TotalCount int64 `json:"total_count"` + HitCount int64 `json:"hit_count"` + MissCount int64 `json:"miss_count"` + CacheSize int64 `json:"cache_size"` + CacheCount int64 `json:"cache_count"` + Evictions int64 `json:"evictions"` +} + +type NodesStatsFielddataStats struct { + MemorySize string `json:"memory_size"` + MemorySizeInBytes int64 `json:"memory_size_in_bytes"` + Evictions int64 `json:"evictions"` + Fields map[string]struct { + MemorySize string `json:"memory_size"` + MemorySizeInBytes int64 `json:"memory_size_in_bytes"` + } `json:"fields"` +} + +type NodesStatsPercolateStats struct { + Total int64 `json:"total"` + Time string `json:"time"` + TimeInMillis int64 `json:"time_in_millis"` + Current int64 `json:"current"` + MemorySize string `json:"memory_size"` + MemorySizeInBytes int64 `json:"memory_size_in_bytes"` + Queries int64 `json:"queries"` +} + +type NodesStatsCompletionStats struct { + Size string `json:"size"` + SizeInBytes int64 `json:"size_in_bytes"` + Fields map[string]struct { + Size string `json:"size"` + SizeInBytes int64 `json:"size_in_bytes"` + } `json:"fields"` +} + +type NodesStatsSegmentsStats struct { + Count int64 `json:"count"` + Memory string `json:"memory"` + MemoryInBytes int64 `json:"memory_in_bytes"` + TermsMemory string `json:"terms_memory"` + TermsMemoryInBytes int64 `json:"terms_memory_in_bytes"` + StoredFieldsMemory string `json:"stored_fields_memory"` + StoredFieldsMemoryInBytes int64 `json:"stored_fields_memory_in_bytes"` + TermVectorsMemory string `json:"term_vectors_memory"` + TermVectorsMemoryInBytes int64 `json:"term_vectors_memory_in_bytes"` + NormsMemory string `json:"norms_memory"` + NormsMemoryInBytes int64 `json:"norms_memory_in_bytes"` + DocValuesMemory string `json:"doc_values_memory"` + DocValuesMemoryInBytes int64 `json:"doc_values_memory_in_bytes"` + IndexWriterMemory string `json:"index_writer_memory"` + IndexWriterMemoryInBytes int64 `json:"index_writer_memory_in_bytes"` + IndexWriterMaxMemory string `json:"index_writer_max_memory"` + IndexWriterMaxMemoryInBytes int64 `json:"index_writer_max_memory_in_bytes"` + VersionMapMemory string `json:"version_map_memory"` + VersionMapMemoryInBytes int64 `json:"version_map_memory_in_bytes"` + FixedBitSetMemory string `json:"fixed_bit_set"` // not a typo + FixedBitSetMemoryInBytes int64 `json:"fixed_bit_set_memory_in_bytes"` +} + +type NodesStatsTranslogStats struct { + Operations int64 `json:"operations"` + Size string `json:"size"` + SizeInBytes int64 `json:"size_in_bytes"` +} + +type NodesStatsSuggestStats struct { + Total int64 `json:"total"` + TotalTime string `json:"total_time"` + TotalTimeInMillis int64 `json:"total_time_in_millis"` + Current int64 `json:"current"` +} + +type NodesStatsRequestCacheStats struct { + MemorySize string `json:"memory_size"` + MemorySizeInBytes int64 `json:"memory_size_in_bytes"` + Evictions int64 `json:"evictions"` + HitCount int64 `json:"hit_count"` + MissCount int64 `json:"miss_count"` +} + +type NodesStatsRecoveryStats struct { + CurrentAsSource int `json:"current_as_source"` + CurrentAsTarget int `json:"current_as_target"` + ThrottleTime string `json:"throttle_time"` + ThrottleTimeInMillis int64 `json:"throttle_time_in_millis"` +} + +type NodesStatsNodeOS struct { + Timestamp int64 `json:"timestamp"` + CPU *NodesStatsNodeOSCPU `json:"cpu"` + Mem *NodesStatsNodeOSMem `json:"mem"` + Swap *NodesStatsNodeOSSwap `json:"swap"` +} + +type NodesStatsNodeOSCPU struct { + Percent int `json:"percent"` + LoadAverage map[string]float64 `json:"load_average"` // keys are: 1m, 5m, and 15m +} + +type NodesStatsNodeOSMem struct { + Total string `json:"total"` + TotalInBytes int64 `json:"total_in_bytes"` + Free string `json:"free"` + FreeInBytes int64 `json:"free_in_bytes"` + Used string `json:"used"` + UsedInBytes int64 `json:"used_in_bytes"` + FreePercent int `json:"free_percent"` + UsedPercent int `json:"used_percent"` +} + +type NodesStatsNodeOSSwap struct { + Total string `json:"total"` + TotalInBytes int64 `json:"total_in_bytes"` + Free string `json:"free"` + FreeInBytes int64 `json:"free_in_bytes"` + Used string `json:"used"` + UsedInBytes int64 `json:"used_in_bytes"` +} + +type NodesStatsNodeProcess struct { + Timestamp int64 `json:"timestamp"` + OpenFileDescriptors int64 `json:"open_file_descriptors"` + MaxFileDescriptors int64 `json:"max_file_descriptors"` + CPU struct { + Percent int `json:"percent"` + Total string `json:"total"` + TotalInMillis int64 `json:"total_in_millis"` + } `json:"cpu"` + Mem struct { + TotalVirtual string `json:"total_virtual"` + TotalVirtualInBytes int64 `json:"total_virtual_in_bytes"` + } `json:"mem"` +} + +type NodesStatsNodeJVM struct { + Timestamp int64 `json:"timestamp"` + Uptime string `json:"uptime"` + UptimeInMillis int64 `json:"uptime_in_millis"` + Mem *NodesStatsNodeJVMMem `json:"mem"` + Threads *NodesStatsNodeJVMThreads `json:"threads"` + GC *NodesStatsNodeJVMGC `json:"gc"` + BufferPools map[string]*NodesStatsNodeJVMBufferPool `json:"buffer_pools"` + Classes *NodesStatsNodeJVMClasses `json:"classes"` +} + +type NodesStatsNodeJVMMem struct { + HeapUsed string `json:"heap_used"` + HeapUsedInBytes int64 `json:"heap_used_in_bytes"` + HeapUsedPercent int `json:"heap_used_percent"` + HeapCommitted string `json:"heap_committed"` + HeapCommittedInBytes int64 `json:"heap_committed_in_bytes"` + HeapMax string `json:"heap_max"` + HeapMaxInBytes int64 `json:"heap_max_in_bytes"` + NonHeapUsed string `json:"non_heap_used"` + NonHeapUsedInBytes int64 `json:"non_heap_used_in_bytes"` + NonHeapCommitted string `json:"non_heap_committed"` + NonHeapCommittedInBytes int64 `json:"non_heap_committed_in_bytes"` + Pools map[string]struct { + Used string `json:"used"` + UsedInBytes int64 `json:"used_in_bytes"` + Max string `json:"max"` + MaxInBytes int64 `json:"max_in_bytes"` + PeakUsed string `json:"peak_used"` + PeakUsedInBytes int64 `json:"peak_used_in_bytes"` + PeakMax string `json:"peak_max"` + PeakMaxInBytes int64 `json:"peak_max_in_bytes"` + } `json:"pools"` +} + +type NodesStatsNodeJVMThreads struct { + Count int64 `json:"count"` + PeakCount int64 `json:"peak_count"` +} + +type NodesStatsNodeJVMGC struct { + Collectors map[string]*NodesStatsNodeJVMGCCollector `json:"collectors"` +} + +type NodesStatsNodeJVMGCCollector struct { + CollectionCount int64 `json:"collection_count"` + CollectionTime string `json:"collection_time"` + CollectionTimeInMillis int64 `json:"collection_time_in_millis"` +} + +type NodesStatsNodeJVMBufferPool struct { + Count int64 `json:"count"` + TotalCapacity string `json:"total_capacity"` + TotalCapacityInBytes int64 `json:"total_capacity_in_bytes"` +} + +type NodesStatsNodeJVMClasses struct { + CurrentLoadedCount int64 `json:"current_loaded_count"` + TotalLoadedCount int64 `json:"total_loaded_count"` + TotalUnloadedCount int64 `json:"total_unloaded_count"` +} + +type NodesStatsNodeThreadPool struct { + Threads int `json:"threads"` + Queue int `json:"queue"` + Active int `json:"active"` + Rejected int64 `json:"rejected"` + Largest int `json:"largest"` + Completed int64 `json:"completed"` +} + +type NodesStatsNodeFS struct { + Timestamp int64 `json:"timestamp"` + Total *NodesStatsNodeFSEntry `json:"total"` + Data []*NodesStatsNodeFSEntry `json:"data"` + IOStats *NodesStatsNodeFSIOStats `json:"io_stats"` +} + +type NodesStatsNodeFSEntry struct { + Path string `json:"path"` + Mount string `json:"mount"` + Type string `json:"type"` + Total string `json:"total"` + TotalInBytes int64 `json:"total_in_bytes"` + Free string `json:"free"` + FreeInBytes int64 `json:"free_in_bytes"` + Available string `json:"available"` + AvailableInBytes int64 `json:"available_in_bytes"` + Spins string `json:"spins"` +} + +type NodesStatsNodeFSIOStats struct { + Devices []*NodesStatsNodeFSIOStatsEntry `json:"devices"` + Total *NodesStatsNodeFSIOStatsEntry `json:"total"` +} + +type NodesStatsNodeFSIOStatsEntry struct { + DeviceName string `json:"device_name"` + Operations int64 `json:"operations"` + ReadOperations int64 `json:"read_operations"` + WriteOperations int64 `json:"write_operations"` + ReadKilobytes int64 `json:"read_kilobytes"` + WriteKilobytes int64 `json:"write_kilobytes"` +} + +type NodesStatsNodeTransport struct { + ServerOpen int `json:"server_open"` + RxCount int64 `json:"rx_count"` + RxSize string `json:"rx_size"` + RxSizeInBytes int64 `json:"rx_size_in_bytes"` + TxCount int64 `json:"tx_count"` + TxSize string `json:"tx_size"` + TxSizeInBytes int64 `json:"tx_size_in_bytes"` +} + +type NodesStatsNodeHTTP struct { + CurrentOpen int `json:"current_open"` + TotalOpened int `json:"total_opened"` +} + +type NodesStatsBreaker struct { + LimitSize string `json:"limit_size"` + LimitSizeInBytes int64 `json:"limit_size_in_bytes"` + EstimatedSize string `json:"estimated_size"` + EstimatedSizeInBytes int64 `json:"estimated_size_in_bytes"` + Overhead float64 `json:"overhead"` + Tripped int64 `json:"tripped"` +} + +type NodesStatsScriptStats struct { + Compilations int64 `json:"compilations"` + CacheEvictions int64 `json:"cache_evictions"` +} + +type NodesStatsDiscovery struct { + ClusterStateQueue *NodesStatsDiscoveryStats `json:"cluster_state_queue"` +} + +type NodesStatsDiscoveryStats struct { + Total int64 `json:"total"` + Pending int64 `json:"pending"` + Committed int64 `json:"committed"` +} + +type NodesStatsIngest struct { + Total *NodesStatsIngestStats `json:"total"` + Pipelines interface{} `json:"pipelines"` +} + +type NodesStatsIngestStats struct { + Count int64 `json:"count"` + Time string `json:"time"` + TimeInMillis int64 `json:"time_in_millis"` + Current int64 `json:"current"` + Failed int64 `json:"failed"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/ping.go b/vendor/gopkg.in/olivere/elastic.v5/ping.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/ping.go rename to vendor/gopkg.in/olivere/elastic.v5/ping.go index fada22817..5ec7f0f9a 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/ping.go +++ b/vendor/gopkg.in/olivere/elastic.v5/ping.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,6 +8,9 @@ import ( "encoding/json" "net/http" "net/url" + + "golang.org/x/net/context" + "golang.org/x/net/context/ctxhttp" ) // PingService checks if an Elasticsearch server on a given URL is alive. @@ -71,7 +74,7 @@ func (s *PingService) Pretty(pretty bool) *PingService { // Do returns the PingResult, the HTTP status code of the Elasticsearch // server, and an error. -func (s *PingService) Do() (*PingResult, int, error) { +func (s *PingService) Do(ctx context.Context) (*PingResult, int, error) { s.client.mu.RLock() basicAuth := s.client.basicAuth basicAuthUsername := s.client.basicAuthUsername @@ -108,7 +111,7 @@ func (s *PingService) Do() (*PingResult, int, error) { req.SetBasicAuth(basicAuthUsername, basicAuthPassword) } - res, err := s.client.c.Do((*http.Request)(req)) + res, err := ctxhttp.Do(ctx, s.client.c, (*http.Request)(req)) if err != nil { return nil, 0, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/plugins.go b/vendor/gopkg.in/olivere/elastic.v5/plugins.go similarity index 83% rename from vendor/gopkg.in/olivere/elastic.v3/plugins.go rename to vendor/gopkg.in/olivere/elastic.v5/plugins.go index 3906d74d7..a46ac3748 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/plugins.go +++ b/vendor/gopkg.in/olivere/elastic.v5/plugins.go @@ -1,9 +1,11 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. package elastic +import "golang.org/x/net/context" + // HasPlugin indicates whether the cluster has the named plugin. func (c *Client) HasPlugin(name string) (bool, error) { plugins, err := c.Plugins() @@ -20,7 +22,7 @@ func (c *Client) HasPlugin(name string) (bool, error) { // Plugins returns the list of all registered plugins. func (c *Client) Plugins() ([]string, error) { - stats, err := c.ClusterStats().Do() + stats, err := c.ClusterStats().Do(context.Background()) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_template.go b/vendor/gopkg.in/olivere/elastic.v5/put_template.go similarity index 84% rename from vendor/gopkg.in/olivere/elastic.v3/search_template.go rename to vendor/gopkg.in/olivere/elastic.v5/put_template.go index ee8809005..23e2bbb10 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_template.go +++ b/vendor/gopkg.in/olivere/elastic.v5/put_template.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,12 +8,14 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // PutTemplateService creates or updates a search template. // The documentation can be found at -// http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html. +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html. type PutTemplateService struct { client *Client pretty bool @@ -109,7 +111,7 @@ func (s *PutTemplateService) Validate() error { } // Do executes the operation. -func (s *PutTemplateService) Do() (*PutTemplateResponse, error) { +func (s *PutTemplateService) Do(ctx context.Context) (*AcknowledgedResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -130,22 +132,15 @@ func (s *PutTemplateService) Do() (*PutTemplateResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("PUT", path, params, body) + res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) if err != nil { return nil, err } // Return operation response - ret := new(PutTemplateResponse) + ret := new(AcknowledgedResponse) if err := s.client.decoder.Decode(res.Body, ret); err != nil { return nil, err } return ret, nil } - -// PutTemplateResponse is the response of PutTemplateService.Do. -type PutTemplateResponse struct { - Id string `json:"_id"` - Version int `json:"_version"` - Created bool `json:"created"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/query.go b/vendor/gopkg.in/olivere/elastic.v5/query.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v3/query.go rename to vendor/gopkg.in/olivere/elastic.v5/query.go index 0869eaecc..ad01354a0 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/query.go +++ b/vendor/gopkg.in/olivere/elastic.v5/query.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/reindex.go b/vendor/gopkg.in/olivere/elastic.v5/reindex.go similarity index 79% rename from vendor/gopkg.in/olivere/elastic.v3/reindex.go rename to vendor/gopkg.in/olivere/elastic.v5/reindex.go index 663bf25a6..5cab1695f 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/reindex.go +++ b/vendor/gopkg.in/olivere/elastic.v5/reindex.go @@ -7,29 +7,26 @@ package elastic import ( "fmt" "net/url" + + "golang.org/x/net/context" ) // ReindexService is a method to copy documents from one index to another. -// It was introduced in Elasticsearch 2.3.0. -// -// Notice that Elastic already had a Reindexer service that pre-dated -// the Reindex API. Use that if you're on an earlier version of Elasticsearch. -// -// It is documented at https://www.elastic.co/guide/en/elasticsearch/plugins/master/plugins-reindex.html. +// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.0/docs-reindex.html. type ReindexService struct { - client *Client - pretty bool - consistency string - refresh *bool - timeout string - waitForCompletion *bool - bodyJson interface{} - bodyString string - source *ReindexSource - destination *ReindexDestination - conflicts string - size *int - script *Script + client *Client + pretty bool + refresh string + timeout string + waitForActiveShards string + waitForCompletion *bool + requestsPerSecond *int + body interface{} + source *ReindexSource + destination *ReindexDestination + conflicts string + size *int + script *Script } // NewReindexService creates a new ReindexService. @@ -39,16 +36,26 @@ func NewReindexService(client *Client) *ReindexService { } } -// Consistency specifies an explicit write consistency setting for the operation. -func (s *ReindexService) Consistency(consistency string) *ReindexService { - s.consistency = consistency +// WaitForActiveShards sets the number of shard copies that must be active before +// proceeding with the reindex operation. Defaults to 1, meaning the primary shard only. +// Set to `all` for all shard copies, otherwise set to any non-negative value less than or +// equal to the total number of copies for the shard (number of replicas + 1). +func (s *ReindexService) WaitForActiveShards(waitForActiveShards string) *ReindexService { + s.waitForActiveShards = waitForActiveShards + return s +} + +// RequestsPerSecond specifies the throttle to set on this request in sub-requests per second. +// -1 means set no throttle as does "unlimited" which is the only non-float this accepts. +func (s *ReindexService) RequestsPerSecond(requestsPerSecond int) *ReindexService { + s.requestsPerSecond = &requestsPerSecond return s } // Refresh indicates whether Elasticsearch should refresh the effected indexes // immediately. -func (s *ReindexService) Refresh(refresh bool) *ReindexService { - s.refresh = &refresh +func (s *ReindexService) Refresh(refresh string) *ReindexService { + s.refresh = refresh return s } @@ -147,18 +154,10 @@ func (s *ReindexService) Script(script *Script) *ReindexService { return s } -// BodyJson specifies e.g. the query to restrict the results specified with the -// Query DSL (optional). The interface{} will be serialized to a JSON document, -// so use a map[string]interface{}. -func (s *ReindexService) BodyJson(body interface{}) *ReindexService { - s.bodyJson = body - return s -} - -// Body specifies e.g. a query to restrict the results specified with -// the Query DSL (optional). -func (s *ReindexService) BodyString(body string) *ReindexService { - s.bodyString = body +// Body specifies the body of the request to send to Elasticsearch. +// It overrides settings specified with other setters, e.g. Query. +func (s *ReindexService) Body(body interface{}) *ReindexService { + s.body = body return s } @@ -172,15 +171,18 @@ func (s *ReindexService) buildURL() (string, url.Values, error) { if s.pretty { params.Set("pretty", "1") } - if s.consistency != "" { - params.Set("consistency", s.consistency) - } - if s.refresh != nil { - params.Set("refresh", fmt.Sprintf("%v", *s.refresh)) + if s.refresh != "" { + params.Set("refresh", s.refresh) } if s.timeout != "" { params.Set("timeout", s.timeout) } + if s.requestsPerSecond != nil { + params.Set("requests_per_second", fmt.Sprintf("%v", *s.requestsPerSecond)) + } + if s.waitForActiveShards != "" { + params.Set("wait_for_active_shards", s.waitForActiveShards) + } if s.waitForCompletion != nil { params.Set("wait_for_completion", fmt.Sprintf("%v", *s.waitForCompletion)) } @@ -190,6 +192,9 @@ func (s *ReindexService) buildURL() (string, url.Values, error) { // Validate checks if the operation is valid. func (s *ReindexService) Validate() error { var invalid []string + if s.body != nil { + return nil + } if s.source == nil { invalid = append(invalid, "Source") } else { @@ -206,13 +211,10 @@ func (s *ReindexService) Validate() error { return nil } -// body returns the body part of the document request. -func (s *ReindexService) body() (interface{}, error) { - if s.bodyJson != nil { - return s.bodyJson, nil - } - if s.bodyString != "" { - return s.bodyString, nil +// getBody returns the body part of the document request. +func (s *ReindexService) getBody() (interface{}, error) { + if s.body != nil { + return s.body, nil } body := make(map[string]interface{}) @@ -247,7 +249,7 @@ func (s *ReindexService) body() (interface{}, error) { } // Do executes the operation. -func (s *ReindexService) Do() (*ReindexResponse, error) { +func (s *ReindexService) Do(ctx context.Context) (*BulkIndexByScrollResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -260,41 +262,25 @@ func (s *ReindexService) Do() (*ReindexResponse, error) { } // Setup HTTP request body - body, err := s.body() + body, err := s.getBody() if err != nil { return nil, err } // Get HTTP response - res, err := s.client.PerformRequest("POST", path, params, body) + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) if err != nil { return nil, err } // Return operation response - ret := new(ReindexResponse) + ret := new(BulkIndexByScrollResponse) if err := s.client.decoder.Decode(res.Body, ret); err != nil { return nil, err } return ret, nil } -// ReindexResponse is the response of ReindexService.Do. -type ReindexResponse struct { - Took interface{} `json:"took"` // 2.3.0 returns "37.7ms" while 2.2 returns 38 for took - TimedOut bool `json:"timed_out"` - Total int64 `json:"total"` - Updated int64 `json:"updated"` - Created int64 `json:"created"` - Deleted int64 `json:"deleted"` - Batches int64 `json:"batches"` - VersionConflicts int64 `json:"version_conflicts"` - Noops int64 `json:"noops"` - Retries int64 `json:"retries"` - Canceled string `json:"canceled"` - Failures []shardOperationFailure `json:"failures"` -} - // -- Source of Reindex -- // ReindexSource specifies the source of a Reindex process. @@ -314,12 +300,7 @@ type ReindexSource struct { // NewReindexSource creates a new ReindexSource. func NewReindexSource() *ReindexSource { - return &ReindexSource{ - indices: make([]string, 0), - types: make([]string, 0), - sorts: make([]SortInfo, 0), - sorters: make([]Sorter, 0), - } + return &ReindexSource{} } // SearchType is the search operation type. Possible values are @@ -436,7 +417,7 @@ func (r *ReindexSource) Source() (interface{}, error) { } if len(r.sorters) > 0 { - sortarr := make([]interface{}, 0) + var sortarr []interface{} for _, sorter := range r.sorters { src, err := sorter.Source() if err != nil { @@ -446,7 +427,7 @@ func (r *ReindexSource) Source() (interface{}, error) { } source["sort"] = sortarr } else if len(r.sorts) > 0 { - sortarr := make([]interface{}, 0) + var sortarr []interface{} for _, sort := range r.sorts { src, err := sort.Source() if err != nil { @@ -465,7 +446,7 @@ func (r *ReindexSource) Source() (interface{}, error) { // ReindexDestination is the destination of a Reindex API call. // It is basically the meta data of a BulkIndexRequest. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/2.3/docs-reindex.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-reindex.html // fsourcer details. type ReindexDestination struct { index string @@ -524,7 +505,7 @@ func (r *ReindexDestination) Parent(parent string) *ReindexDestination { // OpType specifies if this request should follow create-only or upsert // behavior. This follows the OpType of the standard document index API. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#operation-type +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html#operation-type // for details. func (r *ReindexDestination) OpType(opType string) *ReindexDestination { r.opType = opType diff --git a/vendor/gopkg.in/olivere/elastic.v3/request.go b/vendor/gopkg.in/olivere/elastic.v5/request.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v3/request.go rename to vendor/gopkg.in/olivere/elastic.v5/request.go index 1347e1b6f..e0e71b5e3 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/request.go +++ b/vendor/gopkg.in/olivere/elastic.v5/request.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/rescore.go b/vendor/gopkg.in/olivere/elastic.v5/rescore.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v3/rescore.go rename to vendor/gopkg.in/olivere/elastic.v5/rescore.go index 0cbc06710..9b7eaee1d 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/rescore.go +++ b/vendor/gopkg.in/olivere/elastic.v5/rescore.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/rescorer.go b/vendor/gopkg.in/olivere/elastic.v5/rescorer.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v3/rescorer.go rename to vendor/gopkg.in/olivere/elastic.v5/rescorer.go index 28ad59cbb..ccd4bb854 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/rescorer.go +++ b/vendor/gopkg.in/olivere/elastic.v5/rescorer.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/response.go b/vendor/gopkg.in/olivere/elastic.v5/response.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/response.go rename to vendor/gopkg.in/olivere/elastic.v5/response.go index 9426c23af..e7380d98a 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/response.go +++ b/vendor/gopkg.in/olivere/elastic.v5/response.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v5/retrier.go b/vendor/gopkg.in/olivere/elastic.v5/retrier.go new file mode 100644 index 000000000..b0d4e9ca4 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/retrier.go @@ -0,0 +1,62 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "net/http" + "time" + + "golang.org/x/net/context" +) + +// RetrierFunc specifies the signature of a Retry function. +type RetrierFunc func(context.Context, int, *http.Request, *http.Response, error) (time.Duration, bool, error) + +// Retrier decides whether to retry a failed HTTP request with Elasticsearch. +type Retrier interface { + // Retry is called when a request has failed. It decides whether to retry + // the call, how long to wait for the next call, or whether to return an + // error (which will be returned to the service that started the HTTP + // request in the first place). + // + // Callers may also use this to inspect the HTTP request/response and + // the error that happened. Additional data can be passed through via + // the context. + Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error) +} + +// -- StopRetrier -- + +// StopRetrier is an implementation that does no retries. +type StopRetrier struct { +} + +// NewStopRetrier returns a retrier that does no retries. +func NewStopRetrier() *StopRetrier { + return &StopRetrier{} +} + +// Retry does not retry. +func (r *StopRetrier) Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error) { + return 0, false, nil +} + +// -- BackoffRetrier -- + +// BackoffRetrier is an implementation that does nothing but return nil on Retry. +type BackoffRetrier struct { + backoff Backoff +} + +// NewBackoffRetrier returns a retrier that uses the given backoff strategy. +func NewBackoffRetrier(backoff Backoff) *BackoffRetrier { + return &BackoffRetrier{backoff: backoff} +} + +// Retry calls into the backoff strategy and its wait interval. +func (r *BackoffRetrier) Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error) { + wait, goahead := r.backoff.Next(retry) + return wait, goahead, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/backoff/retry.go b/vendor/gopkg.in/olivere/elastic.v5/retry.go similarity index 69% rename from vendor/gopkg.in/olivere/elastic.v3/backoff/retry.go rename to vendor/gopkg.in/olivere/elastic.v5/retry.go index 701e03ccc..3571a3b7a 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/backoff/retry.go +++ b/vendor/gopkg.in/olivere/elastic.v5/retry.go @@ -1,11 +1,11 @@ -// Copyright 2012-2016 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. -// This file is (c) 2014 Cenk Altı and governed by the MIT license. +// This file is based on code (c) 2014 Cenk Altı and governed by the MIT license. // See https://github.com/cenkalti/backoff for original source. -package backoff +package elastic import "time" @@ -13,12 +13,12 @@ import "time" // The operation will be retried using a backoff policy if it returns an error. type Operation func() error -// Notify is a notify-on-error function. It receives an operation error and -// backoff delay if the operation failed (with an error). +// Notify is a notify-on-error function. It receives error returned +// from an operation. // -// NOTE that if the backoff policy stated to stop retrying, +// Notice that if the backoff policy stated to stop retrying, // the notify function isn't called. -type Notify func(error, time.Duration) +type Notify func(error) // Retry the function f until it does not return error or BackOff stops. // f is guaranteed to be run at least once. @@ -32,22 +32,25 @@ func Retry(o Operation, b Backoff) error { return RetryNotify(o, b, nil) } // for each failed attempt before sleep. func RetryNotify(operation Operation, b Backoff, notify Notify) error { var err error - var next time.Duration + var wait time.Duration + var retry bool + var n int - b.Reset() for { if err = operation(); err == nil { return nil } - if next = b.Next(); next == Stop { + n++ + wait, retry = b.Next(n) + if !retry { return err } if notify != nil { - notify(err, next) + notify(err) } - time.Sleep(next) + time.Sleep(wait) } } diff --git a/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0-beta1.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0-beta1.sh new file mode 100755 index 000000000..08c67ea17 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0-beta1.sh @@ -0,0 +1 @@ +docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/config:/usr/share/elasticsearch/config" -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:5.0.0-beta1 elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0-rc1.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0-rc1.sh new file mode 100755 index 000000000..d4586acca --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0-rc1.sh @@ -0,0 +1 @@ +docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/config:/usr/share/elasticsearch/config" -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:5.0.0-rc1 elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0.sh new file mode 100755 index 000000000..e7a98c8fc --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.0.sh @@ -0,0 +1 @@ +docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/config:/usr/share/elasticsearch/config" -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:5.0.0 elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.1.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.1.sh new file mode 100755 index 000000000..528670211 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.0.1.sh @@ -0,0 +1 @@ +docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/config:/usr/share/elasticsearch/config" -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:5.0.1 elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v5/run-es-5.1.1.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.1.1.sh new file mode 100755 index 000000000..b15b57113 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.1.1.sh @@ -0,0 +1 @@ +docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/config:/usr/share/elasticsearch/config" -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:5.1.1 elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v5/run-es-5.1.2.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.1.2.sh new file mode 100755 index 000000000..66c85e58a --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.1.2.sh @@ -0,0 +1 @@ +docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/config:/usr/share/elasticsearch/config" -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:5.1.2 elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.0.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.0.sh new file mode 100755 index 000000000..417d283a7 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.0.sh @@ -0,0 +1 @@ +docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/config:/usr/share/elasticsearch/config" -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:5.2.0 elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.1.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.1.sh new file mode 100755 index 000000000..6d0d5dd70 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.1.sh @@ -0,0 +1 @@ +docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/config:/usr/share/elasticsearch/config" -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:5.2.1 elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.2.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.2.sh new file mode 100755 index 000000000..65e43f3ca --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/run-es-5.2.2.sh @@ -0,0 +1 @@ +docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/config:/usr/share/elasticsearch/config" -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:5.2.2 elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v3/script.go b/vendor/gopkg.in/olivere/elastic.v5/script.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/script.go rename to vendor/gopkg.in/olivere/elastic.v5/script.go index a5c9e45e2..b771c0547 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/script.go +++ b/vendor/gopkg.in/olivere/elastic.v5/script.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,7 +9,7 @@ import "errors" // Script holds all the paramaters necessary to compile or find in cache // and then execute a script. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/modules-scripting.html // for details of scripting. type Script struct { script string @@ -60,7 +60,7 @@ func (s *Script) Type(typ string) *Script { // Lang sets the language of the script. Permitted values are "groovy", // "expression", "mustache", "mvel" (default), "javascript", "python". // To use certain languages, you need to configure your server and/or -// add plugins. See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html +// add plugins. See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/modules-scripting.html // for details. func (s *Script) Lang(lang string) *Script { s.lang = lang diff --git a/vendor/gopkg.in/olivere/elastic.v5/scroll.go b/vendor/gopkg.in/olivere/elastic.v5/scroll.go new file mode 100644 index 000000000..7268026ff --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/scroll.go @@ -0,0 +1,445 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import ( + "fmt" + "io" + "net/url" + "strings" + "sync" + + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" +) + +const ( + // DefaultScrollKeepAlive is the default time a scroll cursor will be kept alive. + DefaultScrollKeepAlive = "5m" +) + +// ScrollService iterates over pages of search results from Elasticsearch. +type ScrollService struct { + client *Client + indices []string + types []string + keepAlive string + body interface{} + ss *SearchSource + size *int + pretty bool + routing string + preference string + ignoreUnavailable *bool + allowNoIndices *bool + expandWildcards string + + mu sync.RWMutex + scrollId string +} + +// NewScrollService initializes and returns a new ScrollService. +func NewScrollService(client *Client) *ScrollService { + builder := &ScrollService{ + client: client, + ss: NewSearchSource(), + keepAlive: DefaultScrollKeepAlive, + } + return builder +} + +// Index sets the name of one or more indices to iterate over. +func (s *ScrollService) Index(indices ...string) *ScrollService { + if s.indices == nil { + s.indices = make([]string, 0) + } + s.indices = append(s.indices, indices...) + return s +} + +// Type sets the name of one or more types to iterate over. +func (s *ScrollService) Type(types ...string) *ScrollService { + if s.types == nil { + s.types = make([]string, 0) + } + s.types = append(s.types, types...) + return s +} + +// Scroll is an alias for KeepAlive, the time to keep +// the cursor alive (e.g. "5m" for 5 minutes). +func (s *ScrollService) Scroll(keepAlive string) *ScrollService { + s.keepAlive = keepAlive + return s +} + +// KeepAlive sets the maximum time after which the cursor will expire. +// It is "2m" by default. +func (s *ScrollService) KeepAlive(keepAlive string) *ScrollService { + s.keepAlive = keepAlive + return s +} + +// Size specifies the number of documents Elasticsearch should return +// from each shard, per page. +func (s *ScrollService) Size(size int) *ScrollService { + s.size = &size + return s +} + +// Body sets the raw body to send to Elasticsearch. This can be e.g. a string, +// a map[string]interface{} or anything that can be serialized into JSON. +// Notice that setting the body disables the use of SearchSource and many +// other properties of the ScanService. +func (s *ScrollService) Body(body interface{}) *ScrollService { + s.body = body + return s +} + +// SearchSource sets the search source builder to use with this iterator. +// Notice that only a certain number of properties can be used when scrolling, +// e.g. query and sorting. +func (s *ScrollService) SearchSource(searchSource *SearchSource) *ScrollService { + s.ss = searchSource + if s.ss == nil { + s.ss = NewSearchSource() + } + return s +} + +// Query sets the query to perform, e.g. a MatchAllQuery. +func (s *ScrollService) Query(query Query) *ScrollService { + s.ss = s.ss.Query(query) + return s +} + +// PostFilter is executed as the last filter. It only affects the +// search hits but not facets. See +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-post-filter.html +// for details. +func (s *ScrollService) PostFilter(postFilter Query) *ScrollService { + s.ss = s.ss.PostFilter(postFilter) + return s +} + +// Slice allows slicing the scroll request into several batches. +// This is supported in Elasticsearch 5.0 or later. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-scroll.html#sliced-scroll +// for details. +func (s *ScrollService) Slice(sliceQuery Query) *ScrollService { + s.ss = s.ss.Slice(sliceQuery) + return s +} + +// FetchSource indicates whether the response should contain the stored +// _source for every hit. +func (s *ScrollService) FetchSource(fetchSource bool) *ScrollService { + s.ss = s.ss.FetchSource(fetchSource) + return s +} + +// FetchSourceContext indicates how the _source should be fetched. +func (s *ScrollService) FetchSourceContext(fetchSourceContext *FetchSourceContext) *ScrollService { + s.ss = s.ss.FetchSourceContext(fetchSourceContext) + return s +} + +// Version can be set to true to return a version for each search hit. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-version.html. +func (s *ScrollService) Version(version bool) *ScrollService { + s.ss = s.ss.Version(version) + return s +} + +// Sort adds a sort order. This can have negative effects on the performance +// of the scroll operation as Elasticsearch needs to sort first. +func (s *ScrollService) Sort(field string, ascending bool) *ScrollService { + s.ss = s.ss.Sort(field, ascending) + return s +} + +// SortWithInfo specifies a sort order. Notice that sorting can have a +// negative impact on scroll performance. +func (s *ScrollService) SortWithInfo(info SortInfo) *ScrollService { + s.ss = s.ss.SortWithInfo(info) + return s +} + +// SortBy specifies a sort order. Notice that sorting can have a +// negative impact on scroll performance. +func (s *ScrollService) SortBy(sorter ...Sorter) *ScrollService { + s.ss = s.ss.SortBy(sorter...) + return s +} + +// Pretty asks Elasticsearch to pretty-print the returned JSON. +func (s *ScrollService) Pretty(pretty bool) *ScrollService { + s.pretty = pretty + return s +} + +// Routing is a list of specific routing values to control the shards +// the search will be executed on. +func (s *ScrollService) Routing(routings ...string) *ScrollService { + s.routing = strings.Join(routings, ",") + return s +} + +// Preference sets the preference to execute the search. Defaults to +// randomize across shards ("random"). Can be set to "_local" to prefer +// local shards, "_primary" to execute on primary shards only, +// or a custom value which guarantees that the same order will be used +// across different requests. +func (s *ScrollService) Preference(preference string) *ScrollService { + s.preference = preference + return s +} + +// IgnoreUnavailable indicates whether the specified concrete indices +// should be ignored when unavailable (missing or closed). +func (s *ScrollService) IgnoreUnavailable(ignoreUnavailable bool) *ScrollService { + s.ignoreUnavailable = &ignoreUnavailable + return s +} + +// AllowNoIndices indicates whether to ignore if a wildcard indices +// expression resolves into no concrete indices. (This includes `_all` string +// or when no indices have been specified). +func (s *ScrollService) AllowNoIndices(allowNoIndices bool) *ScrollService { + s.allowNoIndices = &allowNoIndices + return s +} + +// ExpandWildcards indicates whether to expand wildcard expression to +// concrete indices that are open, closed or both. +func (s *ScrollService) ExpandWildcards(expandWildcards string) *ScrollService { + s.expandWildcards = expandWildcards + return s +} + +// ScrollId specifies the identifier of a scroll in action. +func (s *ScrollService) ScrollId(scrollId string) *ScrollService { + s.mu.Lock() + s.scrollId = scrollId + s.mu.Unlock() + return s +} + +// Do returns the next search result. It will return io.EOF as error if there +// are no more search results. +func (s *ScrollService) Do(ctx context.Context) (*SearchResult, error) { + s.mu.RLock() + nextScrollId := s.scrollId + s.mu.RUnlock() + if len(nextScrollId) == 0 { + return s.first(ctx) + } + return s.next(ctx) +} + +// Clear cancels the current scroll operation. If you don't do this manually, +// the scroll will be expired automatically by Elasticsearch. You can control +// how long a scroll cursor is kept alive with the KeepAlive func. +func (s *ScrollService) Clear(ctx context.Context) error { + s.mu.RLock() + scrollId := s.scrollId + s.mu.RUnlock() + if len(scrollId) == 0 { + return nil + } + + path := "/_search/scroll" + params := url.Values{} + body := struct { + ScrollId []string `json:"scroll_id,omitempty"` + }{ + ScrollId: []string{scrollId}, + } + + _, err := s.client.PerformRequest(ctx, "DELETE", path, params, body) + if err != nil { + return err + } + + return nil +} + +// -- First -- + +// first takes the first page of search results. +func (s *ScrollService) first(ctx context.Context) (*SearchResult, error) { + // Get URL and parameters for request + path, params, err := s.buildFirstURL() + if err != nil { + return nil, err + } + + // Get HTTP request body + body, err := s.bodyFirst() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(SearchResult) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + s.mu.Lock() + s.scrollId = ret.ScrollId + s.mu.Unlock() + if ret.Hits == nil || len(ret.Hits.Hits) == 0 { + return nil, io.EOF + } + return ret, nil +} + +// buildFirstURL builds the URL for retrieving the first page. +func (s *ScrollService) buildFirstURL() (string, url.Values, error) { + // Build URL + var err error + var path string + if len(s.indices) == 0 && len(s.types) == 0 { + path = "/_search" + } else if len(s.indices) > 0 && len(s.types) == 0 { + path, err = uritemplates.Expand("/{index}/_search", map[string]string{ + "index": strings.Join(s.indices, ","), + }) + } else if len(s.indices) == 0 && len(s.types) > 0 { + path, err = uritemplates.Expand("/_all/{typ}/_search", map[string]string{ + "typ": strings.Join(s.types, ","), + }) + } else { + path, err = uritemplates.Expand("/{index}/{typ}/_search", map[string]string{ + "index": strings.Join(s.indices, ","), + "typ": strings.Join(s.types, ","), + }) + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + if s.size != nil && *s.size > 0 { + params.Set("size", fmt.Sprintf("%d", *s.size)) + } + if len(s.keepAlive) > 0 { + params.Set("scroll", s.keepAlive) + } + if len(s.routing) > 0 { + params.Set("routing", s.routing) + } + if len(s.preference) > 0 { + params.Set("preference", s.preference) + } + if s.allowNoIndices != nil { + params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) + } + if len(s.expandWildcards) > 0 { + params.Set("expand_wildcards", s.expandWildcards) + } + if s.ignoreUnavailable != nil { + params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) + } + + return path, params, nil +} + +// bodyFirst returns the request to fetch the first batch of results. +func (s *ScrollService) bodyFirst() (interface{}, error) { + var err error + var body interface{} + + if s.body != nil { + body = s.body + } else { + // Use _doc sort by default if none is specified + if !s.ss.hasSort() { + // Use efficient sorting when no user-defined query/body is specified + s.ss = s.ss.SortBy(SortByDoc{}) + } + + // Body from search source + body, err = s.ss.Source() + if err != nil { + return nil, err + } + } + + return body, nil +} + +// -- Next -- + +func (s *ScrollService) next(ctx context.Context) (*SearchResult, error) { + // Get URL for request + path, params, err := s.buildNextURL() + if err != nil { + return nil, err + } + + // Setup HTTP request body + body, err := s.bodyNext() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(SearchResult) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + s.mu.Lock() + s.scrollId = ret.ScrollId + s.mu.Unlock() + if ret.Hits == nil || len(ret.Hits.Hits) == 0 { + return nil, io.EOF + } + return ret, nil +} + +// buildNextURL builds the URL for the operation. +func (s *ScrollService) buildNextURL() (string, url.Values, error) { + path := "/_search/scroll" + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "1") + } + + return path, params, nil +} + +// body returns the request to fetch the next batch of results. +func (s *ScrollService) bodyNext() (interface{}, error) { + s.mu.RLock() + body := struct { + Scroll string `json:"scroll"` + ScrollId string `json:"scroll_id,omitempty"` + }{ + Scroll: s.keepAlive, + ScrollId: s.scrollId, + } + s.mu.RUnlock() + return body, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search.go b/vendor/gopkg.in/olivere/elastic.v5/search.go similarity index 69% rename from vendor/gopkg.in/olivere/elastic.v3/search.go rename to vendor/gopkg.in/olivere/elastic.v5/search.go index 9965aa13c..e27ada228 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -11,7 +11,9 @@ import ( "reflect" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // Search for documents in Elasticsearch. @@ -20,11 +22,13 @@ type SearchService struct { searchSource *SearchSource source interface{} pretty bool + filterPath []string searchType string index []string typ []string routing string preference string + requestCache *bool ignoreUnavailable *bool allowNoIndices *bool expandWildcards string @@ -55,20 +59,22 @@ func (s *SearchService) Source(source interface{}) *SearchService { return s } +// FilterPath allows reducing the response, a mechanism known as +// response filtering and described here: +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/common-options.html#common-options-response-filtering. +func (s *SearchService) FilterPath(filterPath ...string) *SearchService { + s.filterPath = append(s.filterPath, filterPath...) + return s +} + // Index sets the names of the indices to use for search. func (s *SearchService) Index(index ...string) *SearchService { - if s.index == nil { - s.index = make([]string, 0) - } s.index = append(s.index, index...) return s } // Types adds search restrictions for a list of types. func (s *SearchService) Type(typ ...string) *SearchService { - if s.typ == nil { - s.typ = make([]string, 0) - } s.typ = append(s.typ, typ...) return s } @@ -85,6 +91,14 @@ func (s *SearchService) Timeout(timeout string) *SearchService { return s } +// Profile sets the Profile API flag on the search source. +// When enabled, a search executed by this service will return query +// profiling data. +func (s *SearchService) Profile(profile bool) *SearchService { + s.searchSource = s.searchSource.Profile(profile) + return s +} + // TimeoutInMillis sets the timeout in milliseconds. func (s *SearchService) TimeoutInMillis(timeoutInMillis int) *SearchService { s.searchSource = s.searchSource.TimeoutInMillis(timeoutInMillis) @@ -94,7 +108,7 @@ func (s *SearchService) TimeoutInMillis(timeoutInMillis int) *SearchService { // SearchType sets the search operation type. Valid values are: // "query_then_fetch", "query_and_fetch", "dfs_query_then_fetch", // "dfs_query_and_fetch", "count", "scan". -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-type.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-search-type.html // for details. func (s *SearchService) SearchType(searchType string) *SearchService { s.searchType = searchType @@ -118,6 +132,13 @@ func (s *SearchService) Preference(preference string) *SearchService { return s } +// RequestCache indicates whether the cache should be used for this +// request or not, defaults to index level setting. +func (s *SearchService) RequestCache(requestCache bool) *SearchService { + s.requestCache = &requestCache + return s +} + // Query sets the query to perform, e.g. MatchAllQuery. func (s *SearchService) Query(query Query) *SearchService { s.searchSource = s.searchSource.Query(query) @@ -220,25 +241,34 @@ func (s *SearchService) SortBy(sorter ...Sorter) *SearchService { return s } -// NoFields indicates that no fields should be loaded, resulting in only +// NoStoredFields indicates that no stored fields should be loaded, resulting in only // id and type to be returned per field. -func (s *SearchService) NoFields() *SearchService { - s.searchSource = s.searchSource.NoFields() +func (s *SearchService) NoStoredFields() *SearchService { + s.searchSource = s.searchSource.NoStoredFields() return s } -// Field adds a single field to load and return (note, must be stored) as +// StoredField adds a single field to load and return (note, must be stored) as // part of the search request. If none are specified, the source of the // document will be returned. -func (s *SearchService) Field(fieldName string) *SearchService { - s.searchSource = s.searchSource.Field(fieldName) +func (s *SearchService) StoredField(fieldName string) *SearchService { + s.searchSource = s.searchSource.StoredField(fieldName) return s } -// Fields sets the fields to load and return as part of the search request. +// StoredFields sets the fields to load and return as part of the search request. // If none are specified, the source of the document will be returned. -func (s *SearchService) Fields(fields ...string) *SearchService { - s.searchSource = s.searchSource.Fields(fields...) +func (s *SearchService) StoredFields(fields ...string) *SearchService { + s.searchSource = s.searchSource.StoredFields(fields...) + return s +} + +// SearchAfter allows a different form of pagination by using a live cursor, +// using the results of the previous page to help the retrieval of the next. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-search-after.html +func (s *SearchService) SearchAfter(sortValues ...interface{}) *SearchService { + s.searchSource = s.searchSource.SearchAfter(sortValues...) return s } @@ -303,6 +333,9 @@ func (s *SearchService) buildURL() (string, url.Values, error) { if s.preference != "" { params.Set("preference", s.preference) } + if s.requestCache != nil { + params.Set("request_cache", fmt.Sprintf("%v", *s.requestCache)) + } if s.allowNoIndices != nil { params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) } @@ -312,6 +345,9 @@ func (s *SearchService) buildURL() (string, url.Values, error) { if s.ignoreUnavailable != nil { params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) } + if len(s.filterPath) > 0 { + params.Set("filter_path", strings.Join(s.filterPath, ",")) + } return path, params, nil } @@ -321,7 +357,7 @@ func (s *SearchService) Validate() error { } // Do executes the search and returns a SearchResult. -func (s *SearchService) Do() (*SearchResult, error) { +func (s *SearchService) Do(ctx context.Context) (*SearchResult, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -344,7 +380,7 @@ func (s *SearchService) Do() (*SearchResult, error) { } body = src } - res, err := s.client.PerformRequest("POST", path, params, body) + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) if err != nil { return nil, err } @@ -359,15 +395,15 @@ func (s *SearchService) Do() (*SearchResult, error) { // SearchResult is the result of a search in Elasticsearch. type SearchResult struct { - TookInMillis int64 `json:"took"` // search time in milliseconds - ScrollId string `json:"_scroll_id"` // only used with Scroll and Scan operations - Hits *SearchHits `json:"hits"` // the actual search hits - Suggest SearchSuggest `json:"suggest"` // results from suggesters - Aggregations Aggregations `json:"aggregations"` // results from aggregations - TimedOut bool `json:"timed_out"` // true if the search timed out - //Error string `json:"error,omitempty"` // used in MultiSearch only - // TODO double-check that MultiGet now returns details error information - Error *ErrorDetails `json:"error,omitempty"` // only used in MultiGet + TookInMillis int64 `json:"took"` // search time in milliseconds + ScrollId string `json:"_scroll_id"` // only used with Scroll and Scan operations + Hits *SearchHits `json:"hits"` // the actual search hits + Suggest SearchSuggest `json:"suggest"` // results from suggesters + Aggregations Aggregations `json:"aggregations"` // results from aggregations + TimedOut bool `json:"timed_out"` // true if the search timed out + Error *ErrorDetails `json:"error,omitempty"` // only used in MultiGet + Profile *SearchProfile `json:"profile,omitempty"` // profiling results, if optional Profile API was active for this search + Shards *shardsInfo `json:"_shards,omitempty"` // shard information } // TotalHits is a convenience function to return the number of hits for @@ -386,7 +422,7 @@ func (r *SearchResult) Each(typ reflect.Type) []interface{} { if r.Hits == nil || r.Hits.Hits == nil || len(r.Hits.Hits) == 0 { return nil } - slice := make([]interface{}, 0) + var slice []interface{} for _, hit := range r.Hits.Hits { v := reflect.New(typ).Elem() if err := json.Unmarshal(*hit.Source, v.Addr().Interface()); err == nil { @@ -410,15 +446,13 @@ type SearchHit struct { Type string `json:"_type"` // type meta field Id string `json:"_id"` // external or internal Uid string `json:"_uid"` // uid meta field (see MapperService.java for all meta fields) - Timestamp int64 `json:"_timestamp"` // timestamp meta field - TTL int64 `json:"_ttl"` // ttl meta field Routing string `json:"_routing"` // routing meta field Parent string `json:"_parent"` // parent meta field Version *int64 `json:"_version"` // version number, when Version is set to true in SearchService Sort []interface{} `json:"sort"` // sort information Highlight SearchHitHighlight `json:"highlight"` // highlighter information Source *json.RawMessage `json:"_source"` // stored document source - Fields map[string]interface{} `json:"fields"` // returned fields + Fields map[string]interface{} `json:"fields"` // returned (stored) fields Explanation *SearchExplanation `json:"_explanation"` // explains how the score was computed MatchedQueries []string `json:"matched_queries"` // matched queries InnerHits map[string]*SearchHitInnerHits `json:"inner_hits"` // inner hits with ES >= 1.5.0 @@ -434,7 +468,7 @@ type SearchHitInnerHits struct { } // SearchExplanation explains how the score for a hit was computed. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-explain.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-explain.html. type SearchExplanation struct { Value float64 `json:"value"` // e.g. 1.0 Description string `json:"description"` // e.g. "boost" or "ConstantScore(*:*), product of:" @@ -444,11 +478,11 @@ type SearchExplanation struct { // Suggest // SearchSuggest is a map of suggestions. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters.html. type SearchSuggest map[string][]SearchSuggestion // SearchSuggestion is a single search suggestion. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters.html. type SearchSuggestion struct { Text string `json:"text"` Offset int `json:"offset"` @@ -457,14 +491,59 @@ type SearchSuggestion struct { } // SearchSuggestionOption is an option of a SearchSuggestion. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters.html. type SearchSuggestionOption struct { - Text string `json:"text"` - Highlighted string `json:"highlighted"` - Score float64 `json:"score"` - CollateMatch bool `json:"collate_match"` - Freq int `json:"freq"` // deprecated in 2.x - Payload interface{} `json:"payload"` + Text string `json:"text"` + Index string `json:"_index"` + Type string `json:"_type"` + Id string `json:"_id"` + Score float64 `json:"_score"` + Source *json.RawMessage `json:"_source"` +} + +// SearchProfile is a list of shard profiling data collected during +// query execution in the "profile" section of a SearchResult +type SearchProfile struct { + Shards []SearchProfileShardResult `json:"shards"` +} + +// SearchProfileShardResult returns the profiling data for a single shard +// accessed during the search query or aggregation. +type SearchProfileShardResult struct { + ID string `json:"id"` + Searches []QueryProfileShardResult `json:"searches"` + Aggregations []ProfileResult `json:"aggregations"` +} + +// QueryProfileShardResult is a container class to hold the profile results +// for a single shard in the request. It comtains a list of query profiles, +// a collector tree and a total rewrite tree. +type QueryProfileShardResult struct { + Query []ProfileResult `json:"query,omitempty"` + RewriteTime int64 `json:"rewrite_time,omitempty"` + Collector []interface{} `json:"collector,omitempty"` +} + +// CollectorResult holds the profile timings of the collectors used in the +// search. Children's CollectorResults may be embedded inside of a parent +// CollectorResult. +type CollectorResult struct { + Name string `json:"name,omitempty"` + Reason string `json:"reason,omitempty"` + Time string `json:"time,omitempty"` + TimeNanos int64 `json:"time_in_nanos,omitempty"` + Children []CollectorResult `json:"children,omitempty"` +} + +// ProfileResult is the internal representation of a profiled query, +// corresponding to a single node in the query tree. +type ProfileResult struct { + Type string `json:"type"` + Description string `json:"description,omitempty"` + NodeTime string `json:"time,omitempty"` + NodeTimeNanos int64 `json:"time_in_nanos,omitempty"` + Breakdown map[string]int64 `json:"breakdown,omitempty"` + Children []ProfileResult `json:"children,omitempty"` } // Aggregations (see search_aggs.go) @@ -472,6 +551,6 @@ type SearchSuggestionOption struct { // Highlighting // SearchHitHighlight is the highlight information of a search hit. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-highlighting.html // for a general discussion of highlighting. type SearchHitHighlight map[string][]string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs.go similarity index 82% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs.go index ff427d0ce..778aebcff 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -13,7 +13,7 @@ import ( // analytic information over a set of documents. It is // (in many senses) the follow-up of facets in Elasticsearch. // For more details about aggregations, visit: -// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations.html type Aggregation interface { // Source returns a JSON-serializable aggregation that is a fragment // of the request sent to Elasticsearch. @@ -24,7 +24,7 @@ type Aggregation interface { type Aggregations map[string]*json.RawMessage // Min returns min aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-min-aggregation.html func (a Aggregations) Min(name string) (*AggregationValueMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationValueMetric) @@ -39,7 +39,7 @@ func (a Aggregations) Min(name string) (*AggregationValueMetric, bool) { } // Max returns max aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-max-aggregation.html func (a Aggregations) Max(name string) (*AggregationValueMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationValueMetric) @@ -54,7 +54,7 @@ func (a Aggregations) Max(name string) (*AggregationValueMetric, bool) { } // Sum returns sum aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-sum-aggregation.html func (a Aggregations) Sum(name string) (*AggregationValueMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationValueMetric) @@ -69,7 +69,7 @@ func (a Aggregations) Sum(name string) (*AggregationValueMetric, bool) { } // Avg returns average aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-avg-aggregation.html func (a Aggregations) Avg(name string) (*AggregationValueMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationValueMetric) @@ -84,7 +84,7 @@ func (a Aggregations) Avg(name string) (*AggregationValueMetric, bool) { } // ValueCount returns value-count aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-valuecount-aggregation.html func (a Aggregations) ValueCount(name string) (*AggregationValueMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationValueMetric) @@ -99,7 +99,7 @@ func (a Aggregations) ValueCount(name string) (*AggregationValueMetric, bool) { } // Cardinality returns cardinality aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-cardinality-aggregation.html func (a Aggregations) Cardinality(name string) (*AggregationValueMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationValueMetric) @@ -114,7 +114,7 @@ func (a Aggregations) Cardinality(name string) (*AggregationValueMetric, bool) { } // Stats returns stats aggregation results. -// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-stats-aggregation.html func (a Aggregations) Stats(name string) (*AggregationStatsMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationStatsMetric) @@ -129,7 +129,7 @@ func (a Aggregations) Stats(name string) (*AggregationStatsMetric, bool) { } // ExtendedStats returns extended stats aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-extendedstats-aggregation.html func (a Aggregations) ExtendedStats(name string) (*AggregationExtendedStatsMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationExtendedStatsMetric) @@ -144,7 +144,7 @@ func (a Aggregations) ExtendedStats(name string) (*AggregationExtendedStatsMetri } // Percentiles returns percentiles results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-percentile-aggregation.html func (a Aggregations) Percentiles(name string) (*AggregationPercentilesMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationPercentilesMetric) @@ -159,7 +159,7 @@ func (a Aggregations) Percentiles(name string) (*AggregationPercentilesMetric, b } // PercentileRanks returns percentile ranks results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-rank-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-percentile-rank-aggregation.html func (a Aggregations) PercentileRanks(name string) (*AggregationPercentilesMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationPercentilesMetric) @@ -174,7 +174,7 @@ func (a Aggregations) PercentileRanks(name string) (*AggregationPercentilesMetri } // TopHits returns top-hits aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-top-hits-aggregation.html func (a Aggregations) TopHits(name string) (*AggregationTopHitsMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationTopHitsMetric) @@ -189,7 +189,7 @@ func (a Aggregations) TopHits(name string) (*AggregationTopHitsMetric, bool) { } // Global returns global results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-global-aggregation.html func (a Aggregations) Global(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -204,7 +204,7 @@ func (a Aggregations) Global(name string) (*AggregationSingleBucket, bool) { } // Filter returns filter results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-filter-aggregation.html func (a Aggregations) Filter(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -219,7 +219,7 @@ func (a Aggregations) Filter(name string) (*AggregationSingleBucket, bool) { } // Filters returns filters results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-filters-aggregation.html func (a Aggregations) Filters(name string) (*AggregationBucketFilters, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketFilters) @@ -234,7 +234,7 @@ func (a Aggregations) Filters(name string) (*AggregationBucketFilters, bool) { } // Missing returns missing results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-missing-aggregation.html func (a Aggregations) Missing(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -249,7 +249,7 @@ func (a Aggregations) Missing(name string) (*AggregationSingleBucket, bool) { } // Nested returns nested results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-nested-aggregation.html func (a Aggregations) Nested(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -264,7 +264,7 @@ func (a Aggregations) Nested(name string) (*AggregationSingleBucket, bool) { } // ReverseNested returns reverse-nested results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-reverse-nested-aggregation.html func (a Aggregations) ReverseNested(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -279,7 +279,7 @@ func (a Aggregations) ReverseNested(name string) (*AggregationSingleBucket, bool } // Children returns children results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-children-aggregation.html func (a Aggregations) Children(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -294,7 +294,7 @@ func (a Aggregations) Children(name string) (*AggregationSingleBucket, bool) { } // Terms returns terms aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-terms-aggregation.html func (a Aggregations) Terms(name string) (*AggregationBucketKeyItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketKeyItems) @@ -309,7 +309,7 @@ func (a Aggregations) Terms(name string) (*AggregationBucketKeyItems, bool) { } // SignificantTerms returns significant terms aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html func (a Aggregations) SignificantTerms(name string) (*AggregationBucketSignificantTerms, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketSignificantTerms) @@ -324,7 +324,7 @@ func (a Aggregations) SignificantTerms(name string) (*AggregationBucketSignifica } // Sampler returns sampler aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-sampler-aggregation.html func (a Aggregations) Sampler(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -339,7 +339,7 @@ func (a Aggregations) Sampler(name string) (*AggregationSingleBucket, bool) { } // Range returns range aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-range-aggregation.html func (a Aggregations) Range(name string) (*AggregationBucketRangeItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketRangeItems) @@ -354,7 +354,7 @@ func (a Aggregations) Range(name string) (*AggregationBucketRangeItems, bool) { } // KeyedRange returns keyed range aggregation results. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-range-aggregation.html. func (a Aggregations) KeyedRange(name string) (*AggregationBucketKeyedRangeItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketKeyedRangeItems) @@ -369,7 +369,7 @@ func (a Aggregations) KeyedRange(name string) (*AggregationBucketKeyedRangeItems } // DateRange returns date range aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-daterange-aggregation.html func (a Aggregations) DateRange(name string) (*AggregationBucketRangeItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketRangeItems) @@ -384,7 +384,7 @@ func (a Aggregations) DateRange(name string) (*AggregationBucketRangeItems, bool } // IPv4Range returns IPv4 range aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-iprange-aggregation.html func (a Aggregations) IPv4Range(name string) (*AggregationBucketRangeItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketRangeItems) @@ -399,7 +399,7 @@ func (a Aggregations) IPv4Range(name string) (*AggregationBucketRangeItems, bool } // Histogram returns histogram aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-histogram-aggregation.html func (a Aggregations) Histogram(name string) (*AggregationBucketHistogramItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketHistogramItems) @@ -414,7 +414,7 @@ func (a Aggregations) Histogram(name string) (*AggregationBucketHistogramItems, } // DateHistogram returns date histogram aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-datehistogram-aggregation.html func (a Aggregations) DateHistogram(name string) (*AggregationBucketHistogramItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketHistogramItems) @@ -429,7 +429,7 @@ func (a Aggregations) DateHistogram(name string) (*AggregationBucketHistogramIte } // GeoBounds returns geo-bounds aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-geobounds-aggregation.html func (a Aggregations) GeoBounds(name string) (*AggregationGeoBoundsMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationGeoBoundsMetric) @@ -444,7 +444,7 @@ func (a Aggregations) GeoBounds(name string) (*AggregationGeoBoundsMetric, bool) } // GeoHash returns geo-hash aggregation results. -// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-geohashgrid-aggregation.html func (a Aggregations) GeoHash(name string) (*AggregationBucketKeyItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketKeyItems) @@ -459,7 +459,7 @@ func (a Aggregations) GeoHash(name string) (*AggregationBucketKeyItems, bool) { } // GeoDistance returns geo distance aggregation results. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-geodistance-aggregation.html func (a Aggregations) GeoDistance(name string) (*AggregationBucketRangeItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketRangeItems) @@ -474,7 +474,7 @@ func (a Aggregations) GeoDistance(name string) (*AggregationBucketRangeItems, bo } // AvgBucket returns average bucket pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-avg-bucket-aggregation.html func (a Aggregations) AvgBucket(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -489,7 +489,7 @@ func (a Aggregations) AvgBucket(name string) (*AggregationPipelineSimpleValue, b } // SumBucket returns sum bucket pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-sum-bucket-aggregation.html func (a Aggregations) SumBucket(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -503,8 +503,23 @@ func (a Aggregations) SumBucket(name string) (*AggregationPipelineSimpleValue, b return nil, false } +// StatsBucket returns stats bucket pipeline aggregation results. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-stats-bucket-aggregation.html +func (a Aggregations) StatsBucket(name string) (*AggregationPipelineStatsMetric, bool) { + if raw, found := a[name]; found { + agg := new(AggregationPipelineStatsMetric) + if raw == nil { + return agg, true + } + if err := json.Unmarshal(*raw, agg); err == nil { + return agg, true + } + } + return nil, false +} + // MaxBucket returns maximum bucket pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-max-bucket-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-max-bucket-aggregation.html func (a Aggregations) MaxBucket(name string) (*AggregationPipelineBucketMetricValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineBucketMetricValue) @@ -519,7 +534,7 @@ func (a Aggregations) MaxBucket(name string) (*AggregationPipelineBucketMetricVa } // MinBucket returns minimum bucket pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-min-bucket-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-min-bucket-aggregation.html func (a Aggregations) MinBucket(name string) (*AggregationPipelineBucketMetricValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineBucketMetricValue) @@ -534,7 +549,7 @@ func (a Aggregations) MinBucket(name string) (*AggregationPipelineBucketMetricVa } // MovAvg returns moving average pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html func (a Aggregations) MovAvg(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -549,7 +564,7 @@ func (a Aggregations) MovAvg(name string) (*AggregationPipelineSimpleValue, bool } // Derivative returns derivative pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-derivative-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-derivative-aggregation.html func (a Aggregations) Derivative(name string) (*AggregationPipelineDerivative, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineDerivative) @@ -564,7 +579,7 @@ func (a Aggregations) Derivative(name string) (*AggregationPipelineDerivative, b } // CumulativeSum returns a cumulative sum pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-cumulative-sum-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-cumulative-sum-aggregation.html func (a Aggregations) CumulativeSum(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -579,7 +594,7 @@ func (a Aggregations) CumulativeSum(name string) (*AggregationPipelineSimpleValu } // BucketScript returns bucket script pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-bucket-script-aggregation.html func (a Aggregations) BucketScript(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -594,7 +609,7 @@ func (a Aggregations) BucketScript(name string) (*AggregationPipelineSimpleValue } // SerialDiff returns serial differencing pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-serialdiff-aggregation.html func (a Aggregations) SerialDiff(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -1144,7 +1159,7 @@ func (a *AggregationBucketHistogramItems) UnmarshalJSON(data []byte) error { type AggregationBucketHistogramItem struct { Aggregations - Key int64 //`json:"key"` + Key float64 //`json:"key"` KeyAsString *string //`json:"key_as_string"` DocCount int64 //`json:"doc_count"` } @@ -1272,3 +1287,67 @@ func (a *AggregationPipelineDerivative) UnmarshalJSON(data []byte) error { a.Aggregations = aggs return nil } + +// -- Pipeline stats metric -- + +// AggregationPipelineStatsMetric is a simple value, returned e.g. by a +// MovAvg aggregation. +type AggregationPipelineStatsMetric struct { + Aggregations + + Count int64 // `json:"count"` + CountAsString string // `json:"count_as_string"` + Min *float64 // `json:"min"` + MinAsString string // `json:"min_as_string"` + Max *float64 // `json:"max"` + MaxAsString string // `json:"max_as_string"` + Avg *float64 // `json:"avg"` + AvgAsString string // `json:"avg_as_string"` + Sum *float64 // `json:"sum"` + SumAsString string // `json:"sum_as_string"` + + Meta map[string]interface{} // `json:"meta,omitempty"` +} + +// UnmarshalJSON decodes JSON data and initializes an AggregationPipelineStatsMetric structure. +func (a *AggregationPipelineStatsMetric) UnmarshalJSON(data []byte) error { + var aggs map[string]*json.RawMessage + if err := json.Unmarshal(data, &aggs); err != nil { + return err + } + if v, ok := aggs["count"]; ok && v != nil { + json.Unmarshal(*v, &a.Count) + } + if v, ok := aggs["count_as_string"]; ok && v != nil { + json.Unmarshal(*v, &a.CountAsString) + } + if v, ok := aggs["min"]; ok && v != nil { + json.Unmarshal(*v, &a.Min) + } + if v, ok := aggs["min_as_string"]; ok && v != nil { + json.Unmarshal(*v, &a.MinAsString) + } + if v, ok := aggs["max"]; ok && v != nil { + json.Unmarshal(*v, &a.Max) + } + if v, ok := aggs["max_as_string"]; ok && v != nil { + json.Unmarshal(*v, &a.MaxAsString) + } + if v, ok := aggs["avg"]; ok && v != nil { + json.Unmarshal(*v, &a.Avg) + } + if v, ok := aggs["avg_as_string"]; ok && v != nil { + json.Unmarshal(*v, &a.AvgAsString) + } + if v, ok := aggs["sum"]; ok && v != nil { + json.Unmarshal(*v, &a.Sum) + } + if v, ok := aggs["sum_as_string"]; ok && v != nil { + json.Unmarshal(*v, &a.SumAsString) + } + if v, ok := aggs["meta"]; ok && v != nil { + json.Unmarshal(*v, &a.Meta) + } + a.Aggregations = aggs + return nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_children.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_children.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_children.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_children.go index 903e5461f..14d0d1ca9 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_children.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_children.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -7,7 +7,7 @@ package elastic // ChildrenAggregation is a special single bucket aggregation that enables // aggregating from buckets on parent document types to buckets on child documents. // It is available from 1.4.0.Beta1 upwards. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-children-aggregation.html type ChildrenAggregation struct { typ string subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_date_histogram.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_histogram.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_date_histogram.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_histogram.go index 231c51ef8..17916b490 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_date_histogram.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_histogram.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -6,7 +6,7 @@ package elastic // DateHistogramAggregation is a multi-bucket aggregation similar to the // histogram except it can only be applied on date values. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-datehistogram-aggregation.html type DateHistogramAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_date_range.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_range.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_date_range.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_range.go index 82de0696b..f94513d90 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_date_range.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_range.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -15,7 +15,7 @@ import ( // date format by which the from and to response fields will be returned. // Note that this aggregration includes the from value and excludes the to // value for each range. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-daterange-aggregation.html type DateRangeAggregation struct { field string script *Script @@ -182,7 +182,7 @@ func (a *DateRangeAggregation) Source() (interface{}, error) { opts["format"] = a.format } - ranges := make([]interface{}, 0) + var ranges []interface{} for _, ent := range a.entries { r := make(map[string]interface{}) if ent.Key != "" { diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_filter.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filter.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_filter.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filter.go index 101399882..2085f0d36 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_filter.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filter.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // in the current document set context that match a specified filter. // Often this will be used to narrow down the current aggregation context // to a specific set of documents. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-filter-aggregation.html type FilterAggregation struct { filter Query subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_filters.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filters.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_filters.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filters.go index 9acceb247..80999eed9 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_filters.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filters.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -15,7 +15,7 @@ import "errors" // use both named and unnamed filters. // // For details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-filters-aggregation.html type FiltersAggregation struct { unnamedFilters []Query namedFilters map[string]Query diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_geo_distance.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geo_distance.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_geo_distance.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geo_distance.go index 3a1372221..5ae11fd6b 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_geo_distance.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geo_distance.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -11,7 +11,7 @@ package elastic // the origin point and determines the buckets it belongs to based on // the ranges (a document belongs to a bucket if the distance between the // document and the origin falls within the distance range of the bucket). -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-bucket-geodistance-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-geodistance-aggregation.html type GeoDistanceAggregation struct { field string unit string @@ -142,7 +142,7 @@ func (a *GeoDistanceAggregation) Source() (interface{}, error) { opts["origin"] = a.point } - ranges := make([]interface{}, 0) + var ranges []interface{} for _, ent := range a.ranges { r := make(map[string]interface{}) if ent.Key != "" { diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_geohash_grid.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_geohash_grid.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_global.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_global.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_global.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_global.go index 49e24d60f..fbd14a45f 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_global.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_global.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // the search execution context. This context is defined by the indices // and the document types you’re searching on, but is not influenced // by the search query itself. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-global-aggregation.html type GlobalAggregation struct { subAggregations map[string]Aggregation meta map[string]interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_histogram.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_histogram.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_histogram.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_histogram.go index 7821adbc0..060853d11 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_histogram.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_histogram.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // that can be applied on numeric values extracted from the documents. // It dynamically builds fixed size (a.k.a. interval) buckets over the // values. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-histogram-aggregation.html type HistogramAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_missing.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_missing.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_missing.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_missing.go index ca610c953..3ca3fd693 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_missing.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_missing.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -11,7 +11,7 @@ package elastic // conjunction with other field data bucket aggregators (such as ranges) // to return information for all the documents that could not be placed // in any of the other buckets due to missing field data values. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-missing-aggregation.html type MissingAggregation struct { field string subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_nested.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_nested.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_nested.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_nested.go index f65da8048..62e592eb8 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_nested.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_nested.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -6,7 +6,7 @@ package elastic // NestedAggregation is a special single bucket aggregation that enables // aggregating nested documents. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-bucket-nested-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-nested-aggregation.html type NestedAggregation struct { path string subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_range.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_range.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_range.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_range.go index bc017c60f..88cde76fa 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_range.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_range.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -14,7 +14,7 @@ import ( // will be checked against each bucket range and "bucket" the // relevant/matching document. Note that this aggregration includes the // from value and excludes the to value for each range. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-range-aggregation.html type RangeAggregation struct { field string script *Script @@ -181,7 +181,7 @@ func (a *RangeAggregation) Source() (interface{}, error) { opts["unmapped"] = *a.unmapped } - ranges := make([]interface{}, 0) + var ranges []interface{} for _, ent := range a.entries { r := make(map[string]interface{}) if ent.Key != "" { diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_reverse_nested.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_reverse_nested.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_reverse_nested.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_reverse_nested.go index 89c7531d2..f307f256f 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_reverse_nested.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_reverse_nested.go @@ -11,7 +11,7 @@ package elastic // which allows nesting other aggregations that aren’t part of // the nested object in a nested aggregation. // -// See: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-reverse-nested-aggregation.html type ReverseNestedAggregation struct { path string subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_sampler.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_sampler.go similarity index 76% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_sampler.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_sampler.go index 9a6df15ec..c1a1ab4f7 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_sampler.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_sampler.go @@ -1,4 +1,4 @@ -// Copyright 2012-2016 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,11 +8,9 @@ package elastic // sub aggregations' processing to a sample of the top-scoring documents. // Optionally, diversity settings can be used to limit the number of matches // that share a common value such as an "author". -// See: https://www.elastic.co/guide/en/elasticsearch/reference/2.x/search-aggregations-bucket-sampler-aggregation.html +// +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-sampler-aggregation.html type SamplerAggregation struct { - field string - script *Script - missing interface{} subAggregations map[string]Aggregation meta map[string]interface{} @@ -29,22 +27,6 @@ func NewSamplerAggregation() *SamplerAggregation { } } -func (a *SamplerAggregation) Field(field string) *SamplerAggregation { - a.field = field - return a -} - -func (a *SamplerAggregation) Script(script *Script) *SamplerAggregation { - a.script = script - return a -} - -// Missing configures the value to use when documents miss a value. -func (a *SamplerAggregation) Missing(missing interface{}) *SamplerAggregation { - a.missing = missing - return a -} - func (a *SamplerAggregation) SubAggregation(name string, subAggregation Aggregation) *SamplerAggregation { a.subAggregations[name] = subAggregation return a @@ -78,7 +60,6 @@ func (a *SamplerAggregation) Source() (interface{}, error) { // "aggs" : { // "sample" : { // "sampler" : { - // "field" : "user.id", // "shard_size" : 200 // }, // "aggs": { @@ -98,21 +79,6 @@ func (a *SamplerAggregation) Source() (interface{}, error) { opts := make(map[string]interface{}) source["sampler"] = opts - // ValuesSourceAggregationBuilder - if a.field != "" { - opts["field"] = a.field - } - if a.script != nil { - src, err := a.script.Source() - if err != nil { - return nil, err - } - opts["script"] = src - } - if a.missing != nil { - opts["missing"] = a.missing - } - if a.shardSize >= 0 { opts["shard_size"] = a.shardSize } diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_significant_terms.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_significant_terms.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_significant_terms.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_significant_terms.go index 041bdb43d..e03801f1e 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_significant_terms.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_significant_terms.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -6,7 +6,7 @@ package elastic // SignificantSignificantTermsAggregation is an aggregation that returns interesting // or unusual occurrences of terms in a set. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html type SignificantTermsAggregation struct { field string subAggregations map[string]Aggregation @@ -166,7 +166,7 @@ type SignificanceHeuristic interface { // ChiSquareSignificanceHeuristic implements Chi square as described // in "Information Retrieval", Manning et al., Chapter 13.5.2. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_chi_square +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html#_chi_square // for details. type ChiSquareSignificanceHeuristic struct { backgroundIsSuperset *bool @@ -216,7 +216,7 @@ func (sh *ChiSquareSignificanceHeuristic) Source() (interface{}, error) { // as described in "The Google Similarity Distance", Cilibrasi and Vitanyi, // 2007. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_google_normalized_distance +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html#_google_normalized_distance // for details. type GNDSignificanceHeuristic struct { backgroundIsSuperset *bool @@ -252,7 +252,7 @@ func (sh *GNDSignificanceHeuristic) Source() (interface{}, error) { // -- JLH Score -- // JLHScoreSignificanceHeuristic implements the JLH score as described in -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_jlh_score. +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html#_jlh_score. type JLHScoreSignificanceHeuristic struct{} // NewJLHScoreSignificanceHeuristic initializes a new JLHScoreSignificanceHeuristic. @@ -276,7 +276,7 @@ func (sh *JLHScoreSignificanceHeuristic) Source() (interface{}, error) { // MutualInformationSignificanceHeuristic implements Mutual information // as described in "Information Retrieval", Manning et al., Chapter 13.5.1. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_mutual_information +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html#_mutual_information // for details. type MutualInformationSignificanceHeuristic struct { backgroundIsSuperset *bool @@ -324,7 +324,7 @@ func (sh *MutualInformationSignificanceHeuristic) Source() (interface{}, error) // -- Percentage Score -- // PercentageScoreSignificanceHeuristic implements the algorithm described -// in https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_percentage. +// in https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html#_percentage. type PercentageScoreSignificanceHeuristic struct{} // NewPercentageScoreSignificanceHeuristic initializes a new instance of @@ -347,7 +347,7 @@ func (sh *PercentageScoreSignificanceHeuristic) Source() (interface{}, error) { // -- Script -- // ScriptSignificanceHeuristic implements a scripted significance heuristic. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_scripted +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html#_scripted // for details. type ScriptSignificanceHeuristic struct { script *Script @@ -368,7 +368,7 @@ func (sh *ScriptSignificanceHeuristic) Name() string { // parameters are available in the script: `_subset_freq`, `_superset_freq`, // `_subset_size`, and `_superset_size`. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_scripted +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html#_scripted // for details. func (sh *ScriptSignificanceHeuristic) Script(script *Script) *ScriptSignificanceHeuristic { sh.script = script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_terms.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms.go similarity index 88% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_terms.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms.go index 2d3c0d1ad..5497aa6e9 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_bucket_terms.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -20,8 +20,6 @@ type TermsAggregation struct { minDocCount *int shardMinDocCount *int valueType string - order string - orderAsc bool includePattern string includeFlags *int excludePattern string @@ -31,13 +29,12 @@ type TermsAggregation struct { showTermDocCountError *bool includeTerms []string excludeTerms []string + order []TermsOrder } func NewTermsAggregation() *TermsAggregation { return &TermsAggregation{ subAggregations: make(map[string]Aggregation, 0), - includeTerms: make([]string, 0), - excludeTerms: make([]string, 0), } } @@ -122,15 +119,13 @@ func (a *TermsAggregation) ValueType(valueType string) *TermsAggregation { } func (a *TermsAggregation) Order(order string, asc bool) *TermsAggregation { - a.order = order - a.orderAsc = asc + a.order = append(a.order, TermsOrder{Field: order, Ascending: asc}) return a } func (a *TermsAggregation) OrderByCount(asc bool) *TermsAggregation { // "order" : { "_count" : "asc" } - a.order = "_count" - a.orderAsc = asc + a.order = append(a.order, TermsOrder{Field: "_count", Ascending: asc}) return a } @@ -144,8 +139,7 @@ func (a *TermsAggregation) OrderByCountDesc() *TermsAggregation { func (a *TermsAggregation) OrderByTerm(asc bool) *TermsAggregation { // "order" : { "_term" : "asc" } - a.order = "_term" - a.orderAsc = asc + a.order = append(a.order, TermsOrder{Field: "_term", Ascending: asc}) return a } @@ -173,8 +167,7 @@ func (a *TermsAggregation) OrderByAggregation(aggName string, asc bool) *TermsAg // } // } // } - a.order = aggName - a.orderAsc = asc + a.order = append(a.order, TermsOrder{Field: aggName, Ascending: asc}) return a } @@ -194,8 +187,7 @@ func (a *TermsAggregation) OrderByAggregationAndMetric(aggName, metric string, a // } // } // } - a.order = aggName + "." + metric - a.orderAsc = asc + a.order = append(a.order, TermsOrder{Field: aggName + "." + metric, Ascending: asc}) return a } @@ -280,14 +272,16 @@ func (a *TermsAggregation) Source() (interface{}, error) { if a.valueType != "" { opts["value_type"] = a.valueType } - if a.order != "" { - o := make(map[string]interface{}) - if a.orderAsc { - o[a.order] = "asc" - } else { - o[a.order] = "desc" + if len(a.order) > 0 { + var orderSlice []interface{} + for _, order := range a.order { + src, err := order.Source() + if err != nil { + return nil, err + } + orderSlice = append(orderSlice, src) } - opts["order"] = o + opts["order"] = orderSlice } if len(a.includeTerms) > 0 { opts["include"] = a.includeTerms @@ -339,3 +333,20 @@ func (a *TermsAggregation) Source() (interface{}, error) { return source, nil } + +// TermsOrder specifies a single order field for a terms aggregation. +type TermsOrder struct { + Field string + Ascending bool +} + +// Source returns serializable JSON of the TermsOrder. +func (order *TermsOrder) Source() (interface{}, error) { + source := make(map[string]string) + if order.Ascending { + source[order.Field] = "asc" + } else { + source[order.Field] = "desc" + } + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_avg.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_avg.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_avg.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_avg.go index 37ec2b7ad..ff337a8cd 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_avg.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_avg.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,7 +9,7 @@ package elastic // aggregated documents. These values can be extracted either from // specific numeric fields in the documents, or be generated by // a provided script. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-avg-aggregation.html type AvgAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_cardinality.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_cardinality.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_cardinality.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_cardinality.go index ebf247c79..8f6f447c4 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_cardinality.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_cardinality.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // calculates an approximate count of distinct values. // Values can be extracted either from specific fields in the document // or generated by a script. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-cardinality-aggregation.html type CardinalityAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_extended_stats.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_extended_stats.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_extended_stats.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_extended_stats.go index 69447409c..95b312686 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_extended_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_extended_stats.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // computes stats over numeric values extracted from the aggregated documents. // These values can be extracted either from specific numeric fields // in the documents, or be generated by a provided script. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-extendedstats-aggregation.html type ExtendedStatsAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_geo_bounds.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_geo_bounds.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_geo_bounds.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_geo_bounds.go index 647ba5139..c263a76b4 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_geo_bounds.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_geo_bounds.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -6,7 +6,7 @@ package elastic // GeoBoundsAggregation is a metric aggregation that computes the // bounding box containing all geo_point values for a field. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-geobounds-aggregation.html type GeoBoundsAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_max.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_max.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_max.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_max.go index 334cff020..b62130676 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_max.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_max.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,7 +9,7 @@ package elastic // the aggregated documents. These values can be extracted either from // specific numeric fields in the documents, or be generated by // a provided script. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-max-aggregation.html type MaxAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_min.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_min.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_min.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_min.go index f9e21f7a8..c1ca6922b 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_min.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_min.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,7 +9,7 @@ package elastic // aggregated documents. These values can be extracted either from // specific numeric fields in the documents, or be generated by a // provided script. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-min-aggregation.html type MinAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_percentile_ranks.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentile_ranks.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_percentile_ranks.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentile_ranks.go index c0b3aa663..3e0595e88 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_percentile_ranks.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentile_ranks.go @@ -1,11 +1,11 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. package elastic // PercentileRanksAggregation -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-rank-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-percentile-rank-aggregation.html type PercentileRanksAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_percentiles.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentiles.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_percentiles.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentiles.go index b1695ebb3..411f9c50f 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_percentiles.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentiles.go @@ -1,11 +1,11 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. package elastic // PercentilesAggregation -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-percentile-aggregation.html type PercentilesAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_stats.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_stats.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_stats.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_stats.go index 42da9c854..400b79b00 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_stats.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // over numeric values extracted from the aggregated documents. // These values can be extracted either from specific numeric fields // in the documents, or be generated by a provided script. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-stats-aggregation.html type StatsAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_sum.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_sum.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_sum.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_sum.go index 6f783e7e1..f959a3e54 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_sum.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_sum.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // numeric values that are extracted from the aggregated documents. // These values can be extracted either from specific numeric fields // in the documents, or be generated by a provided script. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-sum-aggregation.html type SumAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_top_hits.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_top_hits.go similarity index 85% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_top_hits.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_top_hits.go index c017abb98..43dd36cdb 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_top_hits.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_top_hits.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -13,7 +13,7 @@ package elastic // a bucket aggregator. One or more bucket aggregators determines by // which properties a result set get sliced into. // -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-top-hits-aggregation.html type TopHitsAggregation struct { searchSource *SearchSource } @@ -49,8 +49,8 @@ func (a *TopHitsAggregation) Version(version bool) *TopHitsAggregation { return a } -func (a *TopHitsAggregation) NoFields() *TopHitsAggregation { - a.searchSource = a.searchSource.NoFields() +func (a *TopHitsAggregation) NoStoredFields() *TopHitsAggregation { + a.searchSource = a.searchSource.NoStoredFields() return a } @@ -64,13 +64,13 @@ func (a *TopHitsAggregation) FetchSourceContext(fetchSourceContext *FetchSourceC return a } -func (a *TopHitsAggregation) FieldDataFields(fieldDataFields ...string) *TopHitsAggregation { - a.searchSource = a.searchSource.FieldDataFields(fieldDataFields...) +func (a *TopHitsAggregation) DocvalueFields(docvalueFields ...string) *TopHitsAggregation { + a.searchSource = a.searchSource.DocvalueFields(docvalueFields...) return a } -func (a *TopHitsAggregation) FieldDataField(fieldDataField string) *TopHitsAggregation { - a.searchSource = a.searchSource.FieldDataField(fieldDataField) +func (a *TopHitsAggregation) DocvalueField(docvalueField string) *TopHitsAggregation { + a.searchSource = a.searchSource.DocvalueField(docvalueField) return a } diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_value_count.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_value_count.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_value_count.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_value_count.go index b2e3e8241..4e7281d62 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_metrics_value_count.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_value_count.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -11,7 +11,7 @@ package elastic // used in conjunction with other single-value aggregations. // For example, when computing the avg one might be interested in the // number of values the average is computed over. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-valuecount-aggregation.html type ValueCountAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_avg_bucket.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_avg_bucket.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_avg_bucket.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_avg_bucket.go index 5cd93d5cc..7eea9310d 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_avg_bucket.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_avg_bucket.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ package elastic // be a multi-bucket aggregation. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-avg-bucket-aggregation.html type AvgBucketAggregation struct { format string gapPolicy string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_bucket_script.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_script.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_bucket_script.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_script.go index 44d6bc624..13cad638f 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_bucket_script.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_script.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ package elastic // numeric and the script must return a numeric value. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-bucket-script-aggregation.html type BucketScriptAggregation struct { format string gapPolicy string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_bucket_selector.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_selector.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_bucket_selector.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_selector.go index ce17ec1f6..f3c938519 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_bucket_selector.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_selector.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -12,7 +12,7 @@ package elastic // will be evaluated as false and all other values will evaluate to true. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-bucket-selector-aggregation.html type BucketSelectorAggregation struct { format string gapPolicy string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_cumulative_sum.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_cumulative_sum.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_cumulative_sum.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_cumulative_sum.go index 018eb918f..95546f1cb 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_cumulative_sum.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_cumulative_sum.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ package elastic // histogram must have min_doc_count set to 0 (default for histogram aggregations). // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-cumulative-sum-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-cumulative-sum-aggregation.html type CumulativeSumAggregation struct { format string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_derivative.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_derivative.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_derivative.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_derivative.go index 66611f46e..2c3c7e03a 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_derivative.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_derivative.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ package elastic // histogram must have min_doc_count set to 0 (default for histogram aggregations). // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-derivative-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-derivative-aggregation.html type DerivativeAggregation struct { format string gapPolicy string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_max_bucket.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_max_bucket.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_max_bucket.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_max_bucket.go index da6f9ef36..5a10b0e45 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_max_bucket.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_max_bucket.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -11,7 +11,7 @@ package elastic // be a multi-bucket aggregation. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-max-bucket-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-max-bucket-aggregation.html type MaxBucketAggregation struct { format string gapPolicy string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_min_bucket.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_min_bucket.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_min_bucket.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_min_bucket.go index 325f00f03..96982250c 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_min_bucket.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_min_bucket.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -11,7 +11,7 @@ package elastic // be a multi-bucket aggregation. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-min-bucket-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-min-bucket-aggregation.html type MinBucketAggregation struct { format string gapPolicy string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_mov_avg.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_mov_avg.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_mov_avg.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_mov_avg.go index 021144ddc..cf94342f7 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_mov_avg.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_mov_avg.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // across the data and emit the average value of that window. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html type MovAvgAggregation struct { format string gapPolicy string @@ -162,7 +162,7 @@ func (a *MovAvgAggregation) Source() (interface{}, error) { } // -- Models for moving averages -- -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html#_models +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html#_models // MovAvgModel specifies the model to use with the MovAvgAggregation. type MovAvgModel interface { @@ -175,7 +175,7 @@ type MovAvgModel interface { // EWMAMovAvgModel calculates an exponentially weighted moving average. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html#_ewma_exponentially_weighted +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html#_ewma_exponentially_weighted type EWMAMovAvgModel struct { alpha *float64 } @@ -213,7 +213,7 @@ func (m *EWMAMovAvgModel) Settings() map[string]interface{} { // HoltLinearMovAvgModel calculates a doubly exponential weighted moving average. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html#_holt_linear +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html#_holt_linear type HoltLinearMovAvgModel struct { alpha *float64 beta *float64 @@ -262,7 +262,7 @@ func (m *HoltLinearMovAvgModel) Settings() map[string]interface{} { // HoltWintersMovAvgModel calculates a triple exponential weighted moving average. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html#_holt_winters +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html#_holt_winters type HoltWintersMovAvgModel struct { alpha *float64 beta *float64 @@ -349,7 +349,7 @@ func (m *HoltWintersMovAvgModel) Settings() map[string]interface{} { // by position in collection. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html#_linear +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html#_linear type LinearMovAvgModel struct { } @@ -373,7 +373,7 @@ func (m *LinearMovAvgModel) Settings() map[string]interface{} { // SimpleMovAvgModel calculates a simple unweighted (arithmetic) moving average. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html#_simple +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html#_simple type SimpleMovAvgModel struct { } diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_serial_diff.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_serial_diff.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_serial_diff.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_serial_diff.go index db81d3cf4..84ae43004 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_serial_diff.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_serial_diff.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,7 +9,7 @@ package elastic // subtracted from itself at different time lags or periods. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-serialdiff-aggregation.html type SerialDiffAggregation struct { format string gapPolicy string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_stats_bucket.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_stats_bucket.go new file mode 100644 index 000000000..fb0a94afc --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_stats_bucket.go @@ -0,0 +1,113 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +// StatsBucketAggregation is a sibling pipeline aggregation which calculates +// a variety of stats across all bucket of a specified metric in a sibling aggregation. +// The specified metric must be numeric and the sibling aggregation must +// be a multi-bucket aggregation. +// +// For more details, see +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-stats-bucket-aggregation.html +type StatsBucketAggregation struct { + format string + gapPolicy string + + subAggregations map[string]Aggregation + meta map[string]interface{} + bucketsPaths []string +} + +// NewStatsBucketAggregation creates and initializes a new StatsBucketAggregation. +func NewStatsBucketAggregation() *StatsBucketAggregation { + return &StatsBucketAggregation{ + subAggregations: make(map[string]Aggregation), + bucketsPaths: make([]string, 0), + } +} + +func (s *StatsBucketAggregation) Format(format string) *StatsBucketAggregation { + s.format = format + return s +} + +// GapPolicy defines what should be done when a gap in the series is discovered. +// Valid values include "insert_zeros" or "skip". Default is "insert_zeros". +func (s *StatsBucketAggregation) GapPolicy(gapPolicy string) *StatsBucketAggregation { + s.gapPolicy = gapPolicy + return s +} + +// GapInsertZeros inserts zeros for gaps in the series. +func (s *StatsBucketAggregation) GapInsertZeros() *StatsBucketAggregation { + s.gapPolicy = "insert_zeros" + return s +} + +// GapSkip skips gaps in the series. +func (s *StatsBucketAggregation) GapSkip() *StatsBucketAggregation { + s.gapPolicy = "skip" + return s +} + +// SubAggregation adds a sub-aggregation to this aggregation. +func (s *StatsBucketAggregation) SubAggregation(name string, subAggregation Aggregation) *StatsBucketAggregation { + s.subAggregations[name] = subAggregation + return s +} + +// Meta sets the meta data to be included in the aggregation response. +func (s *StatsBucketAggregation) Meta(metaData map[string]interface{}) *StatsBucketAggregation { + s.meta = metaData + return s +} + +// BucketsPath sets the paths to the buckets to use for this pipeline aggregator. +func (s *StatsBucketAggregation) BucketsPath(bucketsPaths ...string) *StatsBucketAggregation { + s.bucketsPaths = append(s.bucketsPaths, bucketsPaths...) + return s +} + +func (s *StatsBucketAggregation) Source() (interface{}, error) { + source := make(map[string]interface{}) + params := make(map[string]interface{}) + source["stats_bucket"] = params + + if s.format != "" { + params["format"] = s.format + } + if s.gapPolicy != "" { + params["gap_policy"] = s.gapPolicy + } + + // Add buckets paths + switch len(s.bucketsPaths) { + case 0: + case 1: + params["buckets_path"] = s.bucketsPaths[0] + default: + params["buckets_path"] = s.bucketsPaths + } + + // AggregationBuilder (SubAggregations) + if len(s.subAggregations) > 0 { + aggsMap := make(map[string]interface{}) + source["aggregations"] = aggsMap + for name, aggregate := range s.subAggregations { + src, err := aggregate.Source() + if err != nil { + return nil, err + } + aggsMap[name] = src + } + } + + // Add Meta data if available + if len(s.meta) > 0 { + source["meta"] = s.meta + } + + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_sum_bucket.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_sum_bucket.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_sum_bucket.go rename to vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_sum_bucket.go index 16ef64986..1f78efa56 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_aggs_pipeline_sum_bucket.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_sum_bucket.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ package elastic // be a multi-bucket aggregation. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-sum-bucket-aggregation.html type SumBucketAggregation struct { format string gapPolicy string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_bool.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_bool.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_bool.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_bool.go index c2cc8697b..8ae223834 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_bool.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_bool.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,7 +9,7 @@ import "fmt" // A bool query matches documents matching boolean // combinations of other queries. // For more details, see: -// http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-bool-query.html type BoolQuery struct { Query mustClauses []Query @@ -124,7 +124,7 @@ func (q *BoolQuery) Source() (interface{}, error) { } boolClause["must"] = src } else if len(q.mustClauses) > 1 { - clauses := make([]interface{}, 0) + var clauses []interface{} for _, subQuery := range q.mustClauses { src, err := subQuery.Source() if err != nil { @@ -143,7 +143,7 @@ func (q *BoolQuery) Source() (interface{}, error) { } boolClause["must_not"] = src } else if len(q.mustNotClauses) > 1 { - clauses := make([]interface{}, 0) + var clauses []interface{} for _, subQuery := range q.mustNotClauses { src, err := subQuery.Source() if err != nil { @@ -162,7 +162,7 @@ func (q *BoolQuery) Source() (interface{}, error) { } boolClause["filter"] = src } else if len(q.filterClauses) > 1 { - clauses := make([]interface{}, 0) + var clauses []interface{} for _, subQuery := range q.filterClauses { src, err := subQuery.Source() if err != nil { @@ -181,7 +181,7 @@ func (q *BoolQuery) Source() (interface{}, error) { } boolClause["should"] = src } else if len(q.shouldClauses) > 1 { - clauses := make([]interface{}, 0) + var clauses []interface{} for _, subQuery := range q.shouldClauses { src, err := subQuery.Source() if err != nil { diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_boosting.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_boosting.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_boosting.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_boosting.go index 7f7a53b8b..3a31237c9 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_boosting.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_boosting.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -7,7 +7,7 @@ package elastic // A boosting query can be used to effectively // demote results that match a given query. // For more details, see: -// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-boosting-query.html type BoostingQuery struct { Query positiveClause Query diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_common_terms.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_common_terms.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_common_terms.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_common_terms.go index d45825067..a1a37b37c 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_common_terms.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_common_terms.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // which improves the precision and recall of search results // (by taking stopwords into account), without sacrificing performance. // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-common-terms-query.html type CommonTermsQuery struct { Query name string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_constant_score.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_constant_score.go similarity index 89% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_constant_score.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_constant_score.go index c754d279d..3ba879958 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_constant_score.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_constant_score.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // a constant score equal to the query boost for every document in the filter. // // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-constant-score-query.html type ConstantScoreQuery struct { filter Query boost *float64 diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_dis_max.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_dis_max.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_dis_max.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_dis_max.go index c47d6bb12..af9a40d37 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_dis_max.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_dis_max.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ package elastic // increment for any additional matching subqueries. // // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-dis-max-query.html type DisMaxQuery struct { queries []Query boost *float64 @@ -90,7 +90,7 @@ func (q *DisMaxQuery) Source() (interface{}, error) { } // queries - clauses := make([]interface{}, 0) + var clauses []interface{} for _, subQuery := range q.queries { src, err := subQuery.Source() if err != nil { diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_exists.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_exists.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_exists.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_exists.go index e117673bd..6c2ebd369 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_exists.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_exists.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // has a value in them. // // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-exists-query.html type ExistsQuery struct { name string queryName string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_fsq.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_fsq.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq.go index b7fa15e67..46f3e78ca 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_fsq.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ package elastic // to compute the score on a filtered set of documents. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html type FunctionScoreQuery struct { query Query filter Query diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_fsq_score_funcs.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq_score_funcs.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_fsq_score_funcs.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq_score_funcs.go index fbce3577d..622b645bb 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_fsq_score_funcs.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq_score_funcs.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -18,7 +18,7 @@ type ScoreFunction interface { // -- Exponential Decay -- // ExponentialDecayFunction builds an exponential decay score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html // for details. type ExponentialDecayFunction struct { fieldName string @@ -75,7 +75,7 @@ func (fn *ExponentialDecayFunction) Offset(offset interface{}) *ExponentialDecay } // Weight adjusts the score of the score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_using_function_score // for details. func (fn *ExponentialDecayFunction) Weight(weight float64) *ExponentialDecayFunction { fn.weight = &weight @@ -120,7 +120,7 @@ func (fn *ExponentialDecayFunction) Source() (interface{}, error) { // -- Gauss Decay -- // GaussDecayFunction builds a gauss decay score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html // for details. type GaussDecayFunction struct { fieldName string @@ -177,7 +177,7 @@ func (fn *GaussDecayFunction) Offset(offset interface{}) *GaussDecayFunction { } // Weight adjusts the score of the score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_using_function_score // for details. func (fn *GaussDecayFunction) Weight(weight float64) *GaussDecayFunction { fn.weight = &weight @@ -223,7 +223,7 @@ func (fn *GaussDecayFunction) Source() (interface{}, error) { // -- Linear Decay -- // LinearDecayFunction builds a linear decay score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html // for details. type LinearDecayFunction struct { fieldName string @@ -280,7 +280,7 @@ func (fn *LinearDecayFunction) Offset(offset interface{}) *LinearDecayFunction { } // Weight adjusts the score of the score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_using_function_score // for details. func (fn *LinearDecayFunction) Weight(weight float64) *LinearDecayFunction { fn.weight = &weight @@ -336,7 +336,7 @@ func (fn *LinearDecayFunction) Source() (interface{}, error) { // compute or influence the score of documents that match with the inner // query or filter. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_script_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_script_score // for details. type ScriptFunction struct { script *Script @@ -363,7 +363,7 @@ func (fn *ScriptFunction) Script(script *Script) *ScriptFunction { } // Weight adjusts the score of the score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_using_function_score // for details. func (fn *ScriptFunction) Weight(weight float64) *ScriptFunction { fn.weight = &weight @@ -394,7 +394,7 @@ func (fn *ScriptFunction) Source() (interface{}, error) { // FieldValueFactorFunction is a function score function that allows you // to use a field from a document to influence the score. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_field_value_factor. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_field_value_factor. type FieldValueFactorFunction struct { field string factor *float64 @@ -435,7 +435,7 @@ func (fn *FieldValueFactorFunction) Modifier(modifier string) *FieldValueFactorF } // Weight adjusts the score of the score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_using_function_score // for details. func (fn *FieldValueFactorFunction) Weight(weight float64) *FieldValueFactorFunction { fn.weight = &weight @@ -477,7 +477,7 @@ func (fn *FieldValueFactorFunction) Source() (interface{}, error) { // WeightFactorFunction builds a weight factor function that multiplies // the weight to the score. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_weight +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_weight // for details. type WeightFactorFunction struct { weight float64 @@ -495,7 +495,7 @@ func (fn *WeightFactorFunction) Name() string { } // Weight adjusts the score of the score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_using_function_score // for details. func (fn *WeightFactorFunction) Weight(weight float64) *WeightFactorFunction { fn.weight = weight @@ -517,7 +517,7 @@ func (fn *WeightFactorFunction) Source() (interface{}, error) { // -- Random -- // RandomFunction builds a random score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_random +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_random // for details. type RandomFunction struct { seed interface{} @@ -543,7 +543,7 @@ func (fn *RandomFunction) Seed(seed interface{}) *RandomFunction { } // Weight adjusts the score of the score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_using_function_score // for details. func (fn *RandomFunction) Weight(weight float64) *RandomFunction { fn.weight = &weight diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_fuzzy.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_fuzzy.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_fuzzy.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_fuzzy.go index da79dc7e6..b98f9c7f0 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_fuzzy.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_fuzzy.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // string fields, and a +/- margin on numeric and date fields. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-fuzzy-query.html type FuzzyQuery struct { name string value interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_geo_bounding_box.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_bounding_box.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_geo_bounding_box.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_bounding_box.go index 808ce82df..2b9cda746 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_geo_bounding_box.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_bounding_box.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ import "errors" // a bounding box. // // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-geo-bounding-box-query.html type GeoBoundingBoxQuery struct { name string top *float64 diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_geo_distance.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_distance.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_geo_distance.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_distance.go index c1eed8521..a10bd5e3c 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_geo_distance.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_distance.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // within a specific distance from a geo point. // // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-geo-distance-query.html type GeoDistanceQuery struct { name string distance string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_geo_polygon.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go similarity index 89% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_geo_polygon.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go index b08d7078a..1faaf24e0 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_geo_polygon.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -7,7 +7,7 @@ package elastic // GeoPolygonQuery allows to include hits that only fall within a polygon of points. // // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-geo-polygon-query.html type GeoPolygonQuery struct { name string points []*GeoPoint @@ -58,7 +58,7 @@ func (q *GeoPolygonQuery) Source() (interface{}, error) { polygon := make(map[string]interface{}) params[q.name] = polygon - points := make([]interface{}, 0) + var points []interface{} for _, point := range q.points { points = append(points, point.Source()) } diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_has_child.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_has_child.go similarity index 86% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_has_child.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_has_child.go index a8907546b..27cea7ad6 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_has_child.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_has_child.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,12 +8,12 @@ package elastic // in parent documents that have child docs matching the query. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-has-child-query.html type HasChildQuery struct { query Query childType string boost *float64 - scoreType string + scoreMode string minChildren *int maxChildren *int shortCircuitCutoff *int @@ -35,10 +35,11 @@ func (q *HasChildQuery) Boost(boost float64) *HasChildQuery { return q } -// ScoreType defines how the scores from the matching child documents -// are mapped into the parent document. -func (q *HasChildQuery) ScoreType(scoreType string) *HasChildQuery { - q.scoreType = scoreType +// ScoreMode defines how the scores from the matching child documents +// are mapped into the parent document. Allowed values are: min, max, +// avg, or none. +func (q *HasChildQuery) ScoreMode(scoreMode string) *HasChildQuery { + q.scoreMode = scoreMode return q } @@ -83,6 +84,7 @@ func (q *HasChildQuery) Source() (interface{}, error) { // { // "has_child" : { // "type" : "blog_tag", + // "score_mode" : "min", // "query" : { // "term" : { // "tag" : "something" @@ -103,8 +105,8 @@ func (q *HasChildQuery) Source() (interface{}, error) { if q.boost != nil { query["boost"] = *q.boost } - if q.scoreType != "" { - query["score_type"] = q.scoreType + if q.scoreMode != "" { + query["score_mode"] = q.scoreMode } if q.minChildren != nil { query["min_children"] = *q.minChildren diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_has_parent.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_has_parent.go similarity index 84% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_has_parent.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_has_parent.go index 4db1dde7e..7df110cd2 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_has_parent.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_has_parent.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -11,12 +11,12 @@ package elastic // same manner as has_child query. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-has-parent-query.html type HasParentQuery struct { query Query parentType string boost *float64 - scoreType string + score *bool queryName string innerHit *InnerHit } @@ -35,9 +35,9 @@ func (q *HasParentQuery) Boost(boost float64) *HasParentQuery { return q } -// ScoreType defines how the parent score is mapped into the child documents. -func (q *HasParentQuery) ScoreType(scoreType string) *HasParentQuery { - q.scoreType = scoreType +// Score defines if the parent score is mapped into the child documents. +func (q *HasParentQuery) Score(score bool) *HasParentQuery { + q.score = &score return q } @@ -80,8 +80,8 @@ func (q *HasParentQuery) Source() (interface{}, error) { if q.boost != nil { query["boost"] = *q.boost } - if q.scoreType != "" { - query["score_type"] = q.scoreType + if q.score != nil { + query["score"] = *q.score } if q.queryName != "" { query["_name"] = q.queryName diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_ids.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_ids.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_ids.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_ids.go index 96f463dc6..42cc65672 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_ids.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_ids.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // Note, this query uses the _uid field. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-ids-query.html type IdsQuery struct { types []string values []string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_indices.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_indices.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_indices.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_indices.go index 56efab3dd..ed5ec9d84 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_indices.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_indices.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ package elastic // executed on an index that does not match the listed indices. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-indices-query.html type IndicesQuery struct { query Query indices []string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_match.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_match.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go index b740b0f0d..0c44c5d57 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_match.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -12,7 +12,7 @@ package elastic // or use one of the shortcuts e.g. NewMatchPhraseQuery(...). // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-match-query.html type MatchQuery struct { name string text interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_match_all.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_match_all.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_match_all.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_match_all.go index 5b5ca590e..d681ba237 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_match_all.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_match_all.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // giving them all a _score of 1.0. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-match-all-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-match-all-query.html type MatchAllQuery struct { boost *float64 } diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_more_like_this.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_more_like_this.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_more_like_this.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_more_like_this.go index afce3f05c..606f43b0c 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_more_like_this.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_more_like_this.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -13,7 +13,7 @@ import "errors" // how the terms should be selected and how the query is formed. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-mlt-query.html type MoreLikeThisQuery struct { fields []string docs []*MoreLikeThisQueryItem @@ -214,7 +214,7 @@ func (q *MoreLikeThisQuery) Source() (interface{}, error) { params["fields"] = q.fields } - likes := make([]interface{}, 0) + var likes []interface{} for _, doc := range q.docs { src, err := doc.Source() if err != nil { @@ -225,7 +225,7 @@ func (q *MoreLikeThisQuery) Source() (interface{}, error) { params["like"] = likes if len(q.unlikeDocs) > 0 { - dontLikes := make([]interface{}, 0) + var dontLikes []interface{} for _, doc := range q.unlikeDocs { src, err := doc.Source() if err != nil { diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_multi_match.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_multi_match.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_multi_match.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_multi_match.go index b9f74a0d3..9a149fed5 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_multi_match.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_multi_match.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -12,7 +12,7 @@ import ( // MultiMatchQuery builds on the MatchQuery to allow multi-field queries. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-multi-match-query.html type MultiMatchQuery struct { text interface{} fields []string @@ -207,7 +207,7 @@ func (q *MultiMatchQuery) Source() (interface{}, error) { multiMatch["query"] = q.text if len(q.fields) > 0 { - fields := make([]string, 0) + var fields []string for _, field := range q.fields { if boost, found := q.fieldBoosts[field]; found { if boost != nil { diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_nested.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_nested.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_nested.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_nested.go index 0a598f8bf..11e3bb1c6 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_nested.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_nested.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,7 +10,7 @@ package elastic // root parent doc (or parent nested mapping). // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-nested-query.html type NestedQuery struct { query Query path string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_parent_id.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_parent_id.go new file mode 100644 index 000000000..bd11cc291 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_parent_id.go @@ -0,0 +1,99 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +// ParentIdQuery can be used to find child documents which belong to a +// particular parent. Given the following mapping definition. +// +// For more details, see +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-parent-id-query.html +type ParentIdQuery struct { + typ string + id string + ignoreUnmapped *bool + boost *float64 + queryName string + innerHit *InnerHit +} + +// NewParentIdQuery creates and initializes a new parent_id query. +func NewParentIdQuery(typ, id string) *ParentIdQuery { + return &ParentIdQuery{ + typ: typ, + id: id, + } +} + +// Type sets the parent type. +func (q *ParentIdQuery) Type(typ string) *ParentIdQuery { + q.typ = typ + return q +} + +// Id sets the id. +func (q *ParentIdQuery) Id(id string) *ParentIdQuery { + q.id = id + return q +} + +// IgnoreUnmapped specifies whether unmapped types should be ignored. +// If set to false, the query failes when an unmapped type is found. +func (q *ParentIdQuery) IgnoreUnmapped(ignore bool) *ParentIdQuery { + q.ignoreUnmapped = &ignore + return q +} + +// Boost sets the boost for this query. +func (q *ParentIdQuery) Boost(boost float64) *ParentIdQuery { + q.boost = &boost + return q +} + +// QueryName specifies the query name for the filter that can be used when +// searching for matched filters per hit. +func (q *ParentIdQuery) QueryName(queryName string) *ParentIdQuery { + q.queryName = queryName + return q +} + +// InnerHit sets the inner hit definition in the scope of this query and +// reusing the defined type and query. +func (q *ParentIdQuery) InnerHit(innerHit *InnerHit) *ParentIdQuery { + q.innerHit = innerHit + return q +} + +// Source returns JSON for the parent_id query. +func (q *ParentIdQuery) Source() (interface{}, error) { + // { + // "parent_id" : { + // "type" : "blog", + // "id" : "1" + // } + // } + source := make(map[string]interface{}) + query := make(map[string]interface{}) + source["parent_id"] = query + + query["type"] = q.typ + query["id"] = q.id + if q.boost != nil { + query["boost"] = *q.boost + } + if q.ignoreUnmapped != nil { + query["ignore_unmapped"] = *q.ignoreUnmapped + } + if q.queryName != "" { + query["_name"] = q.queryName + } + if q.innerHit != nil { + src, err := q.innerHit.Source() + if err != nil { + return nil, err + } + query["inner_hits"] = src + } + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_percolator.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_percolator.go new file mode 100644 index 000000000..16f7611ed --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_percolator.go @@ -0,0 +1,115 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import "errors" + +// PercolatorQuery can be used to match queries stored in an index. +// +// For more details, see +// https://www.elastic.co/guide/en/elasticsearch/reference/5.x/query-dsl-percolate-query.html +type PercolatorQuery struct { + field string + documentType string + document interface{} + indexedDocumentIndex string + indexedDocumentType string + indexedDocumentId string + indexedDocumentRouting string + indexedDocumentPreference string + indexedDocumentVersion *int64 +} + +// NewPercolatorQuery creates and initializes a new Percolator query. +func NewPercolatorQuery() *PercolatorQuery { + return &PercolatorQuery{} +} + +func (q *PercolatorQuery) Field(field string) *PercolatorQuery { + q.field = field + return q +} + +func (q *PercolatorQuery) DocumentType(typ string) *PercolatorQuery { + q.documentType = typ + return q +} + +func (q *PercolatorQuery) Document(doc interface{}) *PercolatorQuery { + q.document = doc + return q +} + +func (q *PercolatorQuery) IndexedDocumentIndex(index string) *PercolatorQuery { + q.indexedDocumentIndex = index + return q +} + +func (q *PercolatorQuery) IndexedDocumentType(typ string) *PercolatorQuery { + q.indexedDocumentType = typ + return q +} + +func (q *PercolatorQuery) IndexedDocumentId(id string) *PercolatorQuery { + q.indexedDocumentId = id + return q +} + +func (q *PercolatorQuery) IndexedDocumentRouting(routing string) *PercolatorQuery { + q.indexedDocumentRouting = routing + return q +} + +func (q *PercolatorQuery) IndexedDocumentPreference(preference string) *PercolatorQuery { + q.indexedDocumentPreference = preference + return q +} + +func (q *PercolatorQuery) IndexedDocumentVersion(version int64) *PercolatorQuery { + q.indexedDocumentVersion = &version + return q +} + +// Source returns JSON for the percolate query. +func (q *PercolatorQuery) Source() (interface{}, error) { + if len(q.field) == 0 { + return nil, errors.New("elastic: Field is required in PercolatorQuery") + } + if len(q.documentType) == 0 { + return nil, errors.New("elastic: DocumentType is required in PercolatorQuery") + } + if q.document == nil { + return nil, errors.New("elastic: Document is required in PercolatorQuery") + } + + // { + // "percolate" : { ... } + // } + source := make(map[string]interface{}) + params := make(map[string]interface{}) + source["percolate"] = params + params["field"] = q.field + params["document_type"] = q.documentType + params["document"] = q.document + if len(q.indexedDocumentIndex) > 0 { + params["index"] = q.indexedDocumentIndex + } + if len(q.indexedDocumentType) > 0 { + params["type"] = q.indexedDocumentType + } + if len(q.indexedDocumentId) > 0 { + params["id"] = q.indexedDocumentId + } + if len(q.indexedDocumentRouting) > 0 { + params["routing"] = q.indexedDocumentRouting + } + if len(q.indexedDocumentPreference) > 0 { + params["preference"] = q.indexedDocumentPreference + } + if q.indexedDocumentVersion != nil { + params["version"] = *q.indexedDocumentVersion + } + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_prefix.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_prefix.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_prefix.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_prefix.go index 1628ba8cc..dcf20ea70 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_prefix.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_prefix.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // with a specified prefix (not analyzed). // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-prefix-query.html type PrefixQuery struct { name string prefix string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_query_string.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_query_string.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_query_string.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_query_string.go index f1f767a47..427e54c5b 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_query_string.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_query_string.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -11,7 +11,7 @@ import ( // QueryStringQuery uses the query parser in order to parse its content. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-query-string-query.html type QueryStringQuery struct { queryString string defaultField string @@ -264,7 +264,7 @@ func (q *QueryStringQuery) Source() (interface{}, error) { } if len(q.fields) > 0 { - fields := make([]string, 0) + var fields []string for _, field := range q.fields { if boost, found := q.fieldBoosts[field]; found { if boost != nil { diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_range.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_range.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_range.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_range.go index 23e28597f..54303fb4a 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_range.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_range.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -7,7 +7,7 @@ package elastic // RangeQuery matches documents with fields that have terms within a certain range. // // For details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-range-query.html type RangeQuery struct { name string from interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_raw_string.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_raw_string.go new file mode 100644 index 000000000..3f9685c41 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_raw_string.go @@ -0,0 +1,26 @@ +// Copyright 2012-present Oliver Eilhard, John Stanford. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +import "encoding/json" + +// RawStringQuery can be used to treat a string representation of an ES query +// as a Query. Example usage: +// q := RawStringQuery("{\"match_all\":{}}") +// db.Search().Query(q).From(1).Size(100).Do() +type RawStringQuery string + +// NewRawStringQuery ininitializes a new RawStringQuery. +// It is the same as RawStringQuery(q). +func NewRawStringQuery(q string) RawStringQuery { + return RawStringQuery(q) +} + +// Source returns the JSON encoded body +func (q RawStringQuery) Source() (interface{}, error) { + var f interface{} + err := json.Unmarshal([]byte(q), &f) + return f, err +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_regexp.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_regexp.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_regexp.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_regexp.go index ecd9f7fe0..636e4baf9 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_regexp.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_regexp.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -7,7 +7,7 @@ package elastic // RegexpQuery allows you to use regular expression term queries. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-regexp-query.html type RegexpQuery struct { name string regexp string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_script.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_script.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_script.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_script.go index 3baa90574..664555b3e 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_script.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_script.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,7 +9,7 @@ import "errors" // ScriptQuery allows to define scripts as filters. // // For details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-script-query.html type ScriptQuery struct { script *Script queryName string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_simple_query_string.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_simple_query_string.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_simple_query_string.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_simple_query_string.go index fb0a2a9b9..764fa0a20 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_simple_query_string.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_simple_query_string.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -15,7 +15,7 @@ import ( // and discards invalid parts of the query. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-simple-query-string-query.html type SimpleQueryStringQuery struct { queryText string analyzer string @@ -135,7 +135,7 @@ func (q *SimpleQueryStringQuery) Source() (interface{}, error) { query["query"] = q.queryText if len(q.fields) > 0 { - fields := make([]string, 0) + var fields []string for _, field := range q.fields { if boost, found := q.fieldBoosts[field]; found { if boost != nil { diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_slice.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_slice.go new file mode 100644 index 000000000..0ebf88009 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_slice.go @@ -0,0 +1,53 @@ +// Copyright 2012-present Oliver Eilhard. All rights reserved. +// Use of this source code is governed by a MIT-license. +// See http://olivere.mit-license.org/license.txt for details. + +package elastic + +// SliceQuery allows to partition the documents into several slices. +// It is used e.g. to slice scroll operations in Elasticsearch 5.0 or later. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-scroll.html#sliced-scroll +// for details. +type SliceQuery struct { + field string + id *int + max *int +} + +// NewSliceQuery creates a new SliceQuery. +func NewSliceQuery() *SliceQuery { + return &SliceQuery{} +} + +// Field is the name of the field to slice against (_uid by default). +func (s *SliceQuery) Field(field string) *SliceQuery { + s.field = field + return s +} + +// Id is the id of the slice. +func (s *SliceQuery) Id(id int) *SliceQuery { + s.id = &id + return s +} + +// Max is the maximum number of slices. +func (s *SliceQuery) Max(max int) *SliceQuery { + s.max = &max + return s +} + +// Source returns the JSON body. +func (s *SliceQuery) Source() (interface{}, error) { + m := make(map[string]interface{}) + if s.field != "" { + m["field"] = s.field + } + if s.id != nil { + m["id"] = *s.id + } + if s.max != nil { + m["max"] = *s.max + } + return m, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_term.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_term.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_term.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_term.go index c20c5c66e..051f6dee3 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_term.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_term.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // in the inverted index. // // For details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-term-query.html type TermQuery struct { name string value interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_terms.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_terms.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_terms.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_terms.go index a7e158859..6875ae49a 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_terms.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_terms.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -8,7 +8,7 @@ package elastic // of the provided terms (not analyzed). // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-terms-query.html type TermsQuery struct { name string values []interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_type.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_type.go similarity index 79% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_type.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_type.go index 884d4ae7b..70ace4541 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_type.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_type.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -7,7 +7,7 @@ package elastic // TypeQuery filters documents matching the provided document / mapping type. // // For details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-type-query.html type TypeQuery struct { typ string } diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_queries_wildcard.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_wildcard.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/search_queries_wildcard.go rename to vendor/gopkg.in/olivere/elastic.v5/search_queries_wildcard.go index 127332da3..35f481542 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_queries_wildcard.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_wildcard.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -13,7 +13,7 @@ package elastic // The wildcard query maps to Lucene WildcardQuery. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-wildcard-query.html type WildcardQuery struct { name string wildcard string diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_request.go b/vendor/gopkg.in/olivere/elastic.v5/search_request.go similarity index 67% rename from vendor/gopkg.in/olivere/elastic.v3/search_request.go rename to vendor/gopkg.in/olivere/elastic.v5/search_request.go index f294cdb7a..ad22a5a3f 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_request.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_request.go @@ -1,34 +1,31 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. package elastic -import ( - "fmt" - "strings" -) +import "strings" // SearchRequest combines a search request and its // query details (see SearchSource). // It is used in combination with MultiSearch. type SearchRequest struct { - searchType string // default in ES is "query_then_fetch" - indices []string - types []string - routing *string - preference *string - requestCache *bool - scroll string - source interface{} + searchType string // default in ES is "query_then_fetch" + indices []string + types []string + routing *string + preference *string + requestCache *bool + ignoreUnavailable *bool + allowNoIndices *bool + expandWildcards string + scroll string + source interface{} } // NewSearchRequest creates a new search request. func NewSearchRequest() *SearchRequest { - return &SearchRequest{ - indices: make([]string, 0), - types: make([]string, 0), - } + return &SearchRequest{} } // SearchRequest must be one of "query_then_fetch", "query_and_fetch", @@ -102,6 +99,27 @@ func (r *SearchRequest) RequestCache(requestCache bool) *SearchRequest { return r } +// IgnoreUnavailable indicates whether specified concrete indices should be +// ignored when unavailable (missing or closed). +func (s *SearchRequest) IgnoreUnavailable(ignoreUnavailable bool) *SearchRequest { + s.ignoreUnavailable = &ignoreUnavailable + return s +} + +// AllowNoIndices indicates whether to ignore if a wildcard indices +// expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified). +func (s *SearchRequest) AllowNoIndices(allowNoIndices bool) *SearchRequest { + s.allowNoIndices = &allowNoIndices + return s +} + +// ExpandWildcards indicates whether to expand wildcard expression to +// concrete indices that are open, closed or both. +func (s *SearchRequest) ExpandWildcards(expandWildcards string) *SearchRequest { + s.expandWildcards = expandWildcards + return s +} + func (r *SearchRequest) Scroll(scroll string) *SearchRequest { r.scroll = scroll return r @@ -128,7 +146,7 @@ func (r *SearchRequest) Source(source interface{}) *SearchRequest { // header is used e.g. by MultiSearch to get information about the search header // of one SearchRequest. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-multi-search.html func (r *SearchRequest) header() interface{} { h := make(map[string]interface{}) if r.searchType != "" { @@ -154,15 +172,21 @@ func (r *SearchRequest) header() interface{} { if r.routing != nil && *r.routing != "" { h["routing"] = *r.routing } - if r.preference != nil && *r.preference != "" { h["preference"] = *r.preference } - if r.requestCache != nil { - h["request_cache"] = fmt.Sprintf("%v", *r.requestCache) + h["request_cache"] = *r.requestCache + } + if r.ignoreUnavailable != nil { + h["ignore_unavailable"] = *r.ignoreUnavailable + } + if r.allowNoIndices != nil { + h["allow_no_indices"] = *r.allowNoIndices + } + if r.expandWildcards != "" { + h["expand_wildcards"] = r.expandWildcards } - if r.scroll != "" { h["scroll"] = r.scroll } @@ -172,7 +196,7 @@ func (r *SearchRequest) header() interface{} { // body is used by MultiSearch to get information about the search body // of one SearchRequest. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-multi-search.html func (r *SearchRequest) body() interface{} { return r.source } diff --git a/vendor/gopkg.in/olivere/elastic.v3/search_source.go b/vendor/gopkg.in/olivere/elastic.v5/search_source.go similarity index 79% rename from vendor/gopkg.in/olivere/elastic.v3/search_source.go rename to vendor/gopkg.in/olivere/elastic.v5/search_source.go index d3d041f10..9d71fef25 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/search_source.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_source.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -13,17 +13,19 @@ import ( type SearchSource struct { query Query postQuery Query + sliceQuery Query from int size int explain *bool version *bool sorters []Sorter trackScores bool + searchAfterSortValues []interface{} minScore *float64 timeout string terminateAfter *int - fieldNames []string - fieldDataFields []string + storedFieldNames []string + docvalueFields []string scriptFields []*ScriptField fetchSourceContext *FetchSourceContext aggregations map[string]Aggregation @@ -35,22 +37,18 @@ type SearchSource struct { indexBoosts map[string]float64 stats []string innerHits map[string]*InnerHit + profile bool } // NewSearchSource initializes a new SearchSource. func NewSearchSource() *SearchSource { return &SearchSource{ - from: -1, - size: -1, - trackScores: false, - sorters: make([]Sorter, 0), - fieldDataFields: make([]string, 0), - scriptFields: make([]*ScriptField, 0), - aggregations: make(map[string]Aggregation), - rescores: make([]*Rescore, 0), - indexBoosts: make(map[string]float64), - stats: make([]string, 0), - innerHits: make(map[string]*InnerHit), + from: -1, + size: -1, + trackScores: false, + aggregations: make(map[string]Aggregation), + indexBoosts: make(map[string]float64), + innerHits: make(map[string]*InnerHit), } } @@ -60,6 +58,13 @@ func (s *SearchSource) Query(query Query) *SearchSource { return s } +// Profile specifies that this search source should activate the +// Profile API for queries made on it. +func (s *SearchSource) Profile(profile bool) *SearchSource { + s.profile = profile + return s +} + // PostFilter will be executed after the query has been executed and // only affects the search hits, not the aggregations. // This filter is always executed as the last filtering mechanism. @@ -68,6 +73,16 @@ func (s *SearchSource) PostFilter(postFilter Query) *SearchSource { return s } +// Slice allows partitioning the documents in multiple slices. +// It is e.g. used to slice a scroll operation, supported in +// Elasticsearch 5.0 or later. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-scroll.html#sliced-scroll +// for details. +func (s *SearchSource) Slice(sliceQuery Query) *SearchSource { + s.sliceQuery = sliceQuery + return s +} + // From index to start the search from. Defaults to 0. func (s *SearchSource) From(from int) *SearchSource { s.from = from @@ -149,6 +164,15 @@ func (s *SearchSource) TrackScores(trackScores bool) *SearchSource { return s } +// SearchAfter allows a different form of pagination by using a live cursor, +// using the results of the previous page to help the retrieval of the next. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-search-after.html +func (s *SearchSource) SearchAfter(sortValues ...interface{}) *SearchSource { + s.searchAfterSortValues = append(s.searchAfterSortValues, sortValues...) + return s +} + // Aggregation adds an aggreation to perform as part of the search. func (s *SearchSource) Aggregation(name string, aggregation Aggregation) *SearchSource { s.aggregations[name] = aggregation @@ -218,45 +242,39 @@ func (s *SearchSource) FetchSourceContext(fetchSourceContext *FetchSourceContext return s } -// NoFields indicates that no fields should be loaded, resulting in only +// NoStoredFields indicates that no fields should be loaded, resulting in only // id and type to be returned per field. -func (s *SearchSource) NoFields() *SearchSource { - s.fieldNames = make([]string, 0) +func (s *SearchSource) NoStoredFields() *SearchSource { + s.storedFieldNames = nil return s } -// Field adds a single field to load and return (note, must be stored) as +// StoredField adds a single field to load and return (note, must be stored) as // part of the search request. If none are specified, the source of the // document will be returned. -func (s *SearchSource) Field(fieldName string) *SearchSource { - if s.fieldNames == nil { - s.fieldNames = make([]string, 0) - } - s.fieldNames = append(s.fieldNames, fieldName) +func (s *SearchSource) StoredField(storedFieldName string) *SearchSource { + s.storedFieldNames = append(s.storedFieldNames, storedFieldName) return s } -// Fields sets the fields to load and return as part of the search request. +// StoredFields sets the fields to load and return as part of the search request. // If none are specified, the source of the document will be returned. -func (s *SearchSource) Fields(fieldNames ...string) *SearchSource { - if s.fieldNames == nil { - s.fieldNames = make([]string, 0) - } - s.fieldNames = append(s.fieldNames, fieldNames...) +func (s *SearchSource) StoredFields(storedFieldNames ...string) *SearchSource { + s.storedFieldNames = append(s.storedFieldNames, storedFieldNames...) return s } -// FieldDataField adds a single field to load from the field data cache +// DocvalueField adds a single field to load from the field data cache // and return as part of the search request. -func (s *SearchSource) FieldDataField(fieldDataField string) *SearchSource { - s.fieldDataFields = append(s.fieldDataFields, fieldDataField) +func (s *SearchSource) DocvalueField(fieldDataField string) *SearchSource { + s.docvalueFields = append(s.docvalueFields, fieldDataField) return s } -// FieldDataFields adds one or more fields to load from the field data cache +// DocvalueFields adds one or more fields to load from the field data cache // and return as part of the search request. -func (s *SearchSource) FieldDataFields(fieldDataFields ...string) *SearchSource { - s.fieldDataFields = append(s.fieldDataFields, fieldDataFields...) +func (s *SearchSource) DocvalueFields(docvalueFields ...string) *SearchSource { + s.docvalueFields = append(s.docvalueFields, docvalueFields...) return s } @@ -321,6 +339,13 @@ func (s *SearchSource) Source() (interface{}, error) { } source["post_filter"] = src } + if s.sliceQuery != nil { + src, err := s.sliceQuery.Source() + if err != nil { + return nil, err + } + source["slice"] = src + } if s.minScore != nil { source["min_score"] = *s.minScore } @@ -330,6 +355,9 @@ func (s *SearchSource) Source() (interface{}, error) { if s.explain != nil { source["explain"] = *s.explain } + if s.profile { + source["profile"] = s.profile + } if s.fetchSourceContext != nil { src, err := s.fetchSourceContext.Source() if err != nil { @@ -338,17 +366,17 @@ func (s *SearchSource) Source() (interface{}, error) { source["_source"] = src } - if s.fieldNames != nil { - switch len(s.fieldNames) { + if s.storedFieldNames != nil { + switch len(s.storedFieldNames) { case 1: - source["fields"] = s.fieldNames[0] + source["stored_fields"] = s.storedFieldNames[0] default: - source["fields"] = s.fieldNames + source["stored_fields"] = s.storedFieldNames } } - if len(s.fieldDataFields) > 0 { - source["fielddata_fields"] = s.fieldDataFields + if len(s.docvalueFields) > 0 { + source["docvalue_fields"] = s.docvalueFields } if len(s.scriptFields) > 0 { @@ -364,7 +392,7 @@ func (s *SearchSource) Source() (interface{}, error) { } if len(s.sorters) > 0 { - sortarr := make([]interface{}, 0) + var sortarr []interface{} for _, sorter := range s.sorters { src, err := sorter.Source() if err != nil { @@ -379,6 +407,10 @@ func (s *SearchSource) Source() (interface{}, error) { source["track_scores"] = s.trackScores } + if len(s.searchAfterSortValues) > 0 { + source["search_after"] = s.searchAfterSortValues + } + if len(s.indexBoosts) > 0 { source["indices_boost"] = s.indexBoosts } @@ -420,7 +452,7 @@ func (s *SearchSource) Source() (interface{}, error) { if len(s.rescores) > 0 { // Strip empty rescores from request - rescores := make([]*Rescore, 0) + var rescores []*Rescore for _, r := range s.rescores { if !r.IsEmpty() { rescores = append(rescores, r) @@ -435,7 +467,7 @@ func (s *SearchSource) Source() (interface{}, error) { } source["rescore"] = src } else { - slice := make([]interface{}, 0) + var slice []interface{} for _, r := range rescores { r.defaultRescoreWindowSize = s.defaultRescoreWindowSize src, err := r.Source() diff --git a/vendor/gopkg.in/olivere/elastic.v3/sort.go b/vendor/gopkg.in/olivere/elastic.v5/sort.go similarity index 71% rename from vendor/gopkg.in/olivere/elastic.v3/sort.go rename to vendor/gopkg.in/olivere/elastic.v5/sort.go index 191426141..122b69104 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/sort.go +++ b/vendor/gopkg.in/olivere/elastic.v5/sort.go @@ -9,7 +9,7 @@ import "errors" // -- Sorter -- // Sorter is an interface for sorting strategies, e.g. ScoreSort or FieldSort. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-sort.html. type Sorter interface { Source() (interface{}, error) } @@ -59,6 +59,23 @@ func (info SortInfo) Source() (interface{}, error) { return source, nil } +// -- SortByDoc -- + +// SortByDoc sorts by the "_doc" field, as described in +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-scroll.html. +// +// Example: +// ss := elastic.NewSearchSource() +// ss = ss.SortBy(elastic.SortByDoc{}) +type SortByDoc struct { + Sorter +} + +// Source returns the JSON-serializable data. +func (s SortByDoc) Source() (interface{}, error) { + return "_doc", nil +} + // -- ScoreSort -- // ScoreSort sorts by relevancy score. @@ -68,35 +85,37 @@ type ScoreSort struct { } // NewScoreSort creates a new ScoreSort. -func NewScoreSort() ScoreSort { - return ScoreSort{ascending: false} // Descending by default! +func NewScoreSort() *ScoreSort { + return &ScoreSort{ascending: false} // Descending by default! } // Order defines whether sorting ascending (default) or descending. -func (s ScoreSort) Order(ascending bool) ScoreSort { +func (s *ScoreSort) Order(ascending bool) *ScoreSort { s.ascending = ascending return s } // Asc sets ascending sort order. -func (s ScoreSort) Asc() ScoreSort { +func (s *ScoreSort) Asc() *ScoreSort { s.ascending = true return s } // Desc sets descending sort order. -func (s ScoreSort) Desc() ScoreSort { +func (s *ScoreSort) Desc() *ScoreSort { s.ascending = false return s } // Source returns the JSON-serializable data. -func (s ScoreSort) Source() (interface{}, error) { +func (s *ScoreSort) Source() (interface{}, error) { source := make(map[string]interface{}) x := make(map[string]interface{}) source["_score"] = x if s.ascending { - x["reverse"] = true + x["order"] = "asc" + } else { + x["order"] = "desc" } return source, nil } @@ -117,33 +136,33 @@ type FieldSort struct { } // NewFieldSort creates a new FieldSort. -func NewFieldSort(fieldName string) FieldSort { - return FieldSort{ +func NewFieldSort(fieldName string) *FieldSort { + return &FieldSort{ fieldName: fieldName, ascending: true, } } // FieldName specifies the name of the field to be used for sorting. -func (s FieldSort) FieldName(fieldName string) FieldSort { +func (s *FieldSort) FieldName(fieldName string) *FieldSort { s.fieldName = fieldName return s } // Order defines whether sorting ascending (default) or descending. -func (s FieldSort) Order(ascending bool) FieldSort { +func (s *FieldSort) Order(ascending bool) *FieldSort { s.ascending = ascending return s } // Asc sets ascending sort order. -func (s FieldSort) Asc() FieldSort { +func (s *FieldSort) Asc() *FieldSort { s.ascending = true return s } // Desc sets descending sort order. -func (s FieldSort) Desc() FieldSort { +func (s *FieldSort) Desc() *FieldSort { s.ascending = false return s } @@ -151,21 +170,21 @@ func (s FieldSort) Desc() FieldSort { // Missing sets the value to be used when a field is missing in a document. // You can also use "_last" or "_first" to sort missing last or first // respectively. -func (s FieldSort) Missing(missing interface{}) FieldSort { +func (s *FieldSort) Missing(missing interface{}) *FieldSort { s.missing = missing return s } // IgnoreUnmapped specifies what happens if the field does not exist in // the index. Set it to true to ignore, or set it to false to not ignore (default). -func (s FieldSort) IgnoreUnmapped(ignoreUnmapped bool) FieldSort { +func (s *FieldSort) IgnoreUnmapped(ignoreUnmapped bool) *FieldSort { s.ignoreUnmapped = &ignoreUnmapped return s } // UnmappedType sets the type to use when the current field is not mapped // in an index. -func (s FieldSort) UnmappedType(typ string) FieldSort { +func (s *FieldSort) UnmappedType(typ string) *FieldSort { s.unmappedType = &typ return s } @@ -173,27 +192,27 @@ func (s FieldSort) UnmappedType(typ string) FieldSort { // SortMode specifies what values to pick in case a document contains // multiple values for the targeted sort field. Possible values are: // min, max, sum, and avg. -func (s FieldSort) SortMode(sortMode string) FieldSort { +func (s *FieldSort) SortMode(sortMode string) *FieldSort { s.sortMode = &sortMode return s } // NestedFilter sets a filter that nested objects should match with // in order to be taken into account for sorting. -func (s FieldSort) NestedFilter(nestedFilter Query) FieldSort { +func (s *FieldSort) NestedFilter(nestedFilter Query) *FieldSort { s.nestedFilter = nestedFilter return s } // NestedPath is used if sorting occurs on a field that is inside a // nested object. -func (s FieldSort) NestedPath(nestedPath string) FieldSort { +func (s *FieldSort) NestedPath(nestedPath string) *FieldSort { s.nestedPath = &nestedPath return s } // Source returns the JSON-serializable data. -func (s FieldSort) Source() (interface{}, error) { +func (s *FieldSort) Source() (interface{}, error) { source := make(map[string]interface{}) x := make(map[string]interface{}) source[s.fieldName] = x @@ -230,7 +249,7 @@ func (s FieldSort) Source() (interface{}, error) { // -- GeoDistanceSort -- // GeoDistanceSort allows for sorting by geographic distance. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_geo_distance_sorting. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-sort.html#_geo_distance_sorting. type GeoDistanceSort struct { Sorter fieldName string @@ -245,69 +264,67 @@ type GeoDistanceSort struct { } // NewGeoDistanceSort creates a new sorter for geo distances. -func NewGeoDistanceSort(fieldName string) GeoDistanceSort { - return GeoDistanceSort{ +func NewGeoDistanceSort(fieldName string) *GeoDistanceSort { + return &GeoDistanceSort{ fieldName: fieldName, - points: make([]*GeoPoint, 0), - geohashes: make([]string, 0), ascending: true, } } // FieldName specifies the name of the (geo) field to use for sorting. -func (s GeoDistanceSort) FieldName(fieldName string) GeoDistanceSort { +func (s *GeoDistanceSort) FieldName(fieldName string) *GeoDistanceSort { s.fieldName = fieldName return s } // Order defines whether sorting ascending (default) or descending. -func (s GeoDistanceSort) Order(ascending bool) GeoDistanceSort { +func (s *GeoDistanceSort) Order(ascending bool) *GeoDistanceSort { s.ascending = ascending return s } // Asc sets ascending sort order. -func (s GeoDistanceSort) Asc() GeoDistanceSort { +func (s *GeoDistanceSort) Asc() *GeoDistanceSort { s.ascending = true return s } // Desc sets descending sort order. -func (s GeoDistanceSort) Desc() GeoDistanceSort { +func (s *GeoDistanceSort) Desc() *GeoDistanceSort { s.ascending = false return s } // Point specifies a point to create the range distance aggregations from. -func (s GeoDistanceSort) Point(lat, lon float64) GeoDistanceSort { +func (s *GeoDistanceSort) Point(lat, lon float64) *GeoDistanceSort { s.points = append(s.points, GeoPointFromLatLon(lat, lon)) return s } // Points specifies the geo point(s) to create the range distance aggregations from. -func (s GeoDistanceSort) Points(points ...*GeoPoint) GeoDistanceSort { +func (s *GeoDistanceSort) Points(points ...*GeoPoint) *GeoDistanceSort { s.points = append(s.points, points...) return s } // GeoHashes specifies the geo point to create the range distance aggregations from. -func (s GeoDistanceSort) GeoHashes(geohashes ...string) GeoDistanceSort { +func (s *GeoDistanceSort) GeoHashes(geohashes ...string) *GeoDistanceSort { s.geohashes = append(s.geohashes, geohashes...) return s } // GeoDistance represents how to compute the distance. // It can be sloppy_arc (default), arc, or plane. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_geo_distance_sorting. -func (s GeoDistanceSort) GeoDistance(geoDistance string) GeoDistanceSort { +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-sort.html#_geo_distance_sorting. +func (s *GeoDistanceSort) GeoDistance(geoDistance string) *GeoDistanceSort { s.geoDistance = &geoDistance return s } // Unit specifies the distance unit to use. It defaults to km. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/common-options.html#distance-units +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/common-options.html#distance-units // for details. -func (s GeoDistanceSort) Unit(unit string) GeoDistanceSort { +func (s *GeoDistanceSort) Unit(unit string) *GeoDistanceSort { s.unit = unit return s } @@ -315,33 +332,33 @@ func (s GeoDistanceSort) Unit(unit string) GeoDistanceSort { // SortMode specifies what values to pick in case a document contains // multiple values for the targeted sort field. Possible values are: // min, max, sum, and avg. -func (s GeoDistanceSort) SortMode(sortMode string) GeoDistanceSort { +func (s *GeoDistanceSort) SortMode(sortMode string) *GeoDistanceSort { s.sortMode = &sortMode return s } // NestedFilter sets a filter that nested objects should match with // in order to be taken into account for sorting. -func (s GeoDistanceSort) NestedFilter(nestedFilter Query) GeoDistanceSort { +func (s *GeoDistanceSort) NestedFilter(nestedFilter Query) *GeoDistanceSort { s.nestedFilter = nestedFilter return s } // NestedPath is used if sorting occurs on a field that is inside a // nested object. -func (s GeoDistanceSort) NestedPath(nestedPath string) GeoDistanceSort { +func (s *GeoDistanceSort) NestedPath(nestedPath string) *GeoDistanceSort { s.nestedPath = &nestedPath return s } // Source returns the JSON-serializable data. -func (s GeoDistanceSort) Source() (interface{}, error) { +func (s *GeoDistanceSort) Source() (interface{}, error) { source := make(map[string]interface{}) x := make(map[string]interface{}) source["_geo_distance"] = x // Points - ptarr := make([]interface{}, 0) + var ptarr []interface{} for _, pt := range s.points { ptarr = append(ptarr, pt.Source()) } @@ -357,8 +374,10 @@ func (s GeoDistanceSort) Source() (interface{}, error) { x["distance_type"] = *s.geoDistance } - if !s.ascending { - x["reverse"] = true + if s.ascending { + x["order"] = "asc" + } else { + x["order"] = "desc" } if s.sortMode != nil { x["mode"] = *s.sortMode @@ -379,7 +398,7 @@ func (s GeoDistanceSort) Source() (interface{}, error) { // -- ScriptSort -- // ScriptSort sorts by a custom script. See -// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html#modules-scripting +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/modules-scripting.html#modules-scripting // for details about scripting. type ScriptSort struct { Sorter @@ -393,8 +412,8 @@ type ScriptSort struct { // NewScriptSort creates and initializes a new ScriptSort. // You must provide a script and a type, e.g. "string" or "number". -func NewScriptSort(script *Script, typ string) ScriptSort { - return ScriptSort{ +func NewScriptSort(script *Script, typ string) *ScriptSort { + return &ScriptSort{ script: script, typ: typ, ascending: true, @@ -402,25 +421,25 @@ func NewScriptSort(script *Script, typ string) ScriptSort { } // Type sets the script type, which can be either "string" or "number". -func (s ScriptSort) Type(typ string) ScriptSort { +func (s *ScriptSort) Type(typ string) *ScriptSort { s.typ = typ return s } // Order defines whether sorting ascending (default) or descending. -func (s ScriptSort) Order(ascending bool) ScriptSort { +func (s *ScriptSort) Order(ascending bool) *ScriptSort { s.ascending = ascending return s } // Asc sets ascending sort order. -func (s ScriptSort) Asc() ScriptSort { +func (s *ScriptSort) Asc() *ScriptSort { s.ascending = true return s } // Desc sets descending sort order. -func (s ScriptSort) Desc() ScriptSort { +func (s *ScriptSort) Desc() *ScriptSort { s.ascending = false return s } @@ -428,27 +447,27 @@ func (s ScriptSort) Desc() ScriptSort { // SortMode specifies what values to pick in case a document contains // multiple values for the targeted sort field. Possible values are: // min or max. -func (s ScriptSort) SortMode(sortMode string) ScriptSort { +func (s *ScriptSort) SortMode(sortMode string) *ScriptSort { s.sortMode = &sortMode return s } // NestedFilter sets a filter that nested objects should match with // in order to be taken into account for sorting. -func (s ScriptSort) NestedFilter(nestedFilter Query) ScriptSort { +func (s *ScriptSort) NestedFilter(nestedFilter Query) *ScriptSort { s.nestedFilter = nestedFilter return s } // NestedPath is used if sorting occurs on a field that is inside a // nested object. -func (s ScriptSort) NestedPath(nestedPath string) ScriptSort { +func (s *ScriptSort) NestedPath(nestedPath string) *ScriptSort { s.nestedPath = &nestedPath return s } // Source returns the JSON-serializable data. -func (s ScriptSort) Source() (interface{}, error) { +func (s *ScriptSort) Source() (interface{}, error) { if s.script == nil { return nil, errors.New("ScriptSort expected a script") } @@ -464,8 +483,10 @@ func (s ScriptSort) Source() (interface{}, error) { x["type"] = s.typ - if !s.ascending { - x["reverse"] = true + if s.ascending { + x["order"] = "asc" + } else { + x["order"] = "desc" } if s.sortMode != nil { x["mode"] = *s.sortMode diff --git a/vendor/gopkg.in/olivere/elastic.v3/suggest.go b/vendor/gopkg.in/olivere/elastic.v5/suggest.go similarity index 60% rename from vendor/gopkg.in/olivere/elastic.v3/suggest.go rename to vendor/gopkg.in/olivere/elastic.v5/suggest.go index f51437f6a..b45cf3545 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/suggest.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggest.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -10,75 +10,79 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // SuggestService returns suggestions for text. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters.html. type SuggestService struct { client *Client pretty bool routing string preference string - indices []string + index []string suggesters []Suggester } +// NewSuggestService creates a new instance of SuggestService. func NewSuggestService(client *Client) *SuggestService { builder := &SuggestService{ - client: client, - indices: make([]string, 0), - suggesters: make([]Suggester, 0), + client: client, } return builder } -func (s *SuggestService) Index(indices ...string) *SuggestService { - s.indices = append(s.indices, indices...) +// Index adds one or more indices to use for the suggestion request. +func (s *SuggestService) Index(index ...string) *SuggestService { + s.index = append(s.index, index...) return s } +// Pretty asks Elasticsearch to return indented JSON. func (s *SuggestService) Pretty(pretty bool) *SuggestService { s.pretty = pretty return s } +// Routing specifies the routing value. func (s *SuggestService) Routing(routing string) *SuggestService { s.routing = routing return s } +// Preference specifies the node or shard the operation should be +// performed on (default: random). func (s *SuggestService) Preference(preference string) *SuggestService { s.preference = preference return s } +// Suggester adds a suggester to the request. func (s *SuggestService) Suggester(suggester Suggester) *SuggestService { s.suggesters = append(s.suggesters, suggester) return s } -func (s *SuggestService) Do() (SuggestResult, error) { - // Build url - path := "/" +// buildURL builds the URL for the operation. +func (s *SuggestService) buildURL() (string, url.Values, error) { + var err error + var path string - // Indices part - indexPart := make([]string, 0) - for _, index := range s.indices { - index, err := uritemplates.Expand("{index}", map[string]string{ - "index": index, + if len(s.index) > 0 { + path, err = uritemplates.Expand("/{index}/_suggest", map[string]string{ + "index": strings.Join(s.index, ","), }) - if err != nil { - return nil, err - } - indexPart = append(indexPart, index) + } else { + path = "/_suggest" + } + if err != nil { + return "", url.Values{}, err } - path += strings.Join(indexPart, ",") - // Suggest - path += "/_suggest" - - // Parameters - params := make(url.Values) + // Add query string parameters + params := url.Values{} if s.pretty { params.Set("pretty", fmt.Sprintf("%v", s.pretty)) } @@ -88,6 +92,15 @@ func (s *SuggestService) Do() (SuggestResult, error) { if s.preference != "" { params.Set("preference", s.preference) } + return path, params, nil +} + +// Do executes the request. +func (s *SuggestService) Do(ctx context.Context) (SuggestResult, error) { + path, params, err := s.buildURL() + if err != nil { + return nil, err + } // Set body body := make(map[string]interface{}) @@ -100,7 +113,7 @@ func (s *SuggestService) Do() (SuggestResult, error) { } // Get response - res, err := s.client.PerformRequest("POST", path, params, body) + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) if err != nil { return nil, err } @@ -126,8 +139,10 @@ func (s *SuggestService) Do() (SuggestResult, error) { return ret, nil } +// SuggestResult is the outcome of SuggestService.Do. type SuggestResult map[string][]Suggestion +// Suggestion is a single suggester outcome. type Suggestion struct { Text string `json:"text"` Offset int `json:"offset"` diff --git a/vendor/gopkg.in/olivere/elastic.v3/suggest_field.go b/vendor/gopkg.in/olivere/elastic.v5/suggest_field.go similarity index 71% rename from vendor/gopkg.in/olivere/elastic.v3/suggest_field.go rename to vendor/gopkg.in/olivere/elastic.v5/suggest_field.go index 4738d9910..8e15b4ec2 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/suggest_field.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggest_field.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -6,21 +6,23 @@ package elastic import ( "encoding/json" + "errors" ) // SuggestField can be used by the caller to specify a suggest field // at index time. For a detailed example, see e.g. -// http://www.elasticsearch.org/blog/you-complete-me/. +// https://www.elastic.co/blog/you-complete-me. type SuggestField struct { inputs []string - output *string - payload interface{} weight int contextQueries []SuggesterContextQuery } -func NewSuggestField() *SuggestField { - return &SuggestField{weight: -1} +func NewSuggestField(input ...string) *SuggestField { + return &SuggestField{ + inputs: input, + weight: -1, + } } func (f *SuggestField) Input(input ...string) *SuggestField { @@ -31,16 +33,6 @@ func (f *SuggestField) Input(input ...string) *SuggestField { return f } -func (f *SuggestField) Output(output string) *SuggestField { - f.output = &output - return f -} - -func (f *SuggestField) Payload(payload interface{}) *SuggestField { - f.payload = payload - return f -} - func (f *SuggestField) Weight(weight int) *SuggestField { f.weight = weight return f @@ -64,14 +56,6 @@ func (f *SuggestField) MarshalJSON() ([]byte, error) { } } - if f.output != nil { - source["output"] = *f.output - } - - if f.payload != nil { - source["payload"] = f.payload - } - if f.weight >= 0 { source["weight"] = f.weight } @@ -85,13 +69,19 @@ func (f *SuggestField) MarshalJSON() ([]byte, error) { } source["context"] = src default: - var ctxq []interface{} + ctxq := make(map[string]interface{}) for _, query := range f.contextQueries { src, err := query.Source() if err != nil { return nil, err } - ctxq = append(ctxq, src) + m, ok := src.(map[string]interface{}) + if !ok { + return nil, errors.New("SuggesterContextQuery must be of type map[string]interface{}") + } + for k, v := range m { + ctxq[k] = v + } } source["context"] = ctxq } diff --git a/vendor/gopkg.in/olivere/elastic.v3/suggester.go b/vendor/gopkg.in/olivere/elastic.v5/suggester.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v3/suggester.go rename to vendor/gopkg.in/olivere/elastic.v5/suggester.go index c342b10d3..f7dc48f90 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/suggester.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggester.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/suggester_completion.go b/vendor/gopkg.in/olivere/elastic.v5/suggester_completion.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v3/suggester_completion.go rename to vendor/gopkg.in/olivere/elastic.v5/suggester_completion.go index e0f5a3861..df6086e63 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/suggester_completion.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggester_completion.go @@ -1,11 +1,13 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. package elastic +import "errors" + // CompletionSuggester is a fast suggester for e.g. type-ahead completion. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-completion.html // for more details. type CompletionSuggester struct { Suggester @@ -106,13 +108,20 @@ func (q *CompletionSuggester) Source(includeName bool) (interface{}, error) { } suggester["context"] = src default: - ctxq := make([]interface{}, 0) + ctxq := make(map[string]interface{}) for _, query := range q.contextQueries { src, err := query.Source() if err != nil { return nil, err } - ctxq = append(ctxq, src) + // Merge the dictionary into ctxq + m, ok := src.(map[string]interface{}) + if !ok { + return nil, errors.New("elastic: context query is not a map") + } + for k, v := range m { + ctxq[k] = v + } } suggester["context"] = ctxq } diff --git a/vendor/gopkg.in/olivere/elastic.v3/suggester_completion_fuzzy.go b/vendor/gopkg.in/olivere/elastic.v5/suggester_completion_fuzzy.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/suggester_completion_fuzzy.go rename to vendor/gopkg.in/olivere/elastic.v5/suggester_completion_fuzzy.go index 1c4455a61..e2c06a25f 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/suggester_completion_fuzzy.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggester_completion_fuzzy.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -6,9 +6,9 @@ package elastic // FuzzyFuzzyCompletionSuggester is a FuzzyCompletionSuggester that allows fuzzy // completion. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-completion.html // for details, and -// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html#fuzzy +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-completion.html#fuzzy // for details about the fuzzy completion suggester. type FuzzyCompletionSuggester struct { Suggester @@ -80,7 +80,7 @@ func (q *FuzzyCompletionSuggester) ContextQueries(queries ...SuggesterContextQue // Fuzziness defines the strategy used to describe what "fuzzy" actually // means for the suggester, e.g. 1, 2, "0", "1..2", ">4", or "AUTO". -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/common-options.html#fuzziness +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/common-options.html#fuzziness // for a detailed description. func (q *FuzzyCompletionSuggester) Fuzziness(fuzziness interface{}) *FuzzyCompletionSuggester { q.fuzziness = fuzziness @@ -139,7 +139,7 @@ func (q *FuzzyCompletionSuggester) Source(includeName bool) (interface{}, error) } suggester["context"] = src default: - ctxq := make([]interface{}, 0) + var ctxq []interface{} for _, query := range q.contextQueries { src, err := query.Source() if err != nil { diff --git a/vendor/gopkg.in/olivere/elastic.v3/suggester_context.go b/vendor/gopkg.in/olivere/elastic.v5/suggester_context.go similarity index 82% rename from vendor/gopkg.in/olivere/elastic.v3/suggester_context.go rename to vendor/gopkg.in/olivere/elastic.v5/suggester_context.go index 0903f2171..caf477669 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/suggester_context.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggester_context.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. diff --git a/vendor/gopkg.in/olivere/elastic.v3/suggester_context_category.go b/vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go similarity index 89% rename from vendor/gopkg.in/olivere/elastic.v3/suggester_context_category.go rename to vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go index 4b8e43f88..c224ae04a 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/suggester_context_category.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -7,7 +7,7 @@ package elastic // -- SuggesterCategoryMapping -- // SuggesterCategoryMapping provides a mapping for a category context in a suggester. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/suggester-context.html#_category_mapping. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_category_mapping. type SuggesterCategoryMapping struct { name string fieldName string @@ -59,7 +59,7 @@ func (q *SuggesterCategoryMapping) Source() (interface{}, error) { // -- SuggesterCategoryQuery -- // SuggesterCategoryQuery provides querying a category context in a suggester. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/suggester-context.html#_category_query. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_category_query. type SuggesterCategoryQuery struct { name string values []string diff --git a/vendor/gopkg.in/olivere/elastic.v3/suggester_context_geo.go b/vendor/gopkg.in/olivere/elastic.v5/suggester_context_geo.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v3/suggester_context_geo.go rename to vendor/gopkg.in/olivere/elastic.v5/suggester_context_geo.go index bde1a4067..6815bfe73 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/suggester_context_geo.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggester_context_geo.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -7,7 +7,7 @@ package elastic // -- SuggesterGeoMapping -- // SuggesterGeoMapping provides a mapping for a geolocation context in a suggester. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/suggester-context.html#_geo_location_mapping. +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_geo_location_mapping. type SuggesterGeoMapping struct { name string defaultLocations []*GeoPoint @@ -19,9 +19,7 @@ type SuggesterGeoMapping struct { // NewSuggesterGeoMapping creates a new SuggesterGeoMapping. func NewSuggesterGeoMapping(name string) *SuggesterGeoMapping { return &SuggesterGeoMapping{ - name: name, - defaultLocations: make([]*GeoPoint, 0), - precision: make([]string, 0), + name: name, } } @@ -66,7 +64,7 @@ func (q *SuggesterGeoMapping) Source() (interface{}, error) { case 1: x["default"] = q.defaultLocations[0].Source() default: - arr := make([]interface{}, 0) + var arr []interface{} for _, p := range q.defaultLocations { arr = append(arr, p.Source()) } @@ -82,7 +80,7 @@ func (q *SuggesterGeoMapping) Source() (interface{}, error) { // -- SuggesterGeoQuery -- // SuggesterGeoQuery provides querying a geolocation context in a suggester. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/suggester-context.html#_geo_location_query +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_geo_location_query type SuggesterGeoQuery struct { name string location *GeoPoint diff --git a/vendor/gopkg.in/olivere/elastic.v3/suggester_phrase.go b/vendor/gopkg.in/olivere/elastic.v5/suggester_phrase.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v3/suggester_phrase.go rename to vendor/gopkg.in/olivere/elastic.v5/suggester_phrase.go index ee46329f0..f75e1ddc1 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/suggester_phrase.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggester_phrase.go @@ -1,11 +1,13 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. package elastic +// PhraseSuggester provides an API to access word alternatives +// on a per token basis within a certain string distance. // For more details, see -// http://www.elasticsearch.org/guide/reference/api/search/phrase-suggest/ +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-phrase.html. type PhraseSuggester struct { Suggester name string @@ -33,12 +35,11 @@ type PhraseSuggester struct { collatePrune *bool } -// Creates a new phrase suggester. +// NewPhraseSuggester creates a new PhraseSuggester. func NewPhraseSuggester(name string) *PhraseSuggester { return &PhraseSuggester{ - name: name, - contextQueries: make([]SuggesterContextQuery, 0), - collateParams: make(map[string]interface{}), + name: name, + collateParams: make(map[string]interface{}), } } @@ -173,7 +174,7 @@ func (q *PhraseSuggester) CollatePrune(collatePrune bool) *PhraseSuggester { return q } -// simplePhraseSuggesterRequest is necessary because the order in which +// phraseSuggesterRequest is necessary because the order in which // the JSON elements are routed to Elasticsearch is relevant. // We got into trouble when using plain maps because the text element // needs to go before the simple_phrase element. @@ -182,7 +183,7 @@ type phraseSuggesterRequest struct { Phrase interface{} `json:"phrase"` } -// Creates the source for the phrase suggester. +// Source generates the source for the phrase suggester. func (q *PhraseSuggester) Source(includeName bool) (interface{}, error) { ps := &phraseSuggesterRequest{} @@ -214,7 +215,7 @@ func (q *PhraseSuggester) Source(includeName bool) (interface{}, error) { } suggester["context"] = src default: - ctxq := make([]interface{}, 0) + var ctxq []interface{} for _, query := range q.contextQueries { src, err := query.Source() if err != nil { @@ -249,7 +250,7 @@ func (q *PhraseSuggester) Source(includeName bool) (interface{}, error) { } if q.generators != nil && len(q.generators) > 0 { for typ, generators := range q.generators { - arr := make([]interface{}, 0) + var arr []interface{} for _, g := range generators { src, err := g.Source() if err != nil { @@ -311,7 +312,7 @@ type SmoothingModel interface { } // StupidBackoffSmoothingModel implements a stupid backoff smoothing model. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html#_smoothing_models +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-phrase.html#_smoothing_models // for details about smoothing models. type StupidBackoffSmoothingModel struct { discount float64 @@ -336,7 +337,7 @@ func (sm *StupidBackoffSmoothingModel) Source() (interface{}, error) { // -- // LaplaceSmoothingModel implements a laplace smoothing model. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html#_smoothing_models +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-phrase.html#_smoothing_models // for details about smoothing models. type LaplaceSmoothingModel struct { alpha float64 @@ -362,7 +363,7 @@ func (sm *LaplaceSmoothingModel) Source() (interface{}, error) { // LinearInterpolationSmoothingModel implements a linear interpolation // smoothing model. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html#_smoothing_models +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-phrase.html#_smoothing_models // for details about smoothing models. type LinearInterpolationSmoothingModel struct { trigramLamda float64 @@ -398,7 +399,7 @@ type CandidateGenerator interface { } // DirectCandidateGenerator implements a direct candidate generator. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html#_smoothing_models +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-phrase.html#_smoothing_models // for details about smoothing models. type DirectCandidateGenerator struct { field string diff --git a/vendor/gopkg.in/olivere/elastic.v3/suggester_term.go b/vendor/gopkg.in/olivere/elastic.v5/suggester_term.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/suggester_term.go rename to vendor/gopkg.in/olivere/elastic.v5/suggester_term.go index 116af405a..6dcbbc646 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/suggester_term.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggester_term.go @@ -1,11 +1,12 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. package elastic +// TermSuggester suggests terms based on edit distance. // For more details, see -// http://www.elasticsearch.org/guide/reference/api/search/term-suggest/ +// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-term.html. type TermSuggester struct { Suggester name string @@ -29,11 +30,10 @@ type TermSuggester struct { minDocFreq *float64 } -// Creates a new term suggester. +// NewTermSuggester creates a new TermSuggester. func NewTermSuggester(name string) *TermSuggester { return &TermSuggester{ - name: name, - contextQueries: make([]SuggesterContextQuery, 0), + name: name, } } @@ -135,7 +135,7 @@ type termSuggesterRequest struct { Term interface{} `json:"term"` } -// Creates the source for the term suggester. +// Source generates the source for the term suggester. func (q *TermSuggester) Source(includeName bool) (interface{}, error) { // "suggest" : { // "my-suggest-1" : { @@ -180,13 +180,13 @@ func (q *TermSuggester) Source(includeName bool) (interface{}, error) { } suggester["context"] = src default: - ctxq := make([]interface{}, 0) - for _, query := range q.contextQueries { + ctxq := make([]interface{}, len(q.contextQueries)) + for i, query := range q.contextQueries { src, err := query.Source() if err != nil { return nil, err } - ctxq = append(ctxq, src) + ctxq[i] = src } suggester["context"] = ctxq } diff --git a/vendor/gopkg.in/olivere/elastic.v3/tasks_cancel.go b/vendor/gopkg.in/olivere/elastic.v5/tasks_cancel.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v3/tasks_cancel.go rename to vendor/gopkg.in/olivere/elastic.v5/tasks_cancel.go index 7ee5c5cc3..0c2e00a01 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/tasks_cancel.go +++ b/vendor/gopkg.in/olivere/elastic.v5/tasks_cancel.go @@ -9,13 +9,15 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // TasksCancelService can cancel long-running tasks. // It is supported as of Elasticsearch 2.3.0. // -// See http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks-cancel.html +// See http://www.elastic.co/guide/en/elasticsearch/reference/5.2/tasks-cancel.html // for details. type TasksCancelService struct { client *Client @@ -117,7 +119,7 @@ func (s *TasksCancelService) Validate() error { } // Do executes the operation. -func (s *TasksCancelService) Do() (*TasksListResponse, error) { +func (s *TasksCancelService) Do(ctx context.Context) (*TasksListResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -130,7 +132,7 @@ func (s *TasksCancelService) Do() (*TasksListResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/tasks_list.go b/vendor/gopkg.in/olivere/elastic.v5/tasks_list.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v3/tasks_list.go rename to vendor/gopkg.in/olivere/elastic.v5/tasks_list.go index f74ede19f..898ac2a55 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/tasks_list.go +++ b/vendor/gopkg.in/olivere/elastic.v5/tasks_list.go @@ -9,12 +9,14 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // TasksListService retrieves the list of currently executing tasks // on one ore more nodes in the cluster. It is part of the Task Management API -// documented at http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks-list.html. +// documented at http://www.elastic.co/guide/en/elasticsearch/reference/5.2/tasks-list.html. // // It is supported as of Elasticsearch 2.3.0. type TasksListService struct { @@ -142,7 +144,7 @@ func (s *TasksListService) Validate() error { } // Do executes the operation. -func (s *TasksListService) Do() (*TasksListResponse, error) { +func (s *TasksListService) Do(ctx context.Context) (*TasksListResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -155,7 +157,7 @@ func (s *TasksListService) Do() (*TasksListResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/termvectors.go b/vendor/gopkg.in/olivere/elastic.v5/termvectors.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v3/termvectors.go rename to vendor/gopkg.in/olivere/elastic.v5/termvectors.go index c00a3363b..627ee11db 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/termvectors.go +++ b/vendor/gopkg.in/olivere/elastic.v5/termvectors.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,14 +9,16 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // TermvectorsService returns information and statistics on terms in the // fields of a particular document. The document could be stored in the // index or artificially provided by the user. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/2.1/docs-termvectors.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-termvectors.html // for documentation. type TermvectorsService struct { client *Client @@ -276,7 +278,7 @@ func (s *TermvectorsService) Validate() error { } // Do executes the operation. -func (s *TermvectorsService) Do() (*TermvectorsResponse, error) { +func (s *TermvectorsService) Do(ctx context.Context) (*TermvectorsResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -315,7 +317,7 @@ func (s *TermvectorsService) Do() (*TermvectorsResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest("GET", path, params, body) + res, err := s.client.PerformRequest(ctx, "GET", path, params, body) if err != nil { return nil, err } @@ -332,7 +334,7 @@ func (s *TermvectorsService) Do() (*TermvectorsResponse, error) { // TermvectorsFilterSettings adds additional filters to a Termsvector request. // It allows to filter terms based on their tf-idf scores. -// See https://www.elastic.co/guide/en/elasticsearch/reference/2.1/docs-termvectors.html#_terms_filtering +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-termvectors.html#_terms_filtering // for more information. type TermvectorsFilterSettings struct { maxNumTerms *int64 diff --git a/vendor/gopkg.in/olivere/elastic.v3/update.go b/vendor/gopkg.in/olivere/elastic.v5/update.go similarity index 78% rename from vendor/gopkg.in/olivere/elastic.v3/update.go rename to vendor/gopkg.in/olivere/elastic.v5/update.go index 3d99ee860..a15d30bb9 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/update.go +++ b/vendor/gopkg.in/olivere/elastic.v5/update.go @@ -1,4 +1,4 @@ -// Copyright 2012-2015 Oliver Eilhard. All rights reserved. +// Copyright 2012-present Oliver Eilhard. All rights reserved. // Use of this source code is governed by a MIT-license. // See http://olivere.mit-license.org/license.txt for details. @@ -9,34 +9,35 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // UpdateService updates a document in Elasticsearch. -// See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-update.html // for details. type UpdateService struct { - client *Client - index string - typ string - id string - routing string - parent string - script *Script - fields []string - version *int64 - versionType string - retryOnConflict *int - refresh *bool - replicationType string - consistencyLevel string - upsert interface{} - scriptedUpsert *bool - docAsUpsert *bool - detectNoop *bool - doc interface{} - timeout string - pretty bool + client *Client + index string + typ string + id string + routing string + parent string + script *Script + fields []string + version *int64 + versionType string + retryOnConflict *int + refresh string + waitForActiveShards string + upsert interface{} + scriptedUpsert *bool + docAsUpsert *bool + detectNoop *bool + doc interface{} + timeout string + pretty bool } // NewUpdateService creates the service to update documents in Elasticsearch. @@ -111,21 +112,17 @@ func (b *UpdateService) VersionType(versionType string) *UpdateService { } // Refresh the index after performing the update. -func (b *UpdateService) Refresh(refresh bool) *UpdateService { - b.refresh = &refresh +func (b *UpdateService) Refresh(refresh string) *UpdateService { + b.refresh = refresh return b } -// ReplicationType is one of "sync" or "async". -func (b *UpdateService) ReplicationType(replicationType string) *UpdateService { - b.replicationType = replicationType - return b -} - -// ConsistencyLevel is one of "one", "quorum", or "all". -// It sets the write consistency setting for the update operation. -func (b *UpdateService) ConsistencyLevel(consistencyLevel string) *UpdateService { - b.consistencyLevel = consistencyLevel +// WaitForActiveShards sets the number of shard copies that must be active before +// proceeding with the update operation. Defaults to 1, meaning the primary shard only. +// Set to `all` for all shard copies, otherwise set to any non-negative value less than +// or equal to the total number of copies for the shard (number of replicas + 1). +func (b *UpdateService) WaitForActiveShards(waitForActiveShards string) *UpdateService { + b.waitForActiveShards = waitForActiveShards return b } @@ -203,14 +200,11 @@ func (b *UpdateService) url() (string, url.Values, error) { if b.timeout != "" { params.Set("timeout", b.timeout) } - if b.refresh != nil { - params.Set("refresh", fmt.Sprintf("%v", *b.refresh)) + if b.refresh != "" { + params.Set("refresh", b.refresh) } - if b.replicationType != "" { - params.Set("replication", b.replicationType) - } - if b.consistencyLevel != "" { - params.Set("consistency", b.consistencyLevel) + if b.waitForActiveShards != "" { + params.Set("wait_for_active_shards", b.waitForActiveShards) } if len(b.fields) > 0 { params.Set("fields", strings.Join(b.fields, ",")) @@ -262,7 +256,7 @@ func (b *UpdateService) body() (interface{}, error) { } // Do executes the update operation. -func (b *UpdateService) Do() (*UpdateResponse, error) { +func (b *UpdateService) Do(ctx context.Context) (*UpdateResponse, error) { path, params, err := b.url() if err != nil { return nil, err @@ -275,7 +269,7 @@ func (b *UpdateService) Do() (*UpdateResponse, error) { } // Get response - res, err := b.client.PerformRequest("POST", path, params, body) + res, err := b.client.PerformRequest(ctx, "POST", path, params, body) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v3/update_by_query.go b/vendor/gopkg.in/olivere/elastic.v5/update_by_query.go similarity index 82% rename from vendor/gopkg.in/olivere/elastic.v3/update_by_query.go rename to vendor/gopkg.in/olivere/elastic.v5/update_by_query.go index 28664c7df..a4e7bf25b 100644 --- a/vendor/gopkg.in/olivere/elastic.v3/update_by_query.go +++ b/vendor/gopkg.in/olivere/elastic.v5/update_by_query.go @@ -9,7 +9,9 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v3/uritemplates" + "golang.org/x/net/context" + + "gopkg.in/olivere/elastic.v5/uritemplates" ) // UpdateByQueryService is documented at https://www.elastic.co/guide/en/elasticsearch/plugins/master/plugins-reindex.html. @@ -18,6 +20,9 @@ type UpdateByQueryService struct { pretty bool index []string typ []string + script *Script + query Query + body interface{} xSource []string xSourceExclude []string xSourceInclude []string @@ -25,21 +30,22 @@ type UpdateByQueryService struct { analyzeWildcard *bool analyzer string conflicts string - consistency string defaultOperator string + docvalueFields []string df string expandWildcards string explain *bool fielddataFields []string - fields []string from *int ignoreUnavailable *bool lenient *bool lowercaseExpandedTerms *bool + pipeline string preference string q string - refresh *bool + refresh string requestCache *bool + requestsPerSecond *int routing []string scroll string scrollSize *int @@ -48,6 +54,7 @@ type UpdateByQueryService struct { size *int sort []string stats []string + storedFields []string suggestField string suggestMode string suggestSize *int @@ -57,28 +64,24 @@ type UpdateByQueryService struct { trackScores *bool version *bool versionType *bool + waitForActiveShards string waitForCompletion *bool - script *Script - query Query - bodyJson interface{} - bodyString string } // NewUpdateByQueryService creates a new UpdateByQueryService. func NewUpdateByQueryService(client *Client) *UpdateByQueryService { return &UpdateByQueryService{ - client: client, - xSource: make([]string, 0), - xSourceExclude: make([]string, 0), - xSourceInclude: make([]string, 0), - fielddataFields: make([]string, 0), - fields: make([]string, 0), - routing: make([]string, 0), - sort: make([]string, 0), - stats: make([]string, 0), + client: client, } } +// Index is a list of index names to search; use `_all` or empty string to +// perform the operation on all indices. +func (s *UpdateByQueryService) Index(index ...string) *UpdateByQueryService { + s.index = append(s.index, index...) + return s +} + // Type is a list of document types to search; leave empty to perform // the operation on all types. func (s *UpdateByQueryService) Type(typ ...string) *UpdateByQueryService { @@ -86,10 +89,22 @@ func (s *UpdateByQueryService) Type(typ ...string) *UpdateByQueryService { return s } -// Index is a list of index names to search; use `_all` or empty string to -// perform the operation on all indices. -func (s *UpdateByQueryService) Index(index ...string) *UpdateByQueryService { - s.index = append(s.index, index...) +// Pretty indicates that the JSON response be indented and human readable. +func (s *UpdateByQueryService) Pretty(pretty bool) *UpdateByQueryService { + s.pretty = pretty + return s +} + +// Script sets an update script. +func (s *UpdateByQueryService) Script(script *Script) *UpdateByQueryService { + s.script = script + return s +} + +// Body specifies the body of the request. It overrides data being specified via +// SearchService or Script. +func (s *UpdateByQueryService) Body(body string) *UpdateByQueryService { + s.body = body return s } @@ -154,25 +169,24 @@ func (s *UpdateByQueryService) ProceedOnVersionConflict() *UpdateByQueryService return s } -// Consistency sets an explicit write consistency setting for the operation. -// Possible values are "one", "quorum", and "all". -func (s *UpdateByQueryService) Consistency(consistency string) *UpdateByQueryService { - s.consistency = consistency - return s -} - // DefaultOperator is the default operator for query string query (AND or OR). func (s *UpdateByQueryService) DefaultOperator(defaultOperator string) *UpdateByQueryService { s.defaultOperator = defaultOperator return s } -// Df specifies the field to use as default where no field prefix is given in the query string. -func (s *UpdateByQueryService) Df(df string) *UpdateByQueryService { +// DF specifies the field to use as default where no field prefix is given in the query string. +func (s *UpdateByQueryService) DF(df string) *UpdateByQueryService { s.df = df return s } +// DocvalueFields specifies the list of fields to return as the docvalue representation of a field for each hit. +func (s *UpdateByQueryService) DocvalueFields(docvalueFields ...string) *UpdateByQueryService { + s.docvalueFields = docvalueFields + return s +} + // ExpandWildcards indicates whether to expand wildcard expression to // concrete indices that are open, closed or both. func (s *UpdateByQueryService) ExpandWildcards(expandWildcards string) *UpdateByQueryService { @@ -194,12 +208,6 @@ func (s *UpdateByQueryService) FielddataFields(fielddataFields ...string) *Updat return s } -// Fields is a list of fields to return as part of a hit. -func (s *UpdateByQueryService) Fields(fields ...string) *UpdateByQueryService { - s.fields = append(s.fields, fields...) - return s -} - // From is the starting offset (default: 0). func (s *UpdateByQueryService) From(from int) *UpdateByQueryService { s.from = &from @@ -226,6 +234,12 @@ func (s *UpdateByQueryService) LowercaseExpandedTerms(lowercaseExpandedTerms boo return s } +// Pipeline specifies the ingest pipeline to set on index requests made by this action (default: none). +func (s *UpdateByQueryService) Pipeline(pipeline string) *UpdateByQueryService { + s.pipeline = pipeline + return s +} + // Preference specifies the node or shard the operation should be performed on // (default: random). func (s *UpdateByQueryService) Preference(preference string) *UpdateByQueryService { @@ -233,15 +247,21 @@ func (s *UpdateByQueryService) Preference(preference string) *UpdateByQueryServi return s } -// Query in the Lucene query string syntax. +// Q specifies the query in the Lucene query string syntax. func (s *UpdateByQueryService) Q(q string) *UpdateByQueryService { s.q = q return s } +// Query sets a query definition using the Query DSL. +func (s *UpdateByQueryService) Query(query Query) *UpdateByQueryService { + s.query = query + return s +} + // Refresh indicates whether the effected indexes should be refreshed. -func (s *UpdateByQueryService) Refresh(refresh bool) *UpdateByQueryService { - s.refresh = &refresh +func (s *UpdateByQueryService) Refresh(refresh string) *UpdateByQueryService { + s.refresh = refresh return s } @@ -252,6 +272,13 @@ func (s *UpdateByQueryService) RequestCache(requestCache bool) *UpdateByQuerySer return s } +// RequestsPerSecond sets the throttle on this request in sub-requests per second. +// -1 means set no throttle as does "unlimited" which is the only non-float this accepts. +func (s *UpdateByQueryService) RequestsPerSecond(requestsPerSecond int) *UpdateByQueryService { + s.requestsPerSecond = &requestsPerSecond + return s +} + // Routing is a list of specific routing values. func (s *UpdateByQueryService) Routing(routing ...string) *UpdateByQueryService { s.routing = append(s.routing, routing...) @@ -313,6 +340,12 @@ func (s *UpdateByQueryService) Stats(stats ...string) *UpdateByQueryService { return s } +// StoredFields specifies the list of stored fields to return as part of a hit. +func (s *UpdateByQueryService) StoredFields(storedFields ...string) *UpdateByQueryService { + s.storedFields = storedFields + return s +} + // SuggestField specifies which field to use for suggestions. func (s *UpdateByQueryService) SuggestField(suggestField string) *UpdateByQueryService { s.suggestField = suggestField @@ -378,65 +411,35 @@ func (s *UpdateByQueryService) VersionType(versionType bool) *UpdateByQueryServi return s } +// WaitForActiveShards sets the number of shard copies that must be active before proceeding +// with the update by query operation. Defaults to 1, meaning the primary shard only. +// Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal +// to the total number of copies for the shard (number of replicas + 1). +func (s *UpdateByQueryService) WaitForActiveShards(waitForActiveShards string) *UpdateByQueryService { + s.waitForActiveShards = waitForActiveShards + return s +} + // WaitForCompletion indicates if the request should block until the reindex is complete. func (s *UpdateByQueryService) WaitForCompletion(waitForCompletion bool) *UpdateByQueryService { s.waitForCompletion = &waitForCompletion return s } -// Pretty indicates that the JSON response be indented and human readable. -func (s *UpdateByQueryService) Pretty(pretty bool) *UpdateByQueryService { - s.pretty = pretty - return s -} - -// Script sets an update script. -func (s *UpdateByQueryService) Script(script *Script) *UpdateByQueryService { - s.script = script - return s -} - -// Query sets a query definition using the Query DSL. -func (s *UpdateByQueryService) Query(query Query) *UpdateByQueryService { - s.query = query - return s -} - -// BodyJson specifies e.g. the query to restrict the results specified with the -// Query DSL (optional). The interface{} will be serialized to a JSON document, -// so use a map[string]interface{}. -func (s *UpdateByQueryService) BodyJson(body interface{}) *UpdateByQueryService { - s.bodyJson = body - return s -} - -// Body specifies e.g. a query to restrict the results specified with -// the Query DSL (optional). -func (s *UpdateByQueryService) BodyString(body string) *UpdateByQueryService { - s.bodyString = body - return s -} - // buildURL builds the URL for the operation. func (s *UpdateByQueryService) buildURL() (string, url.Values, error) { // Build URL var err error var path string - if len(s.index) > 0 && len(s.typ) > 0 { + if len(s.typ) > 0 { path, err = uritemplates.Expand("/{index}/{type}/_update_by_query", map[string]string{ "index": strings.Join(s.index, ","), "type": strings.Join(s.typ, ","), }) - } else if len(s.index) > 0 && len(s.typ) == 0 { + } else { path, err = uritemplates.Expand("/{index}/_update_by_query", map[string]string{ "index": strings.Join(s.index, ","), }) - } else if len(s.index) == 0 && len(s.typ) > 0 { - path, err = uritemplates.Expand("/_all/{type}/_update_by_query", map[string]string{ - "type": strings.Join(s.typ, ","), - }) - } else { - path = "/_all/_update_by_query" } if err != nil { return "", url.Values{}, err @@ -459,18 +462,15 @@ func (s *UpdateByQueryService) buildURL() (string, url.Values, error) { if s.allowNoIndices != nil { params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) } - if s.analyzeWildcard != nil { - params.Set("analyze_wildcard", fmt.Sprintf("%v", *s.analyzeWildcard)) - } if s.analyzer != "" { params.Set("analyzer", s.analyzer) } + if s.analyzeWildcard != nil { + params.Set("analyze_wildcard", fmt.Sprintf("%v", *s.analyzeWildcard)) + } if s.conflicts != "" { params.Set("conflicts", s.conflicts) } - if s.consistency != "" { - params.Set("consistency", s.consistency) - } if s.defaultOperator != "" { params.Set("default_operator", s.defaultOperator) } @@ -483,12 +483,15 @@ func (s *UpdateByQueryService) buildURL() (string, url.Values, error) { if s.explain != nil { params.Set("explain", fmt.Sprintf("%v", *s.explain)) } + if len(s.storedFields) > 0 { + params.Set("stored_fields", strings.Join(s.storedFields, ",")) + } + if len(s.docvalueFields) > 0 { + params.Set("docvalue_fields", strings.Join(s.docvalueFields, ",")) + } if len(s.fielddataFields) > 0 { params.Set("fielddata_fields", strings.Join(s.fielddataFields, ",")) } - if len(s.fields) > 0 { - params.Set("fields", strings.Join(s.fields, ",")) - } if s.from != nil { params.Set("from", fmt.Sprintf("%d", *s.from)) } @@ -501,14 +504,17 @@ func (s *UpdateByQueryService) buildURL() (string, url.Values, error) { if s.lowercaseExpandedTerms != nil { params.Set("lowercase_expanded_terms", fmt.Sprintf("%v", *s.lowercaseExpandedTerms)) } + if s.pipeline != "" { + params.Set("pipeline", s.pipeline) + } if s.preference != "" { params.Set("preference", s.preference) } if s.q != "" { params.Set("q", s.q) } - if s.refresh != nil { - params.Set("refresh", fmt.Sprintf("%v", *s.refresh)) + if s.refresh != "" { + params.Set("refresh", s.refresh) } if s.requestCache != nil { params.Set("request_cache", fmt.Sprintf("%v", *s.requestCache)) @@ -564,28 +570,36 @@ func (s *UpdateByQueryService) buildURL() (string, url.Values, error) { if s.versionType != nil { params.Set("version_type", fmt.Sprintf("%v", *s.versionType)) } + if s.waitForActiveShards != "" { + params.Set("wait_for_active_shards", s.waitForActiveShards) + } if s.waitForCompletion != nil { params.Set("wait_for_completion", fmt.Sprintf("%v", *s.waitForCompletion)) } + if s.requestsPerSecond != nil { + params.Set("requests_per_second", fmt.Sprintf("%v", *s.requestsPerSecond)) + } return path, params, nil } // Validate checks if the operation is valid. func (s *UpdateByQueryService) Validate() error { + var invalid []string + if len(s.index) == 0 { + invalid = append(invalid, "Index") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } return nil } -// body returns the body part of the document request. -func (s *UpdateByQueryService) body() (interface{}, error) { - if s.bodyJson != nil { - return s.bodyJson, nil +// getBody returns the body part of the document request. +func (s *UpdateByQueryService) getBody() (interface{}, error) { + if s.body != nil { + return s.body, nil } - if s.bodyString != "" { - return s.bodyString, nil - } - source := make(map[string]interface{}) - if s.script != nil { src, err := s.script.Source() if err != nil { @@ -593,7 +607,6 @@ func (s *UpdateByQueryService) body() (interface{}, error) { } source["script"] = src } - if s.query != nil { src, err := s.query.Source() if err != nil { @@ -601,12 +614,11 @@ func (s *UpdateByQueryService) body() (interface{}, error) { } source["query"] = src } - return source, nil } // Do executes the operation. -func (s *UpdateByQueryService) Do() (*UpdateByQueryResponse, error) { +func (s *UpdateByQueryService) Do(ctx context.Context) (*BulkIndexByScrollResponse, error) { // Check pre-conditions if err := s.Validate(); err != nil { return nil, err @@ -619,37 +631,21 @@ func (s *UpdateByQueryService) Do() (*UpdateByQueryResponse, error) { } // Setup HTTP request body - body, err := s.body() + body, err := s.getBody() if err != nil { return nil, err } // Get HTTP response - res, err := s.client.PerformRequest("POST", path, params, body) + res, err := s.client.PerformRequest(ctx, "POST", path, params, body) if err != nil { return nil, err } - // Return operation response - ret := new(UpdateByQueryResponse) + // Return operation response (BulkIndexByScrollResponse is defined in DeleteByQuery) + ret := new(BulkIndexByScrollResponse) if err := s.client.decoder.Decode(res.Body, ret); err != nil { return nil, err } return ret, nil } - -// UpdateByQueryResponse is the response of UpdateByQueryService.Do. -type UpdateByQueryResponse struct { - Took int64 `json:"took"` - TimedOut bool `json:"timed_out"` - Total int64 `json:"total"` - Updated int64 `json:"updated"` - Created int64 `json:"created"` - Deleted int64 `json:"deleted"` - Batches int64 `json:"batches"` - VersionConflicts int64 `json:"version_conflicts"` - Noops int64 `json:"noops"` - Retries int64 `json:"retries"` - Canceled string `json:"canceled"` - Failures []shardOperationFailure `json:"failures"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v3/uritemplates/LICENSE b/vendor/gopkg.in/olivere/elastic.v5/uritemplates/LICENSE similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v3/uritemplates/LICENSE rename to vendor/gopkg.in/olivere/elastic.v5/uritemplates/LICENSE diff --git a/vendor/gopkg.in/olivere/elastic.v3/uritemplates/uritemplates.go b/vendor/gopkg.in/olivere/elastic.v5/uritemplates/uritemplates.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v3/uritemplates/uritemplates.go rename to vendor/gopkg.in/olivere/elastic.v5/uritemplates/uritemplates.go diff --git a/vendor/gopkg.in/olivere/elastic.v3/uritemplates/utils.go b/vendor/gopkg.in/olivere/elastic.v5/uritemplates/utils.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v3/uritemplates/utils.go rename to vendor/gopkg.in/olivere/elastic.v5/uritemplates/utils.go diff --git a/vendor/vendor.json b/vendor/vendor.json index c899cc23d..0908fad83 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -340,6 +340,12 @@ "revision": "a728288923b47049b2ce791836767ffbe964a5bd", "revisionTime": "2016-07-07T15:24:52-07:00" }, + { + "checksumSHA1": "WHc3uByvGaMcnSoI21fhzYgbOgg=", + "path": "golang.org/x/net/context/ctxhttp", + "revision": "f2499483f923065a842d38eb4c7f1927e6fc6e6d", + "revisionTime": "2017-01-14T04:22:49Z" + }, { "checksumSHA1": "p36nkSZUaOs/7Wtcy/FduBLgm8g=", "path": "gopkg.in/Shopify/sarama.v1", @@ -351,12 +357,6 @@ "revision": "11d3bc7aa68e238947792f30573146a3231fc0f1", "revisionTime": "2015-07-29T10:04:31+02:00" }, - { - "checksumSHA1": "eC4OV7g1tug838fPWrwflstr/TM=", - "path": "gopkg.in/olivere/elastic.v3", - "revision": "f7ae701daf3abe5dfb99f57b3f47738ec93c9c26", - "revisionTime": "2016-07-16T10:42:39Z" - }, { "checksumSHA1": "lLdKOn9RPtFoTtPUNq5+sIInAiE=", "path": "gopkg.in/olivere/elastic.v3/backoff", @@ -369,6 +369,18 @@ "revision": "f7ae701daf3abe5dfb99f57b3f47738ec93c9c26", "revisionTime": "2016-07-16T10:42:39Z" }, + { + "checksumSHA1": "ji4KugVW5dIfKLoFr1fE+3mT90A=", + "path": "gopkg.in/olivere/elastic.v5", + "revision": "cf4e58efdcee2e8e7c18dad44d51ed166fb256c2", + "revisionTime": "2017-03-26T10:11:08Z" + }, + { + "checksumSHA1": "pCApZfp2CeDnWbNVsyzNO62ZUXA=", + "path": "gopkg.in/olivere/elastic.v5/uritemplates", + "revision": "cf4e58efdcee2e8e7c18dad44d51ed166fb256c2", + "revisionTime": "2017-03-26T10:11:08Z" + }, { "checksumSHA1": "12GqsW8PiRPnezDDy0v4brZrndM=", "path": "gopkg.in/yaml.v2",