From f7e93db512170fcb456f245d259bda082d12b01a Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 21 Nov 2019 13:04:21 +0100 Subject: [PATCH] [MM-16768] Add support for Elasticsearch v7 (#12537) * [MM-16768] Add support for Elasticsearch v7 * Fix i18n * Adds external services tracking to the telemetry * Rebuild elasticsearch interface mock * Rename diagnostics keys * Fix merge change --- app/diagnostics.go | 12 + cmd/mattermost/main.go | 2 +- einterfaces/elasticsearch.go | 1 + einterfaces/mocks/ElasticsearchInterface.go | 23 +- go.mod | 3 +- go.sum | 10 +- i18n/en.json | 8 + .../olivere/elastic}/CONTRIBUTORS | 0 .../olivere/elastic}/LICENSE | 0 .../olivere/elastic}/config/config.go | 0 .../olivere/elastic}/config/doc.go | 0 .../olivere/elastic}/uritemplates/LICENSE | 0 .../elastic}/uritemplates/uritemplates.go | 0 .../olivere/elastic}/uritemplates/utils.go | 0 .../gopkg.in/olivere/elastic.v5/.travis.yml | 27 - .../olivere/elastic.v5/delete_template.go | 109 --- .../olivere/elastic.v5/field_stats.go | 259 ------- .../olivere/elastic.v5/get_template.go | 113 --- vendor/gopkg.in/olivere/elastic.v5/go.mod | 8 - vendor/gopkg.in/olivere/elastic.v5/go.sum | 8 - .../gopkg.in/olivere/elastic.v5/nodes_info.go | 312 --------- .../olivere/elastic.v5/put_template.go | 145 ---- vendor/gopkg.in/olivere/elastic.v5/run-es.sh | 3 - .../elastic.v5/search_queries_indices.go | 89 --- .../olivere/elastic.v5/search_request.go | 217 ------ vendor/gopkg.in/olivere/elastic.v5/suggest.go | 158 ----- .../elastic.v5/suggester_completion_fuzzy.go | 181 ----- vendor/gopkg.in/olivere/elastic.v6/.fossa.yml | 38 + .../{elastic.v5 => elastic.v6}/.gitignore | 2 + .../gopkg.in/olivere/elastic.v6/.golangci.yml | 78 +++ .../gopkg.in/olivere/elastic.v6/.travis.yml | 33 + .../CHANGELOG-3.0.md | 0 .../CHANGELOG-5.0.md | 0 .../olivere/elastic.v6/CHANGELOG-6.0.md | 18 + .../CODE_OF_CONDUCT.md | 0 .../CONTRIBUTING.md | 6 +- .../gopkg.in/olivere/elastic.v6/CONTRIBUTORS | 185 +++++ .../ISSUE_TEMPLATE.md | 5 +- vendor/gopkg.in/olivere/elastic.v6/LICENSE | 20 + .../{elastic.v5 => elastic.v6}/README.md | 113 ++- .../acknowledged_response.go | 4 +- .../{elastic.v5 => elastic.v6}/backoff.go | 0 .../{elastic.v5 => elastic.v6}/bulk.go | 32 +- .../bulk_delete_request.go | 68 +- .../bulk_delete_request_easyjson.go | 144 ++-- .../bulk_index_request.go | 60 +- .../bulk_index_request_easyjson.go | 120 ++-- .../bulk_processor.go | 169 +++-- .../bulk_request.go | 0 .../bulk_update_request.go | 71 +- .../bulk_update_request_easyjson.go | 168 +++-- .../canonicalize.go | 0 .../olivere/elastic.v6/cat_aliases.go | 169 +++++ .../olivere/elastic.v6/cat_allocation.go | 188 +++++ .../gopkg.in/olivere/elastic.v6/cat_count.go | 164 +++++ .../gopkg.in/olivere/elastic.v6/cat_health.go | 160 +++++ .../olivere/elastic.v6/cat_indices.go | 318 +++++++++ .../clear_scroll.go | 11 +- .../{elastic.v5 => elastic.v6}/client.go | 651 ++++++++++++------ .../cluster_health.go | 10 +- .../olivere/elastic.v6/cluster_reroute.go | 390 +++++++++++ .../cluster_state.go | 40 +- .../cluster_stats.go | 100 +-- .../{elastic.v5 => elastic.v6}/connection.go | 0 .../{elastic.v5 => elastic.v6}/count.go | 14 +- .../{elastic.v5 => elastic.v6}/decoder.go | 12 + .../{elastic.v5 => elastic.v6}/delete.go | 42 +- .../delete_by_query.go | 105 ++- .../olivere/{elastic.v5 => elastic.v6}/doc.go | 0 .../olivere/elastic.v6/docker-compose.yml | 55 ++ .../olivere/elastic.v6/docvalue_field.go | 42 ++ .../{elastic.v5 => elastic.v6}/errors.go | 8 + .../{elastic.v5 => elastic.v6}/exists.go | 16 +- .../{elastic.v5 => elastic.v6}/explain.go | 13 +- .../fetch_source_context.go | 2 +- .../{elastic.v5 => elastic.v6}/field_caps.go | 18 +- .../{elastic.v5 => elastic.v6}/geo_point.go | 6 + .../olivere/{elastic.v5 => elastic.v6}/get.go | 37 +- .../{elastic.v5 => elastic.v6}/highlight.go | 2 +- .../{elastic.v5 => elastic.v6}/index.go | 40 +- .../indices_analyze.go | 26 +- .../indices_close.go | 14 +- .../indices_create.go | 62 +- .../indices_delete.go | 12 +- .../indices_delete_template.go | 16 +- .../indices_exists.go | 13 +- .../indices_exists_template.go | 11 +- .../indices_exists_type.go | 13 +- .../indices_flush.go | 12 +- .../elastic.v6/indices_flush_synced.go | 230 +++++++ .../indices_forcemerge.go | 19 +- .../{elastic.v5 => elastic.v6}/indices_get.go | 12 +- .../indices_get_aliases.go | 56 +- .../indices_get_field_mapping.go | 12 +- .../indices_get_mapping.go | 12 +- .../indices_get_settings.go | 12 +- .../indices_get_template.go | 24 +- .../indices_open.go | 44 +- .../indices_put_alias.go | 59 +- .../indices_put_mapping.go | 48 +- .../indices_put_settings.go | 17 +- .../indices_put_template.go | 56 +- .../indices_refresh.go | 10 +- .../indices_rollover.go | 15 +- .../indices_segments.go | 15 +- .../indices_shrink.go | 18 +- .../indices_stats.go | 39 +- .../ingest_delete_pipeline.go | 16 +- .../ingest_get_pipeline.go | 12 +- .../ingest_put_pipeline.go | 17 +- .../ingest_simulate_pipeline.go | 13 +- .../{elastic.v5 => elastic.v6}/inner_hit.go | 10 + .../{elastic.v5 => elastic.v6}/logger.go | 0 .../{elastic.v5 => elastic.v6}/mget.go | 16 +- .../{elastic.v5 => elastic.v6}/msearch.go | 39 +- .../mtermvectors.go | 13 +- .../gopkg.in/olivere/elastic.v6/nodes_info.go | 366 ++++++++++ .../{elastic.v5 => elastic.v6}/nodes_stats.go | 45 +- .../{elastic.v5 => elastic.v6}/ping.go | 2 +- .../{elastic.v5 => elastic.v6}/plugins.go | 0 .../{elastic.v5 => elastic.v6}/query.go | 0 .../{elastic.v5 => elastic.v6}/reindex.go | 251 ++++--- .../{elastic.v5 => elastic.v6}/request.go | 9 +- .../{elastic.v5 => elastic.v6}/rescore.go | 0 .../{elastic.v5 => elastic.v6}/rescorer.go | 0 .../{elastic.v5 => elastic.v6}/response.go | 21 +- .../{elastic.v5 => elastic.v6}/retrier.go | 9 +- .../{elastic.v5 => elastic.v6}/retry.go | 0 vendor/gopkg.in/olivere/elastic.v6/run-es.sh | 3 + .../{elastic.v5 => elastic.v6}/script.go | 75 +- .../olivere/elastic.v6/script_delete.go | 134 ++++ .../gopkg.in/olivere/elastic.v6/script_get.go | 117 ++++ .../gopkg.in/olivere/elastic.v6/script_put.go | 174 +++++ .../{elastic.v5 => elastic.v6}/scroll.go | 72 +- .../{elastic.v5 => elastic.v6}/search.go | 210 ++++-- .../{elastic.v5 => elastic.v6}/search_aggs.go | 248 +++++-- .../search_aggs_bucket_adjacency_matrix.go | 2 +- .../search_aggs_bucket_children.go | 2 +- .../search_aggs_bucket_composite.go | 554 +++++++++++++++ .../search_aggs_bucket_count_thresholds.go | 13 + .../search_aggs_bucket_date_histogram.go | 5 +- .../search_aggs_bucket_date_range.go | 11 +- .../search_aggs_bucket_diversified_sampler.go | 2 +- .../search_aggs_bucket_filter.go | 2 +- .../search_aggs_bucket_filters.go | 2 +- .../search_aggs_bucket_geo_distance.go | 2 +- .../search_aggs_bucket_geohash_grid.go | 10 +- .../search_aggs_bucket_global.go | 2 +- .../search_aggs_bucket_histogram.go | 2 +- .../search_aggs_bucket_ip_range.go | 2 +- .../search_aggs_bucket_missing.go | 2 +- .../search_aggs_bucket_nested.go | 2 +- .../search_aggs_bucket_range.go | 2 +- .../search_aggs_bucket_reverse_nested.go | 2 +- .../search_aggs_bucket_sampler.go | 2 +- .../search_aggs_bucket_significant_terms.go | 18 +- .../search_aggs_bucket_significant_text.go | 245 +++++++ .../search_aggs_bucket_terms.go | 20 +- .../search_aggs_matrix_stats.go | 10 +- .../search_aggs_metrics_avg.go | 13 +- .../search_aggs_metrics_cardinality.go | 11 +- .../search_aggs_metrics_extended_stats.go | 11 +- .../search_aggs_metrics_geo_bounds.go | 2 +- .../search_aggs_metrics_geo_centroid.go | 2 +- .../search_aggs_metrics_max.go | 11 +- .../search_aggs_metrics_min.go | 11 +- .../search_aggs_metrics_percentile_ranks.go | 11 +- .../search_aggs_metrics_percentiles.go | 18 +- .../search_aggs_metrics_scripted_metric.go | 112 +++ .../search_aggs_metrics_stats.go | 11 +- .../search_aggs_metrics_sum.go | 11 +- .../search_aggs_metrics_top_hits.go | 20 +- .../search_aggs_metrics_value_count.go | 2 +- .../search_aggs_metrics_weighted_avg.go | 156 +++++ .../search_aggs_pipeline_avg_bucket.go | 31 +- .../search_aggs_pipeline_bucket_script.go | 25 +- .../search_aggs_pipeline_bucket_selector.go | 25 +- .../search_aggs_pipeline_bucket_sort.go | 119 ++++ .../search_aggs_pipeline_cumulative_sum.go | 31 +- .../search_aggs_pipeline_derivative.go | 31 +- ...rch_aggs_pipeline_extended_stats_bucket.go | 107 +++ .../search_aggs_pipeline_max_bucket.go | 31 +- .../search_aggs_pipeline_min_bucket.go | 31 +- .../search_aggs_pipeline_mov_avg.go | 47 +- .../elastic.v6/search_aggs_pipeline_mov_fn.go | 132 ++++ ...search_aggs_pipeline_percentiles_bucket.go | 29 +- .../search_aggs_pipeline_serial_diff.go | 31 +- .../search_aggs_pipeline_stats_bucket.go | 31 +- .../search_aggs_pipeline_sum_bucket.go | 31 +- .../search_collapse_builder.go | 2 +- .../search_queries_bool.go | 13 +- .../search_queries_boosting.go | 2 +- .../search_queries_common_terms.go | 11 +- .../search_queries_constant_score.go | 2 +- .../search_queries_dis_max.go | 2 +- .../search_queries_exists.go | 4 +- .../search_queries_fsq.go | 2 +- .../search_queries_fsq_score_funcs.go | 47 +- .../search_queries_fuzzy.go | 2 +- .../search_queries_geo_bounding_box.go | 2 +- .../search_queries_geo_distance.go | 11 +- .../search_queries_geo_polygon.go | 2 +- .../search_queries_has_child.go | 2 +- .../search_queries_has_parent.go | 14 +- .../search_queries_ids.go | 2 +- .../search_queries_match.go | 4 +- .../search_queries_match_all.go | 2 +- .../search_queries_match_none.go | 2 +- .../search_queries_match_phrase.go | 2 +- .../search_queries_match_phrase_prefix.go | 2 +- .../search_queries_more_like_this.go | 24 +- .../search_queries_multi_match.go | 2 +- .../search_queries_nested.go | 2 +- .../search_queries_parent_id.go | 2 +- .../search_queries_percolator.go | 66 +- .../search_queries_prefix.go | 2 +- .../search_queries_query_string.go | 109 +-- .../search_queries_range.go | 2 +- .../search_queries_raw_string.go | 0 .../search_queries_regexp.go | 2 +- .../search_queries_script.go | 2 +- .../search_queries_simple_query_string.go | 106 ++- .../search_queries_slice.go | 2 +- .../search_queries_term.go | 2 +- .../search_queries_terms.go | 2 +- .../elastic.v6/search_queries_terms_set.go | 97 +++ .../search_queries_type.go | 2 +- .../search_queries_wildcard.go | 2 +- .../elastic.v6/search_queries_wrapper.go | 28 + .../olivere/elastic.v6/search_request.go | 583 ++++++++++++++++ .../search_shards.go | 53 +- .../search_source.go | 108 ++- .../search_terms_lookup.go | 2 +- .../snapshot_create.go | 31 +- .../snapshot_create_repository.go | 17 +- .../olivere/elastic.v6/snapshot_delete.go | 106 +++ .../snapshot_delete_repository.go | 16 +- .../olivere/elastic.v6/snapshot_get.go | 164 +++++ .../snapshot_get_repository.go | 12 +- .../olivere/elastic.v6/snapshot_restore.go | 244 +++++++ .../snapshot_verify_repository.go | 12 +- .../{elastic.v5 => elastic.v6}/sort.go | 193 +++++- .../suggest_field.go | 4 +- .../{elastic.v5 => elastic.v6}/suggester.go | 0 .../suggester_completion.go | 39 +- .../suggester_context.go | 4 +- .../suggester_context_category.go | 39 +- .../suggester_context_geo.go | 104 ++- .../suggester_phrase.go | 26 +- .../suggester_term.go | 6 +- .../tasks_cancel.go | 81 ++- .../tasks_get_task.go | 36 +- .../{elastic.v5 => elastic.v6}/tasks_list.go | 90 ++- .../{elastic.v5 => elastic.v6}/termvectors.go | 17 +- .../{elastic.v5 => elastic.v6}/update.go | 51 +- .../update_by_query.go | 40 +- .../{elastic.v5 => elastic.v6}/validate.go | 11 +- .../elastic.v6/xpack_ilm_delete_lifecycle.go | 142 ++++ .../elastic.v6/xpack_ilm_get_lifecycle.go | 142 ++++ .../elastic.v6/xpack_ilm_put_lifecycle.go | 162 +++++ .../gopkg.in/olivere/elastic.v6/xpack_info.go | 175 +++++ .../elastic.v6/xpack_security_delete_role.go | 107 +++ .../xpack_security_delete_role_mapping.go | 107 +++ .../elastic.v6/xpack_security_get_role.go | 134 ++++ .../xpack_security_get_role_mapping.go | 113 +++ .../elastic.v6/xpack_security_put_role.go | 122 ++++ .../xpack_security_put_role_mapping.go | 122 ++++ .../elastic.v6/xpack_watcher_ack_watch.go | 147 ++++ .../xpack_watcher_activate_watch.go | 117 ++++ .../xpack_watcher_deactivate_watch.go | 119 ++++ .../elastic.v6/xpack_watcher_delete_watch.go | 119 ++++ .../elastic.v6/xpack_watcher_execute_watch.go | 162 +++++ .../elastic.v6/xpack_watcher_get_watch.go | 162 +++++ .../elastic.v6/xpack_watcher_put_watch.go | 160 +++++ .../elastic.v6/xpack_watcher_restart.go | 85 +++ .../olivere/elastic.v6/xpack_watcher_start.go | 85 +++ .../olivere/elastic.v6/xpack_watcher_stats.go | 113 +++ .../olivere/elastic.v6/xpack_watcher_stop.go | 85 +++ vendor/modules.txt | 25 +- 279 files changed, 12110 insertions(+), 3702 deletions(-) rename vendor/{gopkg.in/olivere/elastic.v5 => github.com/olivere/elastic}/CONTRIBUTORS (100%) rename vendor/{gopkg.in/olivere/elastic.v5 => github.com/olivere/elastic}/LICENSE (100%) rename vendor/{gopkg.in/olivere/elastic.v5 => github.com/olivere/elastic}/config/config.go (100%) rename vendor/{gopkg.in/olivere/elastic.v5 => github.com/olivere/elastic}/config/doc.go (100%) rename vendor/{gopkg.in/olivere/elastic.v5 => github.com/olivere/elastic}/uritemplates/LICENSE (100%) rename vendor/{gopkg.in/olivere/elastic.v5 => github.com/olivere/elastic}/uritemplates/uritemplates.go (100%) rename vendor/{gopkg.in/olivere/elastic.v5 => github.com/olivere/elastic}/uritemplates/utils.go (100%) delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/.travis.yml delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/delete_template.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/field_stats.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/get_template.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/go.mod delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/go.sum delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/nodes_info.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/put_template.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/run-es.sh delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/search_queries_indices.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/search_request.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/suggest.go delete mode 100644 vendor/gopkg.in/olivere/elastic.v5/suggester_completion_fuzzy.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/.fossa.yml rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/.gitignore (96%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/.golangci.yml create mode 100644 vendor/gopkg.in/olivere/elastic.v6/.travis.yml rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/CHANGELOG-3.0.md (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/CHANGELOG-5.0.md (100%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/CHANGELOG-6.0.md rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/CODE_OF_CONDUCT.md (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/CONTRIBUTING.md (88%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/CONTRIBUTORS rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/ISSUE_TEMPLATE.md (91%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/LICENSE rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/README.md (68%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/acknowledged_response.go (69%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/backoff.go (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/bulk.go (90%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/bulk_delete_request.go (68%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/bulk_delete_request_easyjson.go (71%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/bulk_index_request.go (77%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/bulk_index_request_easyjson.go (72%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/bulk_processor.go (78%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/bulk_request.go (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/bulk_update_request.go (77%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/bulk_update_request_easyjson.go (81%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/canonicalize.go (100%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/cat_aliases.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/cat_allocation.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/cat_count.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/cat_health.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/cat_indices.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/clear_scroll.go (89%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/client.go (84%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/cluster_health.go (97%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/cluster_reroute.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/cluster_state.go (87%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/cluster_stats.go (72%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/connection.go (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/count.go (96%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/decoder.go (68%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/delete.go (82%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/delete_by_query.go (87%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/doc.go (100%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/docker-compose.yml create mode 100644 vendor/gopkg.in/olivere/elastic.v6/docvalue_field.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/errors.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/exists.go (90%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/explain.go (96%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/fetch_source_context.go (96%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/field_caps.go (90%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/geo_point.go (89%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/get.go (82%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/highlight.go (99%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/index.go (86%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_analyze.go (90%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_close.go (90%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_create.go (66%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_delete.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_delete_template.go (86%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_exists.go (92%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_exists_template.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_exists_type.go (92%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_flush.go (94%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/indices_flush_synced.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_forcemerge.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_get.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_get_aliases.go (66%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_get_field_mapping.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_get_mapping.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_get_settings.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_get_template.go (81%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_open.go (76%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_put_alias.go (80%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_put_mapping.go (81%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_put_settings.go (92%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_put_template.go (80%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_refresh.go (88%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_rollover.go (96%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_segments.go (93%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_shrink.go (90%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/indices_stats.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/ingest_delete_pipeline.go (88%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/ingest_get_pipeline.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/ingest_put_pipeline.go (89%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/ingest_simulate_pipeline.go (93%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/inner_hit.go (92%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/logger.go (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/mget.go (92%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/msearch.go (66%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/mtermvectors.go (97%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/nodes_info.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/nodes_stats.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/ping.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/plugins.go (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/query.go (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/reindex.go (77%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/request.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/rescore.go (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/rescorer.go (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/response.go (62%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/retrier.go (82%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/retry.go (100%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/run-es.sh rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/script.go (61%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/script_delete.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/script_get.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/script_put.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/scroll.go (87%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search.go (68%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs.go (84%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_adjacency_matrix.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_children.go (97%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_composite.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_count_thresholds.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_date_histogram.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_date_range.go (96%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_diversified_sampler.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_filter.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_filters.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_geo_distance.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_geohash_grid.go (80%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_global.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_histogram.go (99%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_ip_range.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_missing.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_nested.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_range.go (99%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_reverse_nested.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_sampler.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_significant_terms.go (92%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_significant_text.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_bucket_terms.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_matrix_stats.go (86%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_avg.go (90%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_cardinality.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_extended_stats.go (90%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_geo_bounds.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_geo_centroid.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_max.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_min.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_percentile_ranks.go (92%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_percentiles.go (87%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_scripted_metric.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_stats.go (90%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_sum.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_top_hits.go (86%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_metrics_value_count.go (97%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_weighted_avg.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_avg_bucket.go (75%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_bucket_script.go (82%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_bucket_selector.go (82%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_bucket_sort.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_cumulative_sum.go (70%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_derivative.go (78%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_extended_stats_bucket.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_max_bucket.go (76%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_min_bucket.go (76%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_mov_avg.go (88%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_mov_fn.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_percentiles_bucket.go (77%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_serial_diff.go (77%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_stats_bucket.go (76%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_aggs_pipeline_sum_bucket.go (75%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_collapse_builder.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_bool.go (93%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_boosting.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_common_terms.go (92%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_constant_score.go (95%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_dis_max.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_exists.go (89%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_fsq.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_fsq_score_funcs.go (87%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_fuzzy.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_geo_bounding_box.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_geo_distance.go (89%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_geo_polygon.go (96%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_has_child.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_has_parent.go (93%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_ids.go (96%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_match.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_match_all.go (95%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_match_none.go (93%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_match_phrase.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_match_phrase_prefix.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_more_like_this.go (95%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_multi_match.go (99%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_nested.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_parent_id.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_percolator.go (64%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_prefix.go (96%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_query_string.go (77%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_range.go (98%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_raw_string.go (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_regexp.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_script.go (95%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_simple_query_string.go (64%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_slice.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_term.go (95%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_terms.go (96%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_queries_terms_set.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_type.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_queries_wildcard.go (96%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_queries_wrapper.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/search_request.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_shards.go (74%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_source.go (86%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/search_terms_lookup.go (95%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/snapshot_create.go (79%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/snapshot_create_repository.go (91%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/snapshot_delete.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/snapshot_delete_repository.go (87%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/snapshot_get.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/snapshot_get_repository.go (92%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/snapshot_restore.go rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/snapshot_verify_repository.go (91%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/sort.go (71%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/suggest_field.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/suggester.go (100%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/suggester_completion.go (88%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/suggester_context.go (96%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/suggester_context_category.go (74%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/suggester_context_geo.go (56%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/suggester_phrase.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/suggester_term.go (97%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/tasks_cancel.go (54%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/tasks_get_task.go (70%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/tasks_list.go (69%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/termvectors.go (96%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/update.go (83%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/update_by_query.go (94%) rename vendor/gopkg.in/olivere/{elastic.v5 => elastic.v6}/validate.go (96%) create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_delete_lifecycle.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_get_lifecycle.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_put_lifecycle.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_info.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_security_delete_role.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_security_delete_role_mapping.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_security_get_role.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_security_get_role_mapping.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_security_put_role.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_security_put_role_mapping.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_ack_watch.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_activate_watch.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_deactivate_watch.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_delete_watch.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_execute_watch.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_get_watch.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_put_watch.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_restart.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_start.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_stats.go create mode 100644 vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_stop.go diff --git a/app/diagnostics.go b/app/diagnostics.go index 08d9c150e3..0f5c8c374c 100644 --- a/app/diagnostics.go +++ b/app/diagnostics.go @@ -52,6 +52,7 @@ const ( TRACK_PERMISSIONS_GENERAL = "permissions_general" TRACK_PERMISSIONS_SYSTEM_SCHEME = "permissions_system_scheme" TRACK_PERMISSIONS_TEAM_SCHEMES = "permissions_team_schemes" + TRACK_ELASTICSEARCH = "elasticsearch" TRACK_ACTIVITY = "activity" TRACK_LICENSE = "license" @@ -72,6 +73,7 @@ func (a *App) sendDailyDiagnostics(override bool) { a.trackPlugins() a.trackServer() a.trackPermissions() + a.trackElasticsearch() } } @@ -861,3 +863,13 @@ func (a *App) trackPermissions() { } } } + +func (a *App) trackElasticsearch() { + data := map[string]interface{}{} + + if a.Elasticsearch != nil && a.Elasticsearch.GetVersion() != 0 { + data["elasticsearch_server_version"] = a.Elasticsearch.GetVersion() + } + + a.SendDiagnostic(TRACK_ELASTICSEARCH, data) +} diff --git a/cmd/mattermost/main.go b/cmd/mattermost/main.go index c51c36502d..1f326c93c4 100644 --- a/cmd/mattermost/main.go +++ b/cmd/mattermost/main.go @@ -23,7 +23,7 @@ import ( _ "github.com/prometheus/client_golang/prometheus" _ "github.com/prometheus/client_golang/prometheus/promhttp" _ "github.com/tylerb/graceful" - _ "gopkg.in/olivere/elastic.v5" + _ "gopkg.in/olivere/elastic.v6" ) func main() { diff --git a/einterfaces/elasticsearch.go b/einterfaces/elasticsearch.go index 1e244f273e..772cf50c56 100644 --- a/einterfaces/elasticsearch.go +++ b/einterfaces/elasticsearch.go @@ -12,6 +12,7 @@ import ( type ElasticsearchInterface interface { Start() *model.AppError Stop() *model.AppError + GetVersion() int IndexPost(post *model.Post, teamId string) *model.AppError SearchPosts(channels *model.ChannelList, searchParams []*model.SearchParams, page, perPage int) ([]string, model.PostSearchMatches, *model.AppError) DeletePost(post *model.Post) *model.AppError diff --git a/einterfaces/mocks/ElasticsearchInterface.go b/einterfaces/mocks/ElasticsearchInterface.go index 75a8afd5be..c6a535ce78 100644 --- a/einterfaces/mocks/ElasticsearchInterface.go +++ b/einterfaces/mocks/ElasticsearchInterface.go @@ -4,9 +4,12 @@ package mocks -import mock "github.com/stretchr/testify/mock" -import model "github.com/mattermost/mattermost-server/model" -import time "time" +import ( + time "time" + + model "github.com/mattermost/mattermost-server/model" + mock "github.com/stretchr/testify/mock" +) // ElasticsearchInterface is an autogenerated mock type for the ElasticsearchInterface type type ElasticsearchInterface struct { @@ -77,6 +80,20 @@ func (_m *ElasticsearchInterface) DeleteUser(user *model.User) *model.AppError { return r0 } +// GetVersion provides a mock function with given fields: +func (_m *ElasticsearchInterface) GetVersion() int { + ret := _m.Called() + + var r0 int + if rf, ok := ret.Get(0).(func() int); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int) + } + + return r0 +} + // IndexChannel provides a mock function with given fields: channel func (_m *ElasticsearchInterface) IndexChannel(channel *model.Channel) *model.AppError { ret := _m.Called(channel) diff --git a/go.mod b/go.mod index 98d401226b..6bd5636d1e 100644 --- a/go.mod +++ b/go.mod @@ -54,6 +54,7 @@ require ( github.com/mitchellh/go-testing-interface v1.0.0 // indirect github.com/muesli/smartcrop v0.3.0 // indirect github.com/olekukonko/tablewriter v0.0.1 // indirect + github.com/olivere/elastic v6.2.23+incompatible // indirect github.com/onsi/ginkgo v1.8.0 // indirect github.com/onsi/gomega v1.5.0 // indirect github.com/pborman/uuid v1.2.0 @@ -98,7 +99,7 @@ require ( gopkg.in/ini.v1 v1.48.0 // indirect gopkg.in/mail.v2 v2.3.1 gopkg.in/natefinch/lumberjack.v2 v2.0.0 - gopkg.in/olivere/elastic.v5 v5.0.82 + gopkg.in/olivere/elastic.v6 v6.2.23 gopkg.in/yaml.v2 v2.2.3 willnorris.com/go/imageproxy v0.9.0 ) diff --git a/go.sum b/go.sum index ec930343d0..0aa8832016 100644 --- a/go.sum +++ b/go.sum @@ -79,8 +79,6 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/fortytw2/leaktest v1.2.0 h1:cj6GCiwJDH7l3tMHLjZDo0QqPtrXJiWSI9JgpeQKw+Q= -github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= @@ -237,7 +235,6 @@ github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDe github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM= github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho= @@ -292,6 +289,8 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/olivere/elastic v6.2.23+incompatible h1:oRGUA/8fKcnkDcqLuwGb5YCzgbgEBo+Y9gamsWqZ0qU= +github.com/olivere/elastic v6.2.23+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= @@ -378,7 +377,6 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.0.0 h1:UVQPSSmc3qtTi+zPPkCXvZX9VvW/xT/NsRvKfwY81a8= github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= -github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 h1:N8Bg45zpk/UcpNGnfJt2y/3lRWASHNTUET8owPYCgYI= github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= @@ -587,8 +585,8 @@ gopkg.in/mail.v2 v2.3.1 h1:WYFn/oANrAGP2C0dcV6/pbkPzv8yGzqTjPmTeO7qoXk= gopkg.in/mail.v2 v2.3.1/go.mod h1:htwXN1Qh09vZJ1NVKxQqHPBaCBbzKhp5GzuJEA4VJWw= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= -gopkg.in/olivere/elastic.v5 v5.0.82 h1:QH7ere4lvOAWnnOd0VLJ54W8LzExZszoGIRijnb1h2Y= -gopkg.in/olivere/elastic.v5 v5.0.82/go.mod h1:uhHoB4o3bvX5sorxBU29rPcmBQdV2Qfg0FBrx5D6pV0= +gopkg.in/olivere/elastic.v6 v6.2.23 h1:wDrXwXXecu8t/mTPbvMu8zONtTJA201IKq1RxSeEU38= +gopkg.in/olivere/elastic.v6 v6.2.23/go.mod h1:2cTT8Z+/LcArSWpCgvZqBgt3VOqXiy7v00w12Lz8bd4= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= diff --git a/i18n/en.json b/i18n/en.json index 1089b4ce3b..3edbf60ced 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3922,6 +3922,14 @@ "id": "ent.elasticsearch.start.create_bulk_processor_failed.app_error", "translation": "Failed to create Elasticsearch bulk processor" }, + { + "id": "ent.elasticsearch.start.get_server_version.app_error", + "translation": "Failed to get Elasticsearch server version" + }, + { + "id": "ent.elasticsearch.start.parse_server_version.app_error", + "translation": "Failed to parse Elasticsearch server version" + }, { "id": "ent.elasticsearch.start.start_bulk_processor_failed.app_error", "translation": "Failed to start Elasticsearch bulk processor" diff --git a/vendor/gopkg.in/olivere/elastic.v5/CONTRIBUTORS b/vendor/github.com/olivere/elastic/CONTRIBUTORS similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/CONTRIBUTORS rename to vendor/github.com/olivere/elastic/CONTRIBUTORS diff --git a/vendor/gopkg.in/olivere/elastic.v5/LICENSE b/vendor/github.com/olivere/elastic/LICENSE similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/LICENSE rename to vendor/github.com/olivere/elastic/LICENSE diff --git a/vendor/gopkg.in/olivere/elastic.v5/config/config.go b/vendor/github.com/olivere/elastic/config/config.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/config/config.go rename to vendor/github.com/olivere/elastic/config/config.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/config/doc.go b/vendor/github.com/olivere/elastic/config/doc.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/config/doc.go rename to vendor/github.com/olivere/elastic/config/doc.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/uritemplates/LICENSE b/vendor/github.com/olivere/elastic/uritemplates/LICENSE similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/uritemplates/LICENSE rename to vendor/github.com/olivere/elastic/uritemplates/LICENSE diff --git a/vendor/gopkg.in/olivere/elastic.v5/uritemplates/uritemplates.go b/vendor/github.com/olivere/elastic/uritemplates/uritemplates.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/uritemplates/uritemplates.go rename to vendor/github.com/olivere/elastic/uritemplates/uritemplates.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/uritemplates/utils.go b/vendor/github.com/olivere/elastic/uritemplates/utils.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/uritemplates/utils.go rename to vendor/github.com/olivere/elastic/uritemplates/utils.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/.travis.yml b/vendor/gopkg.in/olivere/elastic.v5/.travis.yml deleted file mode 100644 index 13ab77811f..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -sudo: required -language: go -go: -- "1.10.x" -- "1.11.x" -- "1.12.x" -#- tip -env: -- GO111MODULE=on -- GO111MODULE=off -matrix: - allow_failures: - - go: tip -services: -- docker -before_install: -# Install netcat -- if [[ "$TRAVIS_OS_NAME" == "linux" && ! $(which nc) ]] ; then sudo apt-get install -y netcat ; fi -- sudo sysctl -w vm.max_map_count=262144 -- docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch:5.6.16 elasticsearch -Expack.security.enabled=false -Escript.inline=true -Escript.stored=true -Escript.file=true -Enetwork.host=_local_,_site_ -Enetwork.publish_host=_local_ >& /dev/null & -- go get -u github.com/fortytw2/leaktest -- go get . ./aws/... ./config/... ./uritemplates/... -# Wait for Elasticsearch -- while ! nc -z localhost 9200; do sleep 1; done -install: true -script: -- go test -race -v . ./aws/... ./config/... ./uritemplates/... diff --git a/vendor/gopkg.in/olivere/elastic.v5/delete_template.go b/vendor/gopkg.in/olivere/elastic.v5/delete_template.go deleted file mode 100644 index 4775baf84b..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/delete_template.go +++ /dev/null @@ -1,109 +0,0 @@ -// 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 ( - "context" - "fmt" - "net/url" - - "gopkg.in/olivere/elastic.v5/uritemplates" -) - -// DeleteTemplateService deletes a search template. More information can -// be found at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html. -type DeleteTemplateService struct { - client *Client - pretty bool - id string - version *int - versionType string -} - -// NewDeleteTemplateService creates a new DeleteTemplateService. -func NewDeleteTemplateService(client *Client) *DeleteTemplateService { - return &DeleteTemplateService{ - client: client, - } -} - -// Id is the template ID. -func (s *DeleteTemplateService) Id(id string) *DeleteTemplateService { - s.id = id - return s -} - -// Version an explicit version number for concurrency control. -func (s *DeleteTemplateService) Version(version int) *DeleteTemplateService { - s.version = &version - return s -} - -// VersionType specifies a version type. -func (s *DeleteTemplateService) VersionType(versionType string) *DeleteTemplateService { - s.versionType = versionType - return s -} - -// buildURL builds the URL for the operation. -func (s *DeleteTemplateService) buildURL() (string, url.Values, error) { - // Build URL - path, err := uritemplates.Expand("/_search/template/{id}", map[string]string{ - "id": s.id, - }) - if err != nil { - return "", url.Values{}, err - } - - // Add query string parameters - params := url.Values{} - if s.version != nil { - params.Set("version", fmt.Sprintf("%d", *s.version)) - } - if s.versionType != "" { - params.Set("version_type", s.versionType) - } - - return path, params, nil -} - -// Validate checks if the operation is valid. -func (s *DeleteTemplateService) 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 *DeleteTemplateService) Do(ctx context.Context) (*AcknowledgedResponse, 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(AcknowledgedResponse) - 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.v5/field_stats.go b/vendor/gopkg.in/olivere/elastic.v5/field_stats.go deleted file mode 100644 index c2104c5cb3..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/field_stats.go +++ /dev/null @@ -1,259 +0,0 @@ -// 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 ( - "context" - "fmt" - "net/http" - "net/url" - "strings" - - "gopkg.in/olivere/elastic.v5/uritemplates" -) - -const ( - FieldStatsClusterLevel = "cluster" - FieldStatsIndicesLevel = "indices" -) - -// 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/5.2/search-field-stats.html -// for details -type FieldStatsService struct { - client *Client - pretty bool - level string - index []string - allowNoIndices *bool - expandWildcards string - fields []string - ignoreUnavailable *bool - bodyJson interface{} - bodyString string -} - -// NewFieldStatsService creates a new FieldStatsService -func NewFieldStatsService(client *Client) *FieldStatsService { - return &FieldStatsService{ - client: client, - index: make([]string, 0), - fields: make([]string, 0), - } -} - -// Index is a list of index names; use `_all` or empty string to perform -// the operation on all indices. -func (s *FieldStatsService) Index(index ...string) *FieldStatsService { - s.index = append(s.index, index...) - 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 *FieldStatsService) AllowNoIndices(allowNoIndices bool) *FieldStatsService { - s.allowNoIndices = &allowNoIndices - return s -} - -// ExpandWildcards indicates whether to expand wildcard expression to -// concrete indices that are open, closed or both. -func (s *FieldStatsService) ExpandWildcards(expandWildcards string) *FieldStatsService { - s.expandWildcards = expandWildcards - return s -} - -// Fields is a list of fields for to get field statistics -// for (min value, max value, and more). -func (s *FieldStatsService) Fields(fields ...string) *FieldStatsService { - s.fields = append(s.fields, fields...) - return s -} - -// IgnoreUnavailable is documented as: Whether specified concrete indices should be ignored when unavailable (missing or closed). -func (s *FieldStatsService) IgnoreUnavailable(ignoreUnavailable bool) *FieldStatsService { - s.ignoreUnavailable = &ignoreUnavailable - return s -} - -// Level sets if stats should be returned on a per index level or on a cluster wide level; -// should be one of 'cluster' or 'indices'; defaults to former -func (s *FieldStatsService) Level(level string) *FieldStatsService { - s.level = level - return s -} - -// ClusterLevel is a helper that sets Level to "cluster". -func (s *FieldStatsService) ClusterLevel() *FieldStatsService { - s.level = FieldStatsClusterLevel - return s -} - -// IndicesLevel is a helper that sets Level to "indices". -func (s *FieldStatsService) IndicesLevel() *FieldStatsService { - s.level = FieldStatsIndicesLevel - return s -} - -// Pretty indicates that the JSON response be indented and human readable. -func (s *FieldStatsService) Pretty(pretty bool) *FieldStatsService { - s.pretty = pretty - return s -} - -// BodyJson is documented as: Field json objects containing the name and optionally a range to filter out indices result, that have results outside the defined bounds. -func (s *FieldStatsService) BodyJson(body interface{}) *FieldStatsService { - s.bodyJson = body - return s -} - -// BodyString is documented as: Field json objects containing the name and optionally a range to filter out indices result, that have results outside the defined bounds. -func (s *FieldStatsService) BodyString(body string) *FieldStatsService { - s.bodyString = body - return s -} - -// buildURL builds the URL for the operation. -func (s *FieldStatsService) buildURL() (string, url.Values, error) { - // Build URL - var err error - var path string - if len(s.index) > 0 { - path, err = uritemplates.Expand("/{index}/_field_stats", map[string]string{ - "index": strings.Join(s.index, ","), - }) - } else { - path = "/_field_stats" - } - if err != nil { - return "", url.Values{}, err - } - - // Add query string parameters - params := url.Values{} - if s.allowNoIndices != nil { - params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) - } - if s.expandWildcards != "" { - params.Set("expand_wildcards", s.expandWildcards) - } - if len(s.fields) > 0 { - params.Set("fields", strings.Join(s.fields, ",")) - } - if s.ignoreUnavailable != nil { - params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) - } - if s.level != "" { - params.Set("level", s.level) - } - return path, params, nil -} - -// Validate checks if the operation is valid. -func (s *FieldStatsService) Validate() error { - var invalid []string - if s.level != "" && (s.level != FieldStatsIndicesLevel && s.level != FieldStatsClusterLevel) { - invalid = append(invalid, "Level") - } - if len(invalid) != 0 { - return fmt.Errorf("missing or invalid required fields: %v", invalid) - } - return nil -} - -// Do executes the operation. -func (s *FieldStatsService) Do(ctx context.Context) (*FieldStatsResponse, 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, http.StatusNotFound) - if err != nil { - return nil, err - } - - // TODO(oe): Is 404 really a valid response here? - if res.StatusCode == http.StatusNotFound { - return &FieldStatsResponse{make(map[string]IndexFieldStats)}, nil - } - - // Return operation response - ret := new(FieldStatsResponse) - if err := s.client.decoder.Decode(res.Body, ret); err != nil { - return nil, err - } - return ret, nil -} - -// -- Request -- - -// FieldStatsRequest can be used to set up the body to be used in the -// Field Stats API. -type FieldStatsRequest struct { - Fields []string `json:"fields"` - IndexConstraints map[string]*FieldStatsConstraints `json:"index_constraints,omitempty"` -} - -// FieldStatsConstraints is a constraint on a field. -type FieldStatsConstraints struct { - Min *FieldStatsComparison `json:"min_value,omitempty"` - Max *FieldStatsComparison `json:"max_value,omitempty"` -} - -// FieldStatsComparison contain all comparison operations that can be used -// in FieldStatsConstraints. -type FieldStatsComparison struct { - Lte interface{} `json:"lte,omitempty"` - Lt interface{} `json:"lt,omitempty"` - Gte interface{} `json:"gte,omitempty"` - Gt interface{} `json:"gt,omitempty"` -} - -// -- Response -- - -// FieldStatsResponse is the response body content -type FieldStatsResponse struct { - Indices map[string]IndexFieldStats `json:"indices,omitempty"` -} - -// IndexFieldStats contains field stats for an index -type IndexFieldStats struct { - Fields map[string]FieldStats `json:"fields,omitempty"` -} - -// 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"` - MaxValueAsString string `json:"max_value_as_string"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v5/get_template.go b/vendor/gopkg.in/olivere/elastic.v5/get_template.go deleted file mode 100644 index 93279a3a73..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/get_template.go +++ /dev/null @@ -1,113 +0,0 @@ -// 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 ( - "context" - "fmt" - "net/url" - - "gopkg.in/olivere/elastic.v5/uritemplates" -) - -// GetTemplateService reads a search template. -// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html. -type GetTemplateService struct { - client *Client - pretty bool - id string - version interface{} - versionType string -} - -// NewGetTemplateService creates a new GetTemplateService. -func NewGetTemplateService(client *Client) *GetTemplateService { - return &GetTemplateService{ - client: client, - } -} - -// Id is the template ID. -func (s *GetTemplateService) Id(id string) *GetTemplateService { - s.id = id - return s -} - -// Version is an explicit version number for concurrency control. -func (s *GetTemplateService) Version(version interface{}) *GetTemplateService { - s.version = version - return s -} - -// VersionType is a specific version type. -func (s *GetTemplateService) VersionType(versionType string) *GetTemplateService { - s.versionType = versionType - return s -} - -// buildURL builds the URL for the operation. -func (s *GetTemplateService) buildURL() (string, url.Values, error) { - // Build URL - path, err := uritemplates.Expand("/_search/template/{id}", map[string]string{ - "id": s.id, - }) - if err != nil { - return "", url.Values{}, err - } - - // Add query string parameters - params := url.Values{} - if s.version != nil { - params.Set("version", fmt.Sprintf("%v", s.version)) - } - if s.versionType != "" { - params.Set("version_type", s.versionType) - } - - return path, params, nil -} - -// Validate checks if the operation is valid. -func (s *GetTemplateService) 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 and returns the template. -func (s *GetTemplateService) Do(ctx context.Context) (*GetTemplateResponse, 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 result - ret := new(GetTemplateResponse) - if err := s.client.decoder.Decode(res.Body, ret); err != nil { - return nil, err - } - return ret, nil -} - -type GetTemplateResponse struct { - Template string `json:"template"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v5/go.mod b/vendor/gopkg.in/olivere/elastic.v5/go.mod deleted file mode 100644 index a29017697c..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module gopkg.in/olivere/elastic.v5 - -require ( - github.com/fortytw2/leaktest v1.2.0 - github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5 - github.com/pkg/errors v0.8.0 - github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 -) diff --git a/vendor/gopkg.in/olivere/elastic.v5/go.sum b/vendor/gopkg.in/olivere/elastic.v5/go.sum deleted file mode 100644 index 87d299f80e..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/go.sum +++ /dev/null @@ -1,8 +0,0 @@ -github.com/fortytw2/leaktest v1.2.0 h1:cj6GCiwJDH7l3tMHLjZDo0QqPtrXJiWSI9JgpeQKw+Q= -github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= -github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5 h1:0x4qcEHDpruK6ML/m/YSlFUUu0UpRD3I2PHsNCuGnyA= -github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 h1:hp2CYQUINdZMHdvTdXtPOY2ainKl4IoMcpAXEf2xj3Q= -github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= diff --git a/vendor/gopkg.in/olivere/elastic.v5/nodes_info.go b/vendor/gopkg.in/olivere/elastic.v5/nodes_info.go deleted file mode 100644 index d03fdf9c3c..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/nodes_info.go +++ /dev/null @@ -1,312 +0,0 @@ -// 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 ( - "context" - "fmt" - "net/url" - "strings" - "time" - - "gopkg.in/olivere/elastic.v5/uritemplates" -) - -// NodesInfoService allows to retrieve one or more or all of the -// cluster nodes information. -// 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 - nodeId []string - metric []string - flatSettings *bool - human *bool -} - -// NewNodesInfoService creates a new NodesInfoService. -func NewNodesInfoService(client *Client) *NodesInfoService { - return &NodesInfoService{ - client: client, - nodeId: []string{"_all"}, - metric: []string{"_all"}, - } -} - -// 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 *NodesInfoService) NodeId(nodeId ...string) *NodesInfoService { - s.nodeId = append(s.nodeId, nodeId...) - return s -} - -// Metric is a list of metrics you wish returned. Leave empty to return all. -// Valid metrics are: settings, os, process, jvm, thread_pool, network, -// transport, http, and plugins. -func (s *NodesInfoService) Metric(metric ...string) *NodesInfoService { - s.metric = append(s.metric, metric...) - return s -} - -// FlatSettings returns settings in flat format (default: false). -func (s *NodesInfoService) FlatSettings(flatSettings bool) *NodesInfoService { - s.flatSettings = &flatSettings - return s -} - -// Human indicates whether to return time and byte values in human-readable format. -func (s *NodesInfoService) Human(human bool) *NodesInfoService { - s.human = &human - return s -} - -// Pretty indicates whether to indent the returned JSON. -func (s *NodesInfoService) Pretty(pretty bool) *NodesInfoService { - s.pretty = pretty - return s -} - -// buildURL builds the URL for the operation. -func (s *NodesInfoService) buildURL() (string, url.Values, error) { - // Build URL - path, err := uritemplates.Expand("/_nodes/{node_id}/{metric}", map[string]string{ - "node_id": strings.Join(s.nodeId, ","), - "metric": strings.Join(s.metric, ","), - }) - if err != nil { - return "", url.Values{}, err - } - - // Add query string parameters - params := url.Values{} - if s.flatSettings != nil { - params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings)) - } - if s.human != nil { - params.Set("human", fmt.Sprintf("%v", *s.human)) - } - if s.pretty { - params.Set("pretty", "1") - } - return path, params, nil -} - -// Validate checks if the operation is valid. -func (s *NodesInfoService) Validate() error { - return nil -} - -// Do executes the operation. -func (s *NodesInfoService) Do(ctx context.Context) (*NodesInfoResponse, 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(NodesInfoResponse) - if err := s.client.decoder.Decode(res.Body, ret); err != nil { - return nil, err - } - return ret, nil -} - -// NodesInfoResponse is the response of NodesInfoService.Do. -type NodesInfoResponse struct { - ClusterName string `json:"cluster_name"` - Nodes map[string]*NodesInfoNode `json:"nodes"` -} - -type NodesInfoNode struct { - // 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 the IP address, e.g. "192.168.1.2" - IP string `json:"ip"` - // Version is the Elasticsearch version running on the node, e.g. "1.4.3" - Version string `json:"version"` - // Build is the Elasticsearch build, e.g. "36a29a7" - Build string `json:"build"` - // HTTPAddress, e.g. "127.0.0.1:9200" - HTTPAddress string `json:"http_address"` - // HTTPSAddress, e.g. "127.0.0.1:9200" - HTTPSAddress string `json:"https_address"` - - // Roles of the node, e.g. [master, ingest, data] - Roles []string `json:"roles"` - - // Attributes of the node. - Attributes map[string]interface{} `json:"attributes"` - - // Settings of the node, e.g. paths and pidfile. - Settings map[string]interface{} `json:"settings"` - - // OS information, e.g. CPU and memory. - OS *NodesInfoNodeOS `json:"os"` - - // Process information, e.g. max file descriptors. - Process *NodesInfoNodeProcess `json:"process"` - - // JVM information, e.g. VM version. - JVM *NodesInfoNodeJVM `json:"jvm"` - - // ThreadPool information. - ThreadPool *NodesInfoNodeThreadPool `json:"thread_pool"` - - // Network information. - Network *NodesInfoNodeNetwork `json:"network"` - - // Network information. - Transport *NodesInfoNodeTransport `json:"transport"` - - // HTTP information. - HTTP *NodesInfoNodeHTTP `json:"http"` - - // Plugins information. - Plugins []*NodesInfoNodePlugin `json:"plugins"` -} - -type NodesInfoNodeOS struct { - RefreshInterval string `json:"refresh_interval"` // e.g. 1s - RefreshIntervalInMillis int `json:"refresh_interval_in_millis"` // e.g. 1000 - AvailableProcessors int `json:"available_processors"` // e.g. 4 - - // CPU information - CPU struct { - Vendor string `json:"vendor"` // e.g. Intel - Model string `json:"model"` // e.g. iMac15,1 - MHz int `json:"mhz"` // e.g. 3500 - TotalCores int `json:"total_cores"` // e.g. 4 - TotalSockets int `json:"total_sockets"` // e.g. 4 - CoresPerSocket int `json:"cores_per_socket"` // e.g. 16 - CacheSizeInBytes int `json:"cache_size_in_bytes"` // e.g. 256 - } `json:"cpu"` - - // Mem information - Mem struct { - Total string `json:"total"` // e.g. 16gb - TotalInBytes int `json:"total_in_bytes"` // e.g. 17179869184 - } `json:"mem"` - - // Swap information - Swap struct { - Total string `json:"total"` // e.g. 1gb - TotalInBytes int `json:"total_in_bytes"` // e.g. 1073741824 - } `json:"swap"` -} - -type NodesInfoNodeProcess struct { - RefreshInterval string `json:"refresh_interval"` // e.g. 1s - RefreshIntervalInMillis int `json:"refresh_interval_in_millis"` // e.g. 1000 - ID int `json:"id"` // process id, e.g. 87079 - MaxFileDescriptors int `json:"max_file_descriptors"` // e.g. 32768 - Mlockall bool `json:"mlockall"` // e.g. false -} - -type NodesInfoNodeJVM struct { - PID int `json:"pid"` // process id, e.g. 87079 - Version string `json:"version"` // e.g. "1.8.0_25" - VMName string `json:"vm_name"` // e.g. "Java HotSpot(TM) 64-Bit Server VM" - VMVersion string `json:"vm_version"` // e.g. "25.25-b02" - VMVendor string `json:"vm_vendor"` // e.g. "Oracle Corporation" - StartTime time.Time `json:"start_time"` // e.g. "2015-01-03T15:18:30.982Z" - StartTimeInMillis int64 `json:"start_time_in_millis"` - - // Mem information - Mem struct { - HeapInit string `json:"heap_init"` // e.g. 1gb - HeapInitInBytes int `json:"heap_init_in_bytes"` - HeapMax string `json:"heap_max"` // e.g. 4gb - HeapMaxInBytes int `json:"heap_max_in_bytes"` - NonHeapInit string `json:"non_heap_init"` // e.g. 2.4mb - NonHeapInitInBytes int `json:"non_heap_init_in_bytes"` - NonHeapMax string `json:"non_heap_max"` // e.g. 0b - NonHeapMaxInBytes int `json:"non_heap_max_in_bytes"` - DirectMax string `json:"direct_max"` // e.g. 4gb - DirectMaxInBytes int `json:"direct_max_in_bytes"` - } `json:"mem"` - - GCCollectors []string `json:"gc_collectors"` // e.g. ["ParNew"] - MemoryPools []string `json:"memory_pools"` // e.g. ["Code Cache", "Metaspace"] -} - -type NodesInfoNodeThreadPool struct { - Percolate *NodesInfoNodeThreadPoolSection `json:"percolate"` - Bench *NodesInfoNodeThreadPoolSection `json:"bench"` - Listener *NodesInfoNodeThreadPoolSection `json:"listener"` - Index *NodesInfoNodeThreadPoolSection `json:"index"` - Refresh *NodesInfoNodeThreadPoolSection `json:"refresh"` - Suggest *NodesInfoNodeThreadPoolSection `json:"suggest"` - Generic *NodesInfoNodeThreadPoolSection `json:"generic"` - Warmer *NodesInfoNodeThreadPoolSection `json:"warmer"` - Search *NodesInfoNodeThreadPoolSection `json:"search"` - Flush *NodesInfoNodeThreadPoolSection `json:"flush"` - Optimize *NodesInfoNodeThreadPoolSection `json:"optimize"` - Management *NodesInfoNodeThreadPoolSection `json:"management"` - Get *NodesInfoNodeThreadPoolSection `json:"get"` - Merge *NodesInfoNodeThreadPoolSection `json:"merge"` - Bulk *NodesInfoNodeThreadPoolSection `json:"bulk"` - Snapshot *NodesInfoNodeThreadPoolSection `json:"snapshot"` -} - -type NodesInfoNodeThreadPoolSection struct { - Type string `json:"type"` // e.g. fixed - Min int `json:"min"` // e.g. 4 - Max int `json:"max"` // e.g. 4 - KeepAlive string `json:"keep_alive"` // e.g. "5m" - QueueSize interface{} `json:"queue_size"` // e.g. "1k" or -1 -} - -type NodesInfoNodeNetwork struct { - RefreshInterval string `json:"refresh_interval"` // e.g. 1s - RefreshIntervalInMillis int `json:"refresh_interval_in_millis"` // e.g. 1000 - PrimaryInterface struct { - Address string `json:"address"` // e.g. 192.168.1.2 - Name string `json:"name"` // e.g. en0 - MACAddress string `json:"mac_address"` // e.g. 11:22:33:44:55:66 - } `json:"primary_interface"` -} - -type NodesInfoNodeTransport struct { - BoundAddress []string `json:"bound_address"` - PublishAddress string `json:"publish_address"` - Profiles map[string]*NodesInfoNodeTransportProfile `json:"profiles"` -} - -type NodesInfoNodeTransportProfile struct { - BoundAddress []string `json:"bound_address"` - PublishAddress string `json:"publish_address"` -} - -type NodesInfoNodeHTTP struct { - BoundAddress []string `json:"bound_address"` // e.g. ["127.0.0.1:9200", "[fe80::1]:9200", "[::1]:9200"] - PublishAddress string `json:"publish_address"` // e.g. "127.0.0.1:9300" - MaxContentLength string `json:"max_content_length"` // e.g. "100mb" - MaxContentLengthInBytes int64 `json:"max_content_length_in_bytes"` -} - -type NodesInfoNodePlugin struct { - Name string `json:"name"` - Description string `json:"description"` - Site bool `json:"site"` - JVM bool `json:"jvm"` - URL string `json:"url"` // e.g. /_plugin/dummy/ -} diff --git a/vendor/gopkg.in/olivere/elastic.v5/put_template.go b/vendor/gopkg.in/olivere/elastic.v5/put_template.go deleted file mode 100644 index 5bd8423b56..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/put_template.go +++ /dev/null @@ -1,145 +0,0 @@ -// 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 ( - "context" - "fmt" - "net/url" - - "gopkg.in/olivere/elastic.v5/uritemplates" -) - -// PutTemplateService creates or updates a search template. -// The documentation can be found at -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html. -type PutTemplateService struct { - client *Client - pretty bool - id string - opType string - version *int - versionType string - bodyJson interface{} - bodyString string -} - -// NewPutTemplateService creates a new PutTemplateService. -func NewPutTemplateService(client *Client) *PutTemplateService { - return &PutTemplateService{ - client: client, - } -} - -// Id is the template ID. -func (s *PutTemplateService) Id(id string) *PutTemplateService { - s.id = id - return s -} - -// OpType is an explicit operation type. -func (s *PutTemplateService) OpType(opType string) *PutTemplateService { - s.opType = opType - return s -} - -// Version is an explicit version number for concurrency control. -func (s *PutTemplateService) Version(version int) *PutTemplateService { - s.version = &version - return s -} - -// VersionType is a specific version type. -func (s *PutTemplateService) VersionType(versionType string) *PutTemplateService { - s.versionType = versionType - return s -} - -// BodyJson is the document as a JSON serializable object. -func (s *PutTemplateService) BodyJson(body interface{}) *PutTemplateService { - s.bodyJson = body - return s -} - -// BodyString is the document as a string. -func (s *PutTemplateService) BodyString(body string) *PutTemplateService { - s.bodyString = body - return s -} - -// buildURL builds the URL for the operation. -func (s *PutTemplateService) buildURL() (string, url.Values, error) { - // Build URL - path, err := uritemplates.Expand("/_search/template/{id}", map[string]string{ - "id": s.id, - }) - if err != nil { - return "", url.Values{}, err - } - - // Add query string parameters - params := url.Values{} - if s.version != nil { - params.Set("version", fmt.Sprintf("%d", *s.version)) - } - if s.versionType != "" { - params.Set("version_type", s.versionType) - } - if s.opType != "" { - params.Set("op_type", s.opType) - } - - return path, params, nil -} - -// Validate checks if the operation is valid. -func (s *PutTemplateService) 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 *PutTemplateService) Do(ctx context.Context) (*AcknowledgedResponse, 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(AcknowledgedResponse) - 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.v5/run-es.sh b/vendor/gopkg.in/olivere/elastic.v5/run-es.sh deleted file mode 100644 index 9389f0d7b8..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/run-es.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -VERSION=${VERSION:=5.6.16} -docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -v "$PWD/etc:/usr/share/elasticsearch/config" -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch:$VERSION elasticsearch -Expack.security.enabled=false -Expack.ml.enabled=false -Escript.inline=true -Escript.stored=true -Escript.file=true diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_indices.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_indices.go deleted file mode 100644 index ed5ec9d841..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_indices.go +++ /dev/null @@ -1,89 +0,0 @@ -// 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 - -// IndicesQuery can be used when executed across multiple indices, allowing -// to have a query that executes only when executed on an index that matches -// a specific list of indices, and another query that executes when it is -// executed on an index that does not match the listed indices. -// -// For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-indices-query.html -type IndicesQuery struct { - query Query - indices []string - noMatchQueryType string - noMatchQuery Query - queryName string -} - -// NewIndicesQuery creates and initializes a new indices query. -func NewIndicesQuery(query Query, indices ...string) *IndicesQuery { - return &IndicesQuery{ - query: query, - indices: indices, - } -} - -// NoMatchQuery sets the query to use when it executes on an index that -// does not match the indices provided. -func (q *IndicesQuery) NoMatchQuery(query Query) *IndicesQuery { - q.noMatchQuery = query - return q -} - -// NoMatchQueryType sets the no match query which can be either all or none. -func (q *IndicesQuery) NoMatchQueryType(typ string) *IndicesQuery { - q.noMatchQueryType = typ - return q -} - -// QueryName sets the query name for the filter. -func (q *IndicesQuery) QueryName(queryName string) *IndicesQuery { - q.queryName = queryName - return q -} - -// Source returns JSON for the function score query. -func (q *IndicesQuery) Source() (interface{}, error) { - // { - // "indices" : { - // "indices" : ["index1", "index2"], - // "query" : { - // "term" : { "tag" : "wow" } - // }, - // "no_match_query" : { - // "term" : { "tag" : "kow" } - // } - // } - // } - - source := make(map[string]interface{}) - params := make(map[string]interface{}) - source["indices"] = params - - params["indices"] = q.indices - - src, err := q.query.Source() - if err != nil { - return nil, err - } - params["query"] = src - - if q.noMatchQuery != nil { - src, err := q.noMatchQuery.Source() - if err != nil { - return nil, err - } - params["no_match_query"] = src - } else if q.noMatchQueryType != "" { - params["no_match_query"] = q.noMatchQueryType - } - if q.queryName != "" { - params["_name"] = q.queryName - } - - return source, nil -} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_request.go b/vendor/gopkg.in/olivere/elastic.v5/search_request.go deleted file mode 100644 index f9dff52d9b..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/search_request.go +++ /dev/null @@ -1,217 +0,0 @@ -// 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" - "strings" -) - -// SearchRequest combines a search request and its -// query details (see SearchSource). -// It is used in combination with MultiSearch. -type SearchRequest struct { - searchType string - 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{} -} - -// SearchRequest must be one of dfs_query_then_fetch, query_then_fetch -// or query_and_fetch (deprecated in 5.3). -func (r *SearchRequest) SearchType(searchType string) *SearchRequest { - r.searchType = searchType - return r -} - -// SearchTypeDfsQueryThenFetch sets search type to dfs_query_then_fetch. -func (r *SearchRequest) SearchTypeDfsQueryThenFetch() *SearchRequest { - return r.SearchType("dfs_query_then_fetch") -} - -// SearchTypeQueryThenFetch sets search type to query_then_fetch. -func (r *SearchRequest) SearchTypeQueryThenFetch() *SearchRequest { - return r.SearchType("query_then_fetch") -} - -// SearchTypeQueryAndFetch sets search type to query_and_fetch which -// was deprecated in 5.3. -func (r *SearchRequest) SearchTypeQueryAndFetch() *SearchRequest { - return r.SearchType("query_and_fetch") -} - -func (r *SearchRequest) Index(indices ...string) *SearchRequest { - r.indices = append(r.indices, indices...) - return r -} - -func (r *SearchRequest) HasIndices() bool { - return len(r.indices) > 0 -} - -func (r *SearchRequest) Type(types ...string) *SearchRequest { - r.types = append(r.types, types...) - return r -} - -func (r *SearchRequest) Routing(routing string) *SearchRequest { - r.routing = &routing - return r -} - -func (r *SearchRequest) Routings(routings ...string) *SearchRequest { - if routings != nil { - routings := strings.Join(routings, ",") - r.routing = &routings - } else { - r.routing = nil - } - return r -} - -func (r *SearchRequest) Preference(preference string) *SearchRequest { - r.preference = &preference - return r -} - -func (r *SearchRequest) RequestCache(requestCache bool) *SearchRequest { - r.requestCache = &requestCache - 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 -} - -func (r *SearchRequest) SearchSource(searchSource *SearchSource) *SearchRequest { - return r.Source(searchSource) -} - -func (r *SearchRequest) Source(source interface{}) *SearchRequest { - r.source = source - return r -} - -// header is used e.g. by MultiSearch to get information about the search header -// of one SearchRequest. -// 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 != "" { - h["search_type"] = r.searchType - } - - switch len(r.indices) { - case 0: - case 1: - h["index"] = r.indices[0] - default: - h["indices"] = r.indices - } - - switch len(r.types) { - case 0: - case 1: - h["type"] = r.types[0] - default: - h["types"] = r.types - } - - 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"] = *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 - } - - return h -} - -// Body allows to access the search body of the request, as generated by the DSL. -// Notice that Body is read-only. You must not change the request body. -// -// Body is used e.g. by MultiSearch to get information about the search body -// of one SearchRequest. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-multi-search.html -func (r *SearchRequest) Body() (string, error) { - switch t := r.source.(type) { - default: - body, err := json.Marshal(r.source) - if err != nil { - return "", err - } - return string(body), nil - case *SearchSource: - src, err := t.Source() - if err != nil { - return "", err - } - body, err := json.Marshal(src) - if err != nil { - return "", err - } - return string(body), nil - case json.RawMessage: - return string(t), nil - case *json.RawMessage: - return string(*t), nil - case string: - return t, nil - case *string: - if t != nil { - return *t, nil - } - return "{}", nil - } -} diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggest.go b/vendor/gopkg.in/olivere/elastic.v5/suggest.go deleted file mode 100644 index 7249abd5f3..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/suggest.go +++ /dev/null @@ -1,158 +0,0 @@ -// 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 ( - "context" - "encoding/json" - "fmt" - "net/url" - "strings" - - "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 - index []string - suggesters []Suggester -} - -// NewSuggestService creates a new instance of SuggestService. -func NewSuggestService(client *Client) *SuggestService { - builder := &SuggestService{ - client: client, - } - return builder -} - -// 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 -} - -// buildURL builds the URL for the operation. -func (s *SuggestService) buildURL() (string, url.Values, error) { - var err error - var path string - - if len(s.index) > 0 { - path, err = uritemplates.Expand("/{index}/_suggest", map[string]string{ - "index": strings.Join(s.index, ","), - }) - } else { - path = "/_suggest" - } - if err != nil { - return "", url.Values{}, err - } - - // Add query string parameters - params := url.Values{} - if s.pretty { - params.Set("pretty", fmt.Sprintf("%v", s.pretty)) - } - if s.routing != "" { - params.Set("routing", s.routing) - } - 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{}) - for _, s := range s.suggesters { - src, err := s.Source(false) - if err != nil { - return nil, err - } - body[s.Name()] = src - } - - // Get response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) - if err != nil { - return nil, err - } - - // There is a _shard object that cannot be deserialized. - // So we use json.RawMessage instead. - var suggestions map[string]*json.RawMessage - if err := s.client.decoder.Decode(res.Body, &suggestions); err != nil { - return nil, err - } - - ret := make(SuggestResult) - for name, result := range suggestions { - if name != "_shards" { - var sug []Suggestion - if err := s.client.decoder.Decode(*result, &sug); err != nil { - return nil, err - } - ret[name] = sug - } - } - - 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"` - Length int `json:"length"` - Options []suggestionOption `json:"options"` -} - -type suggestionOption struct { - Text string `json:"text"` - Score float64 `json:"score"` - Freq int `json:"freq"` - Payload interface{} `json:"payload"` - CollateMatch bool `json:"collate_match"` -} diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggester_completion_fuzzy.go b/vendor/gopkg.in/olivere/elastic.v5/suggester_completion_fuzzy.go deleted file mode 100644 index eccd1a0206..0000000000 --- a/vendor/gopkg.in/olivere/elastic.v5/suggester_completion_fuzzy.go +++ /dev/null @@ -1,181 +0,0 @@ -// 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 - -// FuzzyCompletionSuggester is a CompletionSuggester that allows fuzzy -// completion. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-completion.html -// for details, and -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-completion.html#fuzzy -// for details about the fuzzy completion suggester. -// -// @Deprecated Use CompletionSuggester with FuzzyOptions instead. -type FuzzyCompletionSuggester struct { - Suggester - name string - text string - field string - analyzer string - size *int - shardSize *int - contextQueries []SuggesterContextQuery - - fuzziness interface{} - fuzzyTranspositions *bool - fuzzyMinLength *int - fuzzyPrefixLength *int - unicodeAware *bool -} - -// Fuzziness defines the fuzziness which is used in FuzzyCompletionSuggester. -type Fuzziness struct { -} - -// Creates a new completion suggester. -func NewFuzzyCompletionSuggester(name string) *FuzzyCompletionSuggester { - return &FuzzyCompletionSuggester{ - name: name, - contextQueries: make([]SuggesterContextQuery, 0), - } -} - -func (q *FuzzyCompletionSuggester) Name() string { - return q.name -} - -func (q *FuzzyCompletionSuggester) Text(text string) *FuzzyCompletionSuggester { - q.text = text - return q -} - -func (q *FuzzyCompletionSuggester) Field(field string) *FuzzyCompletionSuggester { - q.field = field - return q -} - -func (q *FuzzyCompletionSuggester) Analyzer(analyzer string) *FuzzyCompletionSuggester { - q.analyzer = analyzer - return q -} - -func (q *FuzzyCompletionSuggester) Size(size int) *FuzzyCompletionSuggester { - q.size = &size - return q -} - -func (q *FuzzyCompletionSuggester) ShardSize(shardSize int) *FuzzyCompletionSuggester { - q.shardSize = &shardSize - return q -} - -func (q *FuzzyCompletionSuggester) ContextQuery(query SuggesterContextQuery) *FuzzyCompletionSuggester { - q.contextQueries = append(q.contextQueries, query) - return q -} - -func (q *FuzzyCompletionSuggester) ContextQueries(queries ...SuggesterContextQuery) *FuzzyCompletionSuggester { - q.contextQueries = append(q.contextQueries, queries...) - return q -} - -// 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 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 - return q -} - -func (q *FuzzyCompletionSuggester) FuzzyTranspositions(fuzzyTranspositions bool) *FuzzyCompletionSuggester { - q.fuzzyTranspositions = &fuzzyTranspositions - return q -} - -func (q *FuzzyCompletionSuggester) FuzzyMinLength(minLength int) *FuzzyCompletionSuggester { - q.fuzzyMinLength = &minLength - return q -} - -func (q *FuzzyCompletionSuggester) FuzzyPrefixLength(prefixLength int) *FuzzyCompletionSuggester { - q.fuzzyPrefixLength = &prefixLength - return q -} - -func (q *FuzzyCompletionSuggester) UnicodeAware(unicodeAware bool) *FuzzyCompletionSuggester { - q.unicodeAware = &unicodeAware - return q -} - -// Creates the source for the completion suggester. -func (q *FuzzyCompletionSuggester) Source(includeName bool) (interface{}, error) { - cs := &completionSuggesterRequest{} - - if q.text != "" { - cs.Text = q.text - } - - suggester := make(map[string]interface{}) - cs.Completion = suggester - - if q.analyzer != "" { - suggester["analyzer"] = q.analyzer - } - if q.field != "" { - suggester["field"] = q.field - } - if q.size != nil { - suggester["size"] = *q.size - } - if q.shardSize != nil { - suggester["shard_size"] = *q.shardSize - } - switch len(q.contextQueries) { - case 0: - case 1: - src, err := q.contextQueries[0].Source() - if err != nil { - return nil, err - } - suggester["context"] = src - default: - var ctxq []interface{} - for _, query := range q.contextQueries { - src, err := query.Source() - if err != nil { - return nil, err - } - ctxq = append(ctxq, src) - } - suggester["context"] = ctxq - } - - // Fuzzy Completion Suggester fields - fuzzy := make(map[string]interface{}) - suggester["fuzzy"] = fuzzy - if q.fuzziness != nil { - fuzzy["fuzziness"] = q.fuzziness - } - if q.fuzzyTranspositions != nil { - fuzzy["transpositions"] = *q.fuzzyTranspositions - } - if q.fuzzyMinLength != nil { - fuzzy["min_length"] = *q.fuzzyMinLength - } - if q.fuzzyPrefixLength != nil { - fuzzy["prefix_length"] = *q.fuzzyPrefixLength - } - if q.unicodeAware != nil { - fuzzy["unicode_aware"] = *q.unicodeAware - } - - if !includeName { - return cs, nil - } - - source := make(map[string]interface{}) - source[q.name] = cs - return source, nil -} diff --git a/vendor/gopkg.in/olivere/elastic.v6/.fossa.yml b/vendor/gopkg.in/olivere/elastic.v6/.fossa.yml new file mode 100644 index 0000000000..61669d85f8 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/.fossa.yml @@ -0,0 +1,38 @@ +# Generated by FOSSA CLI (https://github.com/fossas/fossa-cli) +# Visit https://fossa.io to learn more + +version: 1 +cli: + server: https://app.fossa.io + fetcher: git + project: git@github.com:olivere/elastic.git +analyze: + modules: + - name: github.com/olivere/elastic + path: . + target: github.com/olivere/elastic + type: go + - name: github.com/olivere/elastic/config + path: ./config + target: github.com/olivere/elastic/config + type: go + - name: github.com/olivere/elastic/uritemplates + path: ./uritemplates + target: github.com/olivere/elastic/uritemplates + type: go + - name: github.com/olivere/elastic/trace/opencensus + path: ./trace/opencensus + target: github.com/olivere/elastic/trace/opencensus + type: go + - name: github.com/olivere/elastic/trace/opentracing + path: ./trace/opentracing + target: github.com/olivere/elastic/trace/opentracing + type: go + - name: github.com/olivere/elastic/aws + path: ./aws + target: github.com/olivere/elastic/aws + type: go + - name: github.com/olivere/elastic/aws/v4 + path: ./aws/v4 + target: github.com/olivere/elastic/aws/v4 + type: go diff --git a/vendor/gopkg.in/olivere/elastic.v5/.gitignore b/vendor/gopkg.in/olivere/elastic.v6/.gitignore similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/.gitignore rename to vendor/gopkg.in/olivere/elastic.v6/.gitignore index 306ffbd832..5dc4d56810 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/.gitignore +++ b/vendor/gopkg.in/olivere/elastic.v6/.gitignore @@ -22,11 +22,13 @@ _testmain.go *.exe /.vscode/ +/.idea/ /debug.test /generator /cluster-test/cluster-test /cluster-test/*.log /cluster-test/es-chaos-monkey +/go.sum /spec /tmp /CHANGELOG-3.0.html diff --git a/vendor/gopkg.in/olivere/elastic.v6/.golangci.yml b/vendor/gopkg.in/olivere/elastic.v6/.golangci.yml new file mode 100644 index 0000000000..253fea4806 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/.golangci.yml @@ -0,0 +1,78 @@ +run: + # 30min deadline + deadline: 30m + # Fail when any changes to go.mod are needed + # (enable after Go modules are introduced) + #modules-download-mode: readonly + # Skip certain directories + skip-dirs: + - node_modules$ + # Skip certain auto-generated files + skip-files: + - ".*\\.pb\\.go$" + +linters-settings: + errcheck: + check-blank: false + ignore: fmt:.*,io/ioutil:^Read.*,os:^Write.*,net/http:^ParseForm.*,github.com/go-kit/kit/log:^Log.*,github.com/go-kit/kit/log/level:^Log.* + govet: + check-shadowing: false + settings: + printf: # analyzer name, run `go tool vet help` to see all analyzers + funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + - (github.com/go-kit/kit/log.Logger).Log + golint: + min-confidence: 0.8 + gocyclo: + min-complexity: 30 + maligned: + suggest-new: true + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 2 + depguard: + list-type: blacklist + packages: + - github.com/davecgh/go-spew/spew + misspell: + locale: US + lll: + line-length: 120 + goimports: + # put imports beginning with prefix after 3rd-party packages; + # it's a comma-separated list of prefixes + local-prefixes: github.com/olivere/elastic + gocritic: + enabled-tags: + - performance + - style + - experimental + disabled-checks: + - wrapperFunc + - importShadow + +linters: + enable-all: true + disable: + - maligned + - prealloc + - gochecknoglobals + - gochecknoinits + - gocyclo + - dupl + - lll + - goconst + +issues: + exclude-rules: + - linters: + - lll + source: '^//go:generate ' + - path: sage/ + text: "ALL_CAPS|don't use underscores in Go names|struct field.*should be" diff --git a/vendor/gopkg.in/olivere/elastic.v6/.travis.yml b/vendor/gopkg.in/olivere/elastic.v6/.travis.yml new file mode 100644 index 0000000000..beda7fd727 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/.travis.yml @@ -0,0 +1,33 @@ +sudo: required +language: go +go: +- "1.11.x" +- "1.12.x" +- tip +matrix: + allow_failures: + - go: tip +env: +- GO111MODULE=on +- GO111MODULE=off +addons: + ssh_known_hosts: github.com + apt: + update: true + packages: + - docker-ce +services: +- docker +before_install: +- if [[ "$TRAVIS_OS_NAME" == "linux" && ! $(which nc) ]] ; then sudo apt-get install -y netcat ; fi +- sudo sysctl -w vm.max_map_count=262144 +- docker-compose pull +- docker-compose up -d +- go get -u github.com/google/go-cmp/cmp +- go get -u github.com/fortytw2/leaktest +- go get . ./aws/... ./config/... ./trace/... ./uritemplates/... +- while ! nc -z localhost 9200; do sleep 1; done +- while ! nc -z localhost 9210; do sleep 1; done +install: true # ignore the go get -t -v ./... +script: +- go test -race -v . ./aws/... ./config/... ./trace/... ./uritemplates/... diff --git a/vendor/gopkg.in/olivere/elastic.v5/CHANGELOG-3.0.md b/vendor/gopkg.in/olivere/elastic.v6/CHANGELOG-3.0.md similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/CHANGELOG-3.0.md rename to vendor/gopkg.in/olivere/elastic.v6/CHANGELOG-3.0.md diff --git a/vendor/gopkg.in/olivere/elastic.v5/CHANGELOG-5.0.md b/vendor/gopkg.in/olivere/elastic.v6/CHANGELOG-5.0.md similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/CHANGELOG-5.0.md rename to vendor/gopkg.in/olivere/elastic.v6/CHANGELOG-5.0.md diff --git a/vendor/gopkg.in/olivere/elastic.v6/CHANGELOG-6.0.md b/vendor/gopkg.in/olivere/elastic.v6/CHANGELOG-6.0.md new file mode 100644 index 0000000000..e354a8567c --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/CHANGELOG-6.0.md @@ -0,0 +1,18 @@ +# Changes from 5.0 to 6.0 + +See [breaking changes](https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-6.0.html). + +## _all removed + +6.0 has removed support for the `_all` field. + +## Boolean values coerced + +Only use `true` or `false` for boolean values, not `0` or `1` or `on` or `off`. + +## Single Type Indices + +Notice that 6.0 and future versions will default to single type indices, i.e. you may not use multiple types when e.g. adding an index with a mapping. + +See [here for details](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/removal-of-types.html#_what_are_mapping_types). + diff --git a/vendor/gopkg.in/olivere/elastic.v5/CODE_OF_CONDUCT.md b/vendor/gopkg.in/olivere/elastic.v6/CODE_OF_CONDUCT.md similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/CODE_OF_CONDUCT.md rename to vendor/gopkg.in/olivere/elastic.v6/CODE_OF_CONDUCT.md diff --git a/vendor/gopkg.in/olivere/elastic.v5/CONTRIBUTING.md b/vendor/gopkg.in/olivere/elastic.v6/CONTRIBUTING.md similarity index 88% rename from vendor/gopkg.in/olivere/elastic.v5/CONTRIBUTING.md rename to vendor/gopkg.in/olivere/elastic.v6/CONTRIBUTING.md index 4fbc79dd0d..c7c425a3ef 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/CONTRIBUTING.md +++ b/vendor/gopkg.in/olivere/elastic.v6/CONTRIBUTING.md @@ -18,7 +18,7 @@ that we missed some features or changes. Feel free to change that. To make it easy to review and understand your changes, please keep the following things in mind before submitting your pull request: -* You compared the existing implemenation with the Java API, did you? +* You compared the existing implementation with the Java API, did you? * Please work on the latest possible state of `olivere/elastic`. Use `release-branch.v2` for targeting Elasticsearch 1.x and `release-branch.v3` for targeting 2.x. @@ -36,5 +36,5 @@ following things in mind before submitting your pull request: ## Additional Resources -* [GitHub documentation](http://help.github.com/) -* [GitHub pull request documentation](http://help.github.com/send-pull-requests/) +* [GitHub documentation](https://help.github.com/) +* [GitHub pull request documentation](https://help.github.com/en/articles/creating-a-pull-request) diff --git a/vendor/gopkg.in/olivere/elastic.v6/CONTRIBUTORS b/vendor/gopkg.in/olivere/elastic.v6/CONTRIBUTORS new file mode 100644 index 0000000000..6bf0ff9a54 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/CONTRIBUTORS @@ -0,0 +1,185 @@ +# This is a list of people who have contributed code +# to the Elastic repository. +# +# It is just my small "thank you" to all those that helped +# making Elastic what it is. +# +# Please keep this list sorted. + +0x6875790d0a [@huydx](https://github.com/huydx) +Aaron Tami [@aarontami](https://github.com/aarontami) +Adam Alix [@adamalix](https://github.com/adamalix) +Adam Weiner [@adamweiner](https://github.com/adamweiner) +Adrian Lungu [@AdrianLungu](https://github.com/AdrianLungu) +alehano [@alehano](https://github.com/alehano) +Alejandro Carstens [@alejandro-carstens](https://github.com/alejandro-carstens) +Alex [@akotlar](https://github.com/akotlar) +Alexander Sack [@asac](https://github.com/asac) +Alexandre Olivier [@aliphen](https://github.com/aliphen) +Alexey Sharov [@nizsheanez](https://github.com/nizsheanez) +Anders [@ANerd](https://github.com/ANerd) +AndreKR [@AndreKR](https://github.com/AndreKR) +André Bierlein [@ligustah](https://github.com/ligustah) +Andrew Dunham [@andrew-d](https://github.com/andrew-d) +Andrew Gaul [@andrewgaul](https://github.com/andrewgaul) +Andy Walker [@alaska](https://github.com/alaska) +Arquivei [@arquivei](https://github.com/arquivei) +Artemiy Elozhenko [@artezh](https://github.com/artezh) +arthurgustin [@arthurgustin](https://github.com/arthurgustin) +Bas van Dijk [@basvandijk](https://github.com/basvandijk) +Benjamin Fernandes [@LotharSee](https://github.com/LotharSee) +Benjamin Zarzycki [@kf6nux](https://github.com/kf6nux) +Björn Gerdau [@kernle32dll](https://github.com/kernle32dll) +Boris Popovschi [@Zyqsempai](https://github.com/Zyqsempai) +Bowei Xu [@vancexu](https://github.com/vancexu) +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) +Carl Dunham [@carldunham](https://github.com/carldunham) +Carl Johan Gustavsson [@cjgu](https://github.com/cjgu) +Cat [@cat-turner](https://github.com/cat-turner) +César Jiménez [@cesarjimenez](https://github.com/cesarjimenez) +cforbes [@cforbes](https://github.com/cforbes) +張泰瑋(Chang Tai Wei) [@david30907d](https://github.com/david30907d) +Chris M [@tebriel](https://github.com/tebriel) +Chris Rice [@donutmonger](https://github.com/donutmonger) +Claudiu Olteanu [@claudiuolteanu](https://github.com/claudiuolteanu) +Chris Duncan [@veqryn](https://github.com/veqryn) +Chris Ludden [@cludden](https://github.com/cludden) +Christophe Courtaut [@kri5](https://github.com/kri5) +cmitchell [@cmitchell](https://github.com/cmitchell) +Connor Peet [@connor4312](https://github.com/connor4312) +Conrad Pankoff [@deoxxa](https://github.com/deoxxa) +Corey Scott [@corsc](https://github.com/corsc) +Chris Petersen [@ex-nerd](https://github.com/ex-nerd) +Daniel Barrett [@shendaras](https://github.com/shendaras) +Daniel Heckrath [@DanielHeckrath](https://github.com/DanielHeckrath) +Daniel Imfeld [@dimfeld](https://github.com/dimfeld) +Daniel Santos [@danlsgiga](https://github.com/danlsgiga) +David Emanuel Buchmann [@wuurrd](https://github.com/wuurrd) +Diego Becciolini [@itizir](https://github.com/itizir) +Dwayne Schultz [@myshkin5](https://github.com/myshkin5) +Elliot Williams [@elliotwms](https://github.com/elliotwms) +Ellison Leão [@ellisonleao](https://github.com/ellisonleao) +Erik Grinaker [@erikgrinaker](https://github.com/erikgrinaker) +Erwin [@eticzon](https://github.com/eticzon) +Etienne Lafarge [@elafarge](https://github.com/elafarge) +Eugene Egorov [@EugeneEgorov](https://github.com/EugeneEgorov) +Evan Shaw [@edsrzf](https://github.com/edsrzf) +Fanfan [@wenpos](https://github.com/wenpos) +Faolan C-P [@fcheslack](https://github.com/fcheslack) +Filip Tepper [@filiptepper](https://github.com/filiptepper) +Garrett Kelley [@GarrettKelley](https://github.com/GarrettKelley) +Gaspard Douady [@plopik](https://github.com/plopik) +Gaylord Aulke [@blafasel42](https://github.com/blafasel42) +Gerhard Häring [@ghaering](https://github.com/ghaering) +gregoryfranklin [@gregoryfranklin](https://github.com/gregoryfranklin) +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) +Harmen [@alicebob](https://github.com/alicebob) +Harrison Wright [@wright8191](https://github.com/wright8191) +Henry Clifford [@hcliff](https://github.com/hcliff) +Igor Dubinskiy [@idubinskiy](https://github.com/idubinskiy) +initialcontext [@initialcontext](https://github.com/initialcontext) +Isaac Saldana [@isaldana](https://github.com/isaldana) +J Barkey Wolf [@jjhbw](https://github.com/jjhbw) +Jack Lindamood [@cep21](https://github.com/cep21) +Jacob [@jdelgad](https://github.com/jdelgad) +Jan Düpmeier [@jduepmeier](https://github.com/jduepmeier) +Jayme Rotsaert [@jrots](https://github.com/jrots) +Jean-Alexandre Beaumont [@Enteris](https://github.com/Enteris) +Jean-François Roche [@jfroche](https://github.com/jfroche) +Jeff Rand [@jeffrand](https://github.com/jeffrand) +Jeremy Canady [@jrmycanady](https://github.com/jrmycanady) +Jérémie Vexiau [@texvex](https://github.com/texvex) +Jesper Bränn [@Yopi](https://github.com/Yopi) +Jim Berlage [@jimberlage](https://github.com/jimberlage) +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) +Jonas Groenaas Drange [@semafor](https://github.com/semafor) +Josef Fröhle [@Dexus](https://github.com/Dexus) +José Martínez [@xose](https://github.com/xose) +Josh Chorlton [@jchorl](https://github.com/jchorl) +Jpnock [@Jpnock](https://github.com/Jpnock) +jun [@coseyo](https://github.com/coseyo) +Junpei Tsuji [@jun06t](https://github.com/jun06t) +kartlee [@kartlee](https://github.com/kartlee) +Keith Hatton [@khatton-ft](https://github.com/khatton-ft) +kel [@liketic](https://github.com/liketic) +Kenta SUZUKI [@suzuken](https://github.com/suzuken) +Kevin Mulvey [@kmulvey](https://github.com/kmulvey) +Kyle Brandt [@kylebrandt](https://github.com/kylebrandt) +Larry Cinnabar [@larrycinnabar](https://github.com/larrycinnabar) +Leandro Piccilli [@lpic10](https://github.com/lpic10) +Lee [@leezhm](https://github.com/leezhm) +lechnertech [@lechnertech](https://github.com/lechnertech) +M. Zulfa Achsani [@misterciput](https://github.com/misterciput) +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) +Martin Häger [@protomouse](https://github.com/protomouse) +Matt Braymer-Hayes [@mattayes](https://github.com/mattayes) +Medhi Bechina [@mdzor](https://github.com/mdzor) +Mike Beshai [@mbesh](https://github.com/mbesh) +mmfrb [@mmfrb](https://github.com/mmfrb) +mnpritula [@mnpritula](https://github.com/mnpritula) +mosa [@mosasiru](https://github.com/mosasiru) +Muhammet Çakır [@cakirmuha](https://github.com/cakirmuha) +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) +NeoCN [@NeoCN](https://github.com/NeoCN) +Nicholas Wolff [@nwolff](https://github.com/nwolff) +Nick K [@utrack](https://github.com/utrack) +Nick Whyte [@nickw444](https://github.com/nickw444) +Nicolae Vartolomei [@nvartolomei](https://github.com/nvartolomei) +okhowang [@okhowang](https://github.com/okhowang) +Orne Brocaar [@brocaar](https://github.com/brocaar) +Paul [@eyeamera](https://github.com/eyeamera) +Paul Oldenburg [@lr-paul](https://github.com/lr-paul) +Pete C [@peteclark-ft](https://github.com/peteclark-ft) +Peter Nagy [@nagypeterjob](https://github.com/nagypeterjob) +Paolo [@ppiccolo](https://github.com/ppiccolo) +Radoslaw Wesolowski [@r--w](https://github.com/r--w) +Rafał Gałus [@rgalus](https://github.com/rgalus) +rchicoli [@rchicoli](https://github.com/rchicoli) +Roman Colohanin [@zuzmic](https://github.com/zuzmic) +Ryan Schmukler [@rschmukler](https://github.com/rschmukler) +Ryan Wynn [@rwynn](https://github.com/rwynn) +Sacheendra talluri [@sacheendra](https://github.com/sacheendra) +Sean DuBois [@Sean-Der](https://github.com/Sean-Der) +Sagan Yaroslav [@sgnrslv](https://github.com/sgnrslv) +Shalin LK [@shalinlk](https://github.com/shalinlk) +singham [@zhaochenxiao90](https://github.com/zhaochenxiao90) +Slawomir CALUCH [@slawo](https://github.com/slawo) +soarpenguin [@soarpenguin](https://github.com/soarpenguin) +Stephan Krynauw [@skrynauw](https://github.com/skrynauw) +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) +Swarlston [@Swarlston](https://github.com/Swarlston) +Take [ww24](https://github.com/ww24) +Tetsuya Morimoto [@t2y](https://github.com/t2y) +TheZeroSlave [@TheZeroSlave](https://github.com/TheZeroSlave) +Tomasz Elendt [@telendt](https://github.com/telendt) +TimeEmit [@TimeEmit](https://github.com/timeemit) +TusharM [@tusharm](https://github.com/tusharm) +wangtuo [@wangtuo](https://github.com/wangtuo) +Wédney Yuri [@wedneyyuri](https://github.com/wedneyyuri) +Wesley Kim [@wesleyk](https://github.com/wesleyk) +wolfkdy [@wolfkdy](https://github.com/wolfkdy) +Wyndham Blanton [@wyndhblb](https://github.com/wyndhblb) +Yarden Bar [@ayashjorden](https://github.com/ayashjorden) +Yuya Kusakabe [@higebu](https://github.com/higebu) +zakthomas [@zakthomas](https://github.com/zakthomas) +Zach [@snowzach](https://github.com/snowzach) +zhangxin [@visaxin](https://github.com/visaxin) +@林 [@zplzpl](https://github.com/zplzpl) diff --git a/vendor/gopkg.in/olivere/elastic.v5/ISSUE_TEMPLATE.md b/vendor/gopkg.in/olivere/elastic.v6/ISSUE_TEMPLATE.md similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/ISSUE_TEMPLATE.md rename to vendor/gopkg.in/olivere/elastic.v6/ISSUE_TEMPLATE.md index c5eb690a75..4cc4eba68a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/ISSUE_TEMPLATE.md +++ b/vendor/gopkg.in/olivere/elastic.v6/ISSUE_TEMPLATE.md @@ -3,9 +3,10 @@ your issue/question without further inquiry. Thank you. ### Which version of Elastic are you using? -[ ] elastic.v2 (for Elasticsearch 1.x) -[ ] elastic.v3 (for Elasticsearch 2.x) +[ ] elastic.v6 (for Elasticsearch 6.x) [ ] elastic.v5 (for Elasticsearch 5.x) +[ ] elastic.v3 (for Elasticsearch 2.x) +[ ] elastic.v2 (for Elasticsearch 1.x) ### Please describe the expected behavior diff --git a/vendor/gopkg.in/olivere/elastic.v6/LICENSE b/vendor/gopkg.in/olivere/elastic.v6/LICENSE new file mode 100644 index 0000000000..8b22cdb601 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) +Copyright © 2012-2015 Oliver Eilhard + +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.v5/README.md b/vendor/gopkg.in/olivere/elastic.v6/README.md similarity index 68% rename from vendor/gopkg.in/olivere/elastic.v5/README.md rename to vendor/gopkg.in/olivere/elastic.v6/README.md index 30930ff228..6b52c136c7 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/README.md +++ b/vendor/gopkg.in/olivere/elastic.v6/README.md @@ -1,46 +1,62 @@ # Elastic +**This is a development branch that is actively being worked on. DO NOT USE IN PRODUCTION! If you want to use stable versions of Elastic, please use a dependency manager like [dep](https://github.com/golang/dep).** + 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.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) +[![Build Status](https://travis-ci.org/olivere/elastic.svg?branch=release-branch.v6)](https://travis-ci.org/olivere/elastic) +[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](http://godoc.org/github.com/olivere/elastic) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/olivere/elastic/master/LICENSE) +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Folivere%2Felastic.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Folivere%2Felastic?ref=badge_shield) See the [wiki](https://github.com/olivere/elastic/wiki) for additional information about Elastic. +Buy Me A Coffee + ## Releases -**The release branches (e.g. [`release-branch.v5`](https://github.com/olivere/elastic/tree/release-branch.v5)) +**The release branches (e.g. [`release-branch.v6`](https://github.com/olivere/elastic/tree/release-branch.v6)) 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).** +If you want to use stable versions of Elastic, please use a dependency manager like [dep](https://github.com/golang/dep).** 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)) +Elasticsearch version | Elastic version | Package URL | Remarks | +----------------------|------------------|-------------|---------| +6.x                   | 6.0             | [`github.com/olivere/elastic`](https://github.com/olivere/elastic) ([source](https://github.com/olivere/elastic/tree/release-branch.v6) [doc](http://godoc.org/github.com/olivere/elastic)) | Use a dependency manager (see below). +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)) | Actively maintained. +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)) | Deprecated. Please update. +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)) | Deprecated. Please update. +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)) | Deprecated. Please update. **Example:** -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. +You have installed Elasticsearch 6.0.0 and want to use Elastic. +As listed above, you should use Elastic 6.0. -```sh -$ go get gopkg.in/olivere/elastic.v5 -``` +To use the required version of Elastic in your application, it is strongly +advised to use a tool like +[dep](https://github.com/golang/dep) +or +[Go modules](https://github.com/golang/go/wiki/Modules) +to manage dependencies. Make sure to use a version such as `^6.0.0`. -You then import it with this import path: +To use Elastic, import: ```go -import elastic "gopkg.in/olivere/elastic.v5" +import "github.com/olivere/elastic" ``` +### Elastic 6.0 + +Elastic 6.0 targets Elasticsearch 6.x which was [released on 14th November 2017](https://www.elastic.co/blog/elasticsearch-6-0-0-released). + +Notice that there are a lot of [breaking changes in Elasticsearch 6.0](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes-6.0.html) +and we used this as an opportunity to [clean up and refactor Elastic](https://github.com/olivere/elastic/blob/release-branch.v6/CHANGELOG-6.0.md) +as we did in the transition from earlier versions of Elastic. + ### Elastic 5.0 Elastic 5.0 targets Elasticsearch 5.0.0 and later. Elasticsearch 5.0.0 was @@ -85,8 +101,8 @@ Having said that, there have been no big API changes that required you 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, and 2.0-2.4.1. Furthermore, we use [Travis CI](https://travis-ci.org/) +Elastic has been used in production starting with Elasticsearch 0.90 up to recent 6.x +versions. 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) @@ -107,11 +123,19 @@ 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. -An example is available [here](https://olivere.github.io/elastic/) +An example is available [here](https://olivere.github.io/elastic/). -Here's a [link to a complete working example for v3](https://gist.github.com/olivere/114347ff9d9cfdca7bdc0ecea8b82263). +Here's a [link to a complete working example for v6](https://gist.github.com/olivere/e4a376b4783c0914e44ea4f745ce2ebf). -See the [wiki](https://github.com/olivere/elastic/wiki) for more details. +Here are a few tips on how to get used to Elastic: + +1. Head over to the [Wiki](https://github.com/olivere/elastic/wiki) for detailed information and + topics like e.g. [how to add a middleware](https://github.com/olivere/elastic/wiki/HttpTransport) + or how to [connect to AWS](https://github.com/olivere/elastic/wiki/Using-with-AWS-Elasticsearch-Service). +2. If you are unsure how to implement something, read the tests (all `_test.go` files). + They not only serve as a guard against changes, but also as a reference. +3. The [recipes](https://github.com/olivere/elastic/tree/release-branch.v6/recipes) + contains small examples on how to implement something, e.g. bulk indexing, scrolling etc. ## API Status @@ -143,12 +167,10 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [x] Context Suggester - [x] Multi Search API - [x] Count API -- [ ] Search Exists API - [x] Validate API - [x] Explain API - [x] Profile API - [x] Field Capabilities API -- [x] Field Stats API ### Aggregations @@ -186,7 +208,9 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [x] Reverse Nested - [x] Sampler - [x] Significant Terms + - [x] Significant Text - [x] Terms + - [x] Composite - Pipeline Aggregations - [x] Avg Bucket - [x] Derivative @@ -200,6 +224,7 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [x] Cumulative Sum - [x] Bucket Script - [x] Bucket Selector + - [x] Bucket Sort - [x] Serial Differencing - [x] Matrix Aggregations - [x] Matrix Stats @@ -222,17 +247,30 @@ See the [wiki](https://github.com/olivere/elastic/wiki) for more details. - [x] Update Indices Settings - [x] Get Settings - [x] Analyze + - [x] Explain Analyze - [x] Index Templates -- [ ] Shadow Replica Indices - [x] Indices Stats - [x] Indices Segments - [ ] Indices Recovery - [ ] Indices Shard Stores - [ ] Clear Cache - [x] Flush + - [x] Synced Flush - [x] Refresh - [x] Force Merge -- [ ] Upgrade + +### Index Lifecycle Management APIs + +- [x] Create Policy +- [x] Get Policy +- [x] Delete Policy +- [ ] Move to Step +- [ ] Remove Policy +- [ ] Retry Policy +- [ ] Get Ilm Status +- [ ] Explain Lifecycle +- [ ] Start Ilm +- [ ] Stop Ilm ### cat APIs @@ -255,6 +293,7 @@ The cat APIs are not implemented as of now. We think they are better suited for - [ ] cat shards - [ ] cat segments - [ ] cat snapshots +- [ ] cat templates ### Cluster APIs @@ -262,10 +301,12 @@ The cat APIs are not implemented as of now. We think they are better suited for - [x] Cluster State - [x] Cluster Stats - [ ] Pending Cluster Tasks -- [ ] Cluster Reroute +- [x] Cluster Reroute - [ ] Cluster Update Settings - [x] Nodes Stats - [x] Nodes Info +- [ ] Nodes Feature Usage +- [ ] Remote Cluster Info - [x] Task Management API - [ ] Nodes hot_threads - [ ] Cluster Allocation Explain API @@ -285,6 +326,7 @@ The cat APIs are not implemented as of now. We think they are better suited for - Term level queries - [x] Term Query - [x] Terms Query + - [x] Terms Set Query - [x] Range Query - [x] Exists Query - [x] Prefix Query @@ -299,7 +341,6 @@ The cat APIs are not implemented as of now. We think they are better suited for - [x] Dis Max Query - [x] Function Score Query - [x] Boosting Query - - [x] Indices Query - Joining queries - [x] Nested Query - [x] Has Child Query @@ -309,12 +350,9 @@ The cat APIs are not implemented as of now. We think they are better suited for - [ ] GeoShape Query - [x] Geo Bounding Box Query - [x] Geo Distance Query - - [ ] Geo Distance Range Query - [x] Geo Polygon Query - - [ ] Geohash Cell Query - Specialized queries - [x] More Like This Query - - [x] Template Query - [x] Script Query - [x] Percolate Query - Span queries @@ -334,11 +372,17 @@ The cat APIs are not implemented as of now. We think they are better suited for - Snapshot and Restore - [x] Repositories - - [ ] Snapshot + - [x] Snapshot get + - [x] Snapshot create + - [x] Snapshot delete - [ ] Restore - [ ] Snapshot status - [ ] Monitoring snapshot/restore status - [ ] Stopping currently running snapshot and restore +- Scripting + - [x] GetScript + - [x] PutScript + - [x] DeleteScript ### Sorting @@ -377,3 +421,6 @@ by Joshua Tacoma, MIT-LICENSE. See [LICENSE](http://olivere.mit-license.org/) or the LICENSE file provided in the repository for details. + + +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Folivere%2Felastic.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Folivere%2Felastic?ref=badge_large) diff --git a/vendor/gopkg.in/olivere/elastic.v5/acknowledged_response.go b/vendor/gopkg.in/olivere/elastic.v6/acknowledged_response.go similarity index 69% rename from vendor/gopkg.in/olivere/elastic.v5/acknowledged_response.go rename to vendor/gopkg.in/olivere/elastic.v6/acknowledged_response.go index 83f954f44c..2045ab85e4 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/acknowledged_response.go +++ b/vendor/gopkg.in/olivere/elastic.v6/acknowledged_response.go @@ -7,5 +7,7 @@ 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"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/backoff.go b/vendor/gopkg.in/olivere/elastic.v6/backoff.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/backoff.go rename to vendor/gopkg.in/olivere/elastic.v6/backoff.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk.go b/vendor/gopkg.in/olivere/elastic.v6/bulk.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v5/bulk.go rename to vendor/gopkg.in/olivere/elastic.v6/bulk.go index 7e2d3c53f4..04dadd8f3c 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/bulk.go +++ b/vendor/gopkg.in/olivere/elastic.v6/bulk.go @@ -10,8 +10,9 @@ import ( "errors" "fmt" "net/url" + "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // BulkService allows for batching bulk requests and sending them to @@ -23,7 +24,7 @@ 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/5.2/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html // for more details. type BulkService struct { client *Client @@ -38,6 +39,7 @@ type BulkService struct { routing string waitForActiveShards string pretty bool + filterPath []string // estimated bulk size in bytes, up to the request index sizeInBytesCursor sizeInBytes int64 @@ -91,8 +93,11 @@ func (s *BulkService) Timeout(timeout string) *BulkService { // 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). +// changes to be made visible by a refresh before reying), or "false" +// (no refresh related actions). The default value is "false". +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html +// for details. func (s *BulkService) Refresh(refresh string) *BulkService { s.refresh = refresh return s @@ -126,6 +131,14 @@ func (s *BulkService) Pretty(pretty bool) *BulkService { return s } +// FilterPath allows reducing the response, a mechanism known as +// response filtering and described here in +// https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#common-options-response-filtering. +func (s *BulkService) FilterPath(filterPath ...string) *BulkService { + s.filterPath = append(s.filterPath, filterPath...) + return s +} + // Add adds bulkable requests, i.e. BulkIndexRequest, BulkUpdateRequest, // and/or BulkDeleteRequest. func (s *BulkService) Add(requests ...BulkableRequest) *BulkService { @@ -227,6 +240,9 @@ func (s *BulkService) Do(ctx context.Context) (*BulkResponse, error) { if s.pretty { params.Set("pretty", fmt.Sprintf("%v", s.pretty)) } + if len(s.filterPath) > 0 { + params.Set("filter_path", strings.Join(s.filterPath, ",")) + } if s.pipeline != "" { params.Set("pipeline", s.pipeline) } @@ -244,7 +260,7 @@ func (s *BulkService) Do(ctx context.Context) (*BulkResponse, error) { } // Get response - res, err := s.client.PerformRequestWithOptions(ctx, PerformRequestOptions{ + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ Method: "POST", Path: path, Params: params, @@ -321,10 +337,12 @@ type BulkResponseItem struct { Type string `json:"_type,omitempty"` Id string `json:"_id,omitempty"` Version int64 `json:"_version,omitempty"` - Status int `json:"status,omitempty"` Result string `json:"result,omitempty"` + Shards *ShardsInfo `json:"_shards,omitempty"` + SeqNo int64 `json:"_seq_no,omitempty"` + PrimaryTerm int64 `json:"_primary_term,omitempty"` + Status int `json:"status,omitempty"` ForcedRefresh bool `json:"forced_refresh,omitempty"` - Found bool `json:"found,omitempty"` Error *ErrorDetails `json:"error,omitempty"` GetResult *GetResult `json:"get,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go b/vendor/gopkg.in/olivere/elastic.v6/bulk_delete_request.go similarity index 68% rename from vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go rename to vendor/gopkg.in/olivere/elastic.v6/bulk_delete_request.go index 6a6bfa7fe2..78177ec23a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go +++ b/vendor/gopkg.in/olivere/elastic.v6/bulk_delete_request.go @@ -16,17 +16,19 @@ import ( // BulkDeleteRequest is a request to remove a document from Elasticsearch. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html // for details. type BulkDeleteRequest struct { BulkableRequest - index string - typ string - id string - parent string - routing string - version int64 // default is MATCH_ANY - versionType string // default is "internal" + index string + typ string + id string + parent string + routing string + version int64 // default is MATCH_ANY + versionType string // default is "internal" + ifSeqNo *int64 + ifPrimaryTerm *int64 source []string @@ -38,13 +40,15 @@ type bulkDeleteRequestCommand map[string]bulkDeleteRequestCommandOp //easyjson:json type bulkDeleteRequestCommandOp struct { - Id string `json:"_id,omitempty"` - Index string `json:"_index,omitempty"` - Parent string `json:"_parent,omitempty"` - Routing string `json:"_routing,omitempty"` - Type string `json:"_type,omitempty"` - Version int64 `json:"_version,omitempty"` - VersionType string `json:"_version_type,omitempty"` + Index string `json:"_index,omitempty"` + Type string `json:"_type,omitempty"` + Id string `json:"_id,omitempty"` + Parent string `json:"parent,omitempty"` + Routing string `json:"routing,omitempty"` + Version int64 `json:"version,omitempty"` + VersionType string `json:"version_type,omitempty"` + IfSeqNo *int64 `json:"if_seq_no,omitempty"` + IfPrimaryTerm *int64 `json:"if_primary_term,omitempty"` } // NewBulkDeleteRequest returns a new BulkDeleteRequest. @@ -109,13 +113,27 @@ func (r *BulkDeleteRequest) Version(version int64) *BulkDeleteRequest { } // VersionType can be "internal" (default), "external", "external_gte", -// "external_gt", or "force". +// or "external_gt". func (r *BulkDeleteRequest) VersionType(versionType string) *BulkDeleteRequest { r.versionType = versionType r.source = nil return r } +// IfSeqNo indicates to only perform the delete operation if the last +// operation that has changed the document has the specified sequence number. +func (r *BulkDeleteRequest) IfSeqNo(ifSeqNo int64) *BulkDeleteRequest { + r.ifSeqNo = &ifSeqNo + return r +} + +// IfPrimaryTerm indicates to only perform the delete operation if the +// last operation that has changed the document has the specified primary term. +func (r *BulkDeleteRequest) IfPrimaryTerm(ifPrimaryTerm int64) *BulkDeleteRequest { + r.ifPrimaryTerm = &ifPrimaryTerm + return r +} + // String returns the on-wire representation of the delete request, // concatenated as a single string. func (r *BulkDeleteRequest) String() string { @@ -128,7 +146,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/5.2/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html // for details. func (r *BulkDeleteRequest) Source() ([]string, error) { if r.source != nil { @@ -136,13 +154,15 @@ func (r *BulkDeleteRequest) Source() ([]string, error) { } command := bulkDeleteRequestCommand{ "delete": bulkDeleteRequestCommandOp{ - Index: r.index, - Type: r.typ, - Id: r.id, - Routing: r.routing, - Parent: r.parent, - Version: r.version, - VersionType: r.versionType, + Index: r.index, + Type: r.typ, + Id: r.id, + Routing: r.routing, + Parent: r.parent, + Version: r.version, + VersionType: r.versionType, + IfSeqNo: r.ifSeqNo, + IfPrimaryTerm: r.ifPrimaryTerm, }, } diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request_easyjson.go b/vendor/gopkg.in/olivere/elastic.v6/bulk_delete_request_easyjson.go similarity index 71% rename from vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request_easyjson.go rename to vendor/gopkg.in/olivere/elastic.v6/bulk_delete_request_easyjson.go index 16dc83f7b4..ea71864932 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request_easyjson.go +++ b/vendor/gopkg.in/olivere/elastic.v6/bulk_delete_request_easyjson.go @@ -17,7 +17,7 @@ var ( _ easyjson.Marshaler ) -func easyjson8092efb6DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkDeleteRequestCommandOp) { +func easyjson8092efb6DecodeGithubComOlivereElastic(in *jlexer.Lexer, out *bulkDeleteRequestCommandOp) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -36,20 +36,40 @@ func easyjson8092efb6DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkDe continue } switch key { - case "_id": - out.Id = string(in.String()) case "_index": out.Index = string(in.String()) - case "_parent": - out.Parent = string(in.String()) - case "_routing": - out.Routing = string(in.String()) case "_type": out.Type = string(in.String()) - case "_version": + case "_id": + out.Id = string(in.String()) + case "parent": + out.Parent = string(in.String()) + case "routing": + out.Routing = string(in.String()) + case "version": out.Version = int64(in.Int64()) - case "_version_type": + case "version_type": out.VersionType = string(in.String()) + case "if_seq_no": + if in.IsNull() { + in.Skip() + out.IfSeqNo = nil + } else { + if out.IfSeqNo == nil { + out.IfSeqNo = new(int64) + } + *out.IfSeqNo = int64(in.Int64()) + } + case "if_primary_term": + if in.IsNull() { + in.Skip() + out.IfPrimaryTerm = nil + } else { + if out.IfPrimaryTerm == nil { + out.IfPrimaryTerm = new(int64) + } + *out.IfPrimaryTerm = int64(in.Int64()) + } default: in.SkipRecursive() } @@ -60,20 +80,10 @@ func easyjson8092efb6DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkDe in.Consumed() } } -func easyjson8092efb6EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkDeleteRequestCommandOp) { +func easyjson8092efb6EncodeGithubComOlivereElastic(out *jwriter.Writer, in bulkDeleteRequestCommandOp) { out.RawByte('{') first := true _ = first - if in.Id != "" { - const prefix string = ",\"_id\":" - if first { - first = false - out.RawString(prefix[1:]) - } else { - out.RawString(prefix) - } - out.String(string(in.Id)) - } if in.Index != "" { const prefix string = ",\"_index\":" if first { @@ -84,26 +94,6 @@ func easyjson8092efb6EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkD } out.String(string(in.Index)) } - if in.Parent != "" { - const prefix string = ",\"_parent\":" - if first { - first = false - out.RawString(prefix[1:]) - } else { - out.RawString(prefix) - } - out.String(string(in.Parent)) - } - if in.Routing != "" { - const prefix string = ",\"_routing\":" - if first { - first = false - out.RawString(prefix[1:]) - } else { - out.RawString(prefix) - } - out.String(string(in.Routing)) - } if in.Type != "" { const prefix string = ",\"_type\":" if first { @@ -114,8 +104,38 @@ func easyjson8092efb6EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkD } out.String(string(in.Type)) } + if in.Id != "" { + const prefix string = ",\"_id\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.String(string(in.Id)) + } + if in.Parent != "" { + const prefix string = ",\"parent\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.String(string(in.Parent)) + } + if in.Routing != "" { + const prefix string = ",\"routing\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.String(string(in.Routing)) + } if in.Version != 0 { - const prefix string = ",\"_version\":" + const prefix string = ",\"version\":" if first { first = false out.RawString(prefix[1:]) @@ -125,7 +145,7 @@ func easyjson8092efb6EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkD out.Int64(int64(in.Version)) } if in.VersionType != "" { - const prefix string = ",\"_version_type\":" + const prefix string = ",\"version_type\":" if first { first = false out.RawString(prefix[1:]) @@ -134,33 +154,53 @@ func easyjson8092efb6EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkD } out.String(string(in.VersionType)) } + if in.IfSeqNo != nil { + const prefix string = ",\"if_seq_no\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.Int64(int64(*in.IfSeqNo)) + } + if in.IfPrimaryTerm != nil { + const prefix string = ",\"if_primary_term\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.Int64(int64(*in.IfPrimaryTerm)) + } out.RawByte('}') } // MarshalJSON supports json.Marshaler interface func (v bulkDeleteRequestCommandOp) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson8092efb6EncodeGopkgInOlivereElasticV5(&w, v) + easyjson8092efb6EncodeGithubComOlivereElastic(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v bulkDeleteRequestCommandOp) MarshalEasyJSON(w *jwriter.Writer) { - easyjson8092efb6EncodeGopkgInOlivereElasticV5(w, v) + easyjson8092efb6EncodeGithubComOlivereElastic(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *bulkDeleteRequestCommandOp) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson8092efb6DecodeGopkgInOlivereElasticV5(&r, v) + easyjson8092efb6DecodeGithubComOlivereElastic(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *bulkDeleteRequestCommandOp) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson8092efb6DecodeGopkgInOlivereElasticV5(l, v) + easyjson8092efb6DecodeGithubComOlivereElastic(l, v) } -func easyjson8092efb6DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkDeleteRequestCommand) { +func easyjson8092efb6DecodeGithubComOlivereElastic1(in *jlexer.Lexer, out *bulkDeleteRequestCommand) { isTopLevel := in.IsStart() if in.IsNull() { in.Skip() @@ -185,7 +225,7 @@ func easyjson8092efb6DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkD in.Consumed() } } -func easyjson8092efb6EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulkDeleteRequestCommand) { +func easyjson8092efb6EncodeGithubComOlivereElastic1(out *jwriter.Writer, in bulkDeleteRequestCommand) { if in == nil && (out.Flags&jwriter.NilMapAsEmpty) == 0 { out.RawString(`null`) } else { @@ -208,23 +248,23 @@ func easyjson8092efb6EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulk // MarshalJSON supports json.Marshaler interface func (v bulkDeleteRequestCommand) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson8092efb6EncodeGopkgInOlivereElasticV51(&w, v) + easyjson8092efb6EncodeGithubComOlivereElastic1(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v bulkDeleteRequestCommand) MarshalEasyJSON(w *jwriter.Writer) { - easyjson8092efb6EncodeGopkgInOlivereElasticV51(w, v) + easyjson8092efb6EncodeGithubComOlivereElastic1(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *bulkDeleteRequestCommand) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson8092efb6DecodeGopkgInOlivereElasticV51(&r, v) + easyjson8092efb6DecodeGithubComOlivereElastic1(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *bulkDeleteRequestCommand) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson8092efb6DecodeGopkgInOlivereElasticV51(l, v) + easyjson8092efb6DecodeGithubComOlivereElastic1(l, v) } diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go b/vendor/gopkg.in/olivere/elastic.v6/bulk_index_request.go similarity index 77% rename from vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go rename to vendor/gopkg.in/olivere/elastic.v6/bulk_index_request.go index 70497a0467..07365073e3 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go +++ b/vendor/gopkg.in/olivere/elastic.v6/bulk_index_request.go @@ -14,7 +14,7 @@ import ( // BulkIndexRequest is a request to add a document to Elasticsearch. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html // for details. type BulkIndexRequest struct { BulkableRequest @@ -24,12 +24,13 @@ type BulkIndexRequest struct { opType string routing string parent string - version int64 // default is MATCH_ANY + version *int64 // default is MATCH_ANY versionType string // default is "internal" doc interface{} pipeline string retryOnConflict *int - ttl string + ifSeqNo *int64 + ifPrimaryTerm *int64 source []string @@ -41,16 +42,18 @@ type bulkIndexRequestCommand map[string]bulkIndexRequestCommandOp //easyjson:json type bulkIndexRequestCommandOp struct { - Id string `json:"_id,omitempty"` - Index string `json:"_index,omitempty"` - TTL string `json:"_ttl,omitempty"` - Type string `json:"_type,omitempty"` - Parent string `json:"_parent,omitempty"` - RetryOnConflict *int `json:"_retry_on_conflict,omitempty"` - Routing string `json:"_routing,omitempty"` - Version int64 `json:"_version,omitempty"` - VersionType string `json:"_version_type,omitempty"` + Index string `json:"_index,omitempty"` + Id string `json:"_id,omitempty"` + Type string `json:"_type,omitempty"` + Parent string `json:"parent,omitempty"` + // RetryOnConflict is "_retry_on_conflict" for 6.0 and "retry_on_conflict" for 6.1+. + RetryOnConflict *int `json:"retry_on_conflict,omitempty"` + Routing string `json:"routing,omitempty"` + Version *int64 `json:"version,omitempty"` + VersionType string `json:"version_type,omitempty"` Pipeline string `json:"pipeline,omitempty"` + IfSeqNo *int64 `json:"if_seq_no,omitempty"` + IfPrimaryTerm *int64 `json:"if_primary_term,omitempty"` } // NewBulkIndexRequest returns a new BulkIndexRequest. @@ -96,7 +99,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/5.2/docs-index_.html#operation-type +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-index_.html#operation-type // for details. func (r *BulkIndexRequest) OpType(opType string) *BulkIndexRequest { r.opType = opType @@ -121,7 +124,8 @@ func (r *BulkIndexRequest) Parent(parent string) *BulkIndexRequest { // Version indicates the version of the document as part of an optimistic // concurrency model. func (r *BulkIndexRequest) Version(version int64) *BulkIndexRequest { - r.version = version + v := version + r.version = &v r.source = nil return r } @@ -129,7 +133,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/5.2/docs-index_.html#index-versioning +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-index_.html#index-versioning // for details. func (r *BulkIndexRequest) VersionType(versionType string) *BulkIndexRequest { r.versionType = versionType @@ -151,13 +155,6 @@ func (r *BulkIndexRequest) RetryOnConflict(retryOnConflict int) *BulkIndexReques 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 @@ -165,6 +162,20 @@ func (r *BulkIndexRequest) Pipeline(pipeline string) *BulkIndexRequest { return r } +// IfSeqNo indicates to only perform the index operation if the last +// operation that has changed the document has the specified sequence number. +func (r *BulkIndexRequest) IfSeqNo(ifSeqNo int64) *BulkIndexRequest { + r.ifSeqNo = &ifSeqNo + return r +} + +// IfPrimaryTerm indicates to only perform the index operation if the +// last operation that has changed the document has the specified primary term. +func (r *BulkIndexRequest) IfPrimaryTerm(ifPrimaryTerm int64) *BulkIndexRequest { + r.ifPrimaryTerm = &ifPrimaryTerm + return r +} + // String returns the on-wire representation of the index request, // concatenated as a single string. func (r *BulkIndexRequest) String() string { @@ -177,7 +188,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/5.2/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html // for details. func (r *BulkIndexRequest) Source() ([]string, error) { // { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } } @@ -199,8 +210,9 @@ func (r *BulkIndexRequest) Source() ([]string, error) { Version: r.version, VersionType: r.versionType, RetryOnConflict: r.retryOnConflict, - TTL: r.ttl, Pipeline: r.pipeline, + IfSeqNo: r.ifSeqNo, + IfPrimaryTerm: r.ifPrimaryTerm, } command := bulkIndexRequestCommand{ r.opType: indexCommand, diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request_easyjson.go b/vendor/gopkg.in/olivere/elastic.v6/bulk_index_request_easyjson.go similarity index 72% rename from vendor/gopkg.in/olivere/elastic.v5/bulk_index_request_easyjson.go rename to vendor/gopkg.in/olivere/elastic.v6/bulk_index_request_easyjson.go index 6ee19fbecc..4257e7cd56 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request_easyjson.go +++ b/vendor/gopkg.in/olivere/elastic.v6/bulk_index_request_easyjson.go @@ -17,7 +17,7 @@ var ( _ easyjson.Marshaler ) -func easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkIndexRequestCommandOp) { +func easyjson9de0fcbfDecodeGithubComOlivereElastic(in *jlexer.Lexer, out *bulkIndexRequestCommandOp) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -36,17 +36,15 @@ func easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkIn continue } switch key { - case "_id": - out.Id = string(in.String()) case "_index": out.Index = string(in.String()) - case "_ttl": - out.TTL = string(in.String()) + case "_id": + out.Id = string(in.String()) case "_type": out.Type = string(in.String()) - case "_parent": + case "parent": out.Parent = string(in.String()) - case "_retry_on_conflict": + case "retry_on_conflict": if in.IsNull() { in.Skip() out.RetryOnConflict = nil @@ -56,14 +54,42 @@ func easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkIn } *out.RetryOnConflict = int(in.Int()) } - case "_routing": + case "routing": out.Routing = string(in.String()) - case "_version": - out.Version = int64(in.Int64()) - case "_version_type": + case "version": + if in.IsNull() { + in.Skip() + out.Version = nil + } else { + if out.Version == nil { + out.Version = new(int64) + } + *out.Version = int64(in.Int64()) + } + case "version_type": out.VersionType = string(in.String()) case "pipeline": out.Pipeline = string(in.String()) + case "if_seq_no": + if in.IsNull() { + in.Skip() + out.IfSeqNo = nil + } else { + if out.IfSeqNo == nil { + out.IfSeqNo = new(int64) + } + *out.IfSeqNo = int64(in.Int64()) + } + case "if_primary_term": + if in.IsNull() { + in.Skip() + out.IfPrimaryTerm = nil + } else { + if out.IfPrimaryTerm == nil { + out.IfPrimaryTerm = new(int64) + } + *out.IfPrimaryTerm = int64(in.Int64()) + } default: in.SkipRecursive() } @@ -74,20 +100,10 @@ func easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkIn in.Consumed() } } -func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkIndexRequestCommandOp) { +func easyjson9de0fcbfEncodeGithubComOlivereElastic(out *jwriter.Writer, in bulkIndexRequestCommandOp) { out.RawByte('{') first := true _ = first - if in.Id != "" { - const prefix string = ",\"_id\":" - if first { - first = false - out.RawString(prefix[1:]) - } else { - out.RawString(prefix) - } - out.String(string(in.Id)) - } if in.Index != "" { const prefix string = ",\"_index\":" if first { @@ -98,15 +114,15 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI } out.String(string(in.Index)) } - if in.TTL != "" { - const prefix string = ",\"_ttl\":" + if in.Id != "" { + const prefix string = ",\"_id\":" if first { first = false out.RawString(prefix[1:]) } else { out.RawString(prefix) } - out.String(string(in.TTL)) + out.String(string(in.Id)) } if in.Type != "" { const prefix string = ",\"_type\":" @@ -119,7 +135,7 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI out.String(string(in.Type)) } if in.Parent != "" { - const prefix string = ",\"_parent\":" + const prefix string = ",\"parent\":" if first { first = false out.RawString(prefix[1:]) @@ -129,7 +145,7 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI out.String(string(in.Parent)) } if in.RetryOnConflict != nil { - const prefix string = ",\"_retry_on_conflict\":" + const prefix string = ",\"retry_on_conflict\":" if first { first = false out.RawString(prefix[1:]) @@ -139,7 +155,7 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI out.Int(int(*in.RetryOnConflict)) } if in.Routing != "" { - const prefix string = ",\"_routing\":" + const prefix string = ",\"routing\":" if first { first = false out.RawString(prefix[1:]) @@ -148,18 +164,18 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI } out.String(string(in.Routing)) } - if in.Version != 0 { - const prefix string = ",\"_version\":" + if in.Version != nil { + const prefix string = ",\"version\":" if first { first = false out.RawString(prefix[1:]) } else { out.RawString(prefix) } - out.Int64(int64(in.Version)) + out.Int64(int64(*in.Version)) } if in.VersionType != "" { - const prefix string = ",\"_version_type\":" + const prefix string = ",\"version_type\":" if first { first = false out.RawString(prefix[1:]) @@ -178,33 +194,53 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkI } out.String(string(in.Pipeline)) } + if in.IfSeqNo != nil { + const prefix string = ",\"if_seq_no\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.Int64(int64(*in.IfSeqNo)) + } + if in.IfPrimaryTerm != nil { + const prefix string = ",\"if_primary_term\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.Int64(int64(*in.IfPrimaryTerm)) + } out.RawByte('}') } // MarshalJSON supports json.Marshaler interface func (v bulkIndexRequestCommandOp) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(&w, v) + easyjson9de0fcbfEncodeGithubComOlivereElastic(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v bulkIndexRequestCommandOp) MarshalEasyJSON(w *jwriter.Writer) { - easyjson9de0fcbfEncodeGopkgInOlivereElasticV5(w, v) + easyjson9de0fcbfEncodeGithubComOlivereElastic(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *bulkIndexRequestCommandOp) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(&r, v) + easyjson9de0fcbfDecodeGithubComOlivereElastic(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *bulkIndexRequestCommandOp) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson9de0fcbfDecodeGopkgInOlivereElasticV5(l, v) + easyjson9de0fcbfDecodeGithubComOlivereElastic(l, v) } -func easyjson9de0fcbfDecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkIndexRequestCommand) { +func easyjson9de0fcbfDecodeGithubComOlivereElastic1(in *jlexer.Lexer, out *bulkIndexRequestCommand) { isTopLevel := in.IsStart() if in.IsNull() { in.Skip() @@ -229,7 +265,7 @@ func easyjson9de0fcbfDecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkI in.Consumed() } } -func easyjson9de0fcbfEncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulkIndexRequestCommand) { +func easyjson9de0fcbfEncodeGithubComOlivereElastic1(out *jwriter.Writer, in bulkIndexRequestCommand) { if in == nil && (out.Flags&jwriter.NilMapAsEmpty) == 0 { out.RawString(`null`) } else { @@ -252,23 +288,23 @@ func easyjson9de0fcbfEncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulk // MarshalJSON supports json.Marshaler interface func (v bulkIndexRequestCommand) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson9de0fcbfEncodeGopkgInOlivereElasticV51(&w, v) + easyjson9de0fcbfEncodeGithubComOlivereElastic1(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v bulkIndexRequestCommand) MarshalEasyJSON(w *jwriter.Writer) { - easyjson9de0fcbfEncodeGopkgInOlivereElasticV51(w, v) + easyjson9de0fcbfEncodeGithubComOlivereElastic1(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *bulkIndexRequestCommand) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson9de0fcbfDecodeGopkgInOlivereElasticV51(&r, v) + easyjson9de0fcbfDecodeGithubComOlivereElastic1(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *bulkIndexRequestCommand) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson9de0fcbfDecodeGopkgInOlivereElasticV51(l, v) + easyjson9de0fcbfDecodeGithubComOlivereElastic1(l, v) } diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_processor.go b/vendor/gopkg.in/olivere/elastic.v6/bulk_processor.go similarity index 78% rename from vendor/gopkg.in/olivere/elastic.v5/bulk_processor.go rename to vendor/gopkg.in/olivere/elastic.v6/bulk_processor.go index 1b92634024..f2711f829d 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/bulk_processor.go +++ b/vendor/gopkg.in/olivere/elastic.v6/bulk_processor.go @@ -6,12 +6,21 @@ package elastic import ( "context" + "errors" "net" "sync" "sync/atomic" "time" ) +var ( + // ErrBulkItemRetry is returned in BulkProcessor from a worker when + // a response item needs to be retried. + ErrBulkItemRetry = errors.New("elastic: uncommitted bulk response items") + + defaultRetryItemStatusCodes = []int{408, 429, 503, 507} +) + // BulkProcessorService allows to easily process bulk requests. It allows setting // policies when to flush new bulk requests, e.g. based on a number of actions, // on the size of the actions, and/or to flush periodically. It also allows @@ -21,7 +30,9 @@ import ( // BulkProcessorService, by default, commits either every 1000 requests or when the // (estimated) size of the bulk requests exceeds 5 MB. However, it does not // commit periodically. BulkProcessorService also does retry by default, using -// an exponential backoff algorithm. +// an exponential backoff algorithm. It also will automatically re-enqueue items +// returned with a status of 408, 429, 503 or 507. You can change this +// behavior with RetryItemStatusCodes. // // The caller is responsible for setting the index and type on every // bulk request added to BulkProcessorService. @@ -30,16 +41,17 @@ import ( // Elasticsearch Java API as documented in // https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-bulk-processor.html. type BulkProcessorService struct { - c *Client - beforeFn BulkBeforeFunc - afterFn BulkAfterFunc - name string // name of processor - numWorkers int // # of workers (>= 1) - bulkActions int // # of requests after which to commit - bulkSize int // # of bytes after which to commit - flushInterval time.Duration // periodic flush interval - wantStats bool // indicates whether to gather statistics - backoff Backoff // a custom Backoff to use for errors + c *Client + beforeFn BulkBeforeFunc + afterFn BulkAfterFunc + name string // name of processor + numWorkers int // # of workers (>= 1) + bulkActions int // # of requests after which to commit + bulkSize int // # of bytes after which to commit + flushInterval time.Duration // periodic flush interval + wantStats bool // indicates whether to gather statistics + backoff Backoff // a custom Backoff to use for errors + retryItemStatusCodes []int // array of status codes for bulk response line items that may be retried } // NewBulkProcessorService creates a new BulkProcessorService. @@ -53,6 +65,7 @@ func NewBulkProcessorService(client *Client) *BulkProcessorService { time.Duration(200)*time.Millisecond, time.Duration(10000)*time.Millisecond, ), + retryItemStatusCodes: defaultRetryItemStatusCodes, } } @@ -64,7 +77,7 @@ type BulkBeforeFunc func(executionId int64, requests []BulkableRequest) // after a commit to Elasticsearch. The err parameter signals an error. type BulkAfterFunc func(executionId int64, requests []BulkableRequest, response *BulkResponse, err error) -// Before specifies a function to be executed before bulk requests get comitted +// Before specifies a function to be executed before bulk requests get committed // to Elasticsearch. func (s *BulkProcessorService) Before(fn BulkBeforeFunc) *BulkProcessorService { s.beforeFn = fn @@ -72,7 +85,7 @@ func (s *BulkProcessorService) Before(fn BulkBeforeFunc) *BulkProcessorService { } // After specifies a function to be executed when bulk requests have been -// comitted to Elasticsearch. The After callback executes both when the +// committed to Elasticsearch. The After callback executes both when the // commit was successful as well as on failures. func (s *BulkProcessorService) After(fn BulkAfterFunc) *BulkProcessorService { s.afterFn = fn @@ -122,12 +135,19 @@ func (s *BulkProcessorService) Stats(wantStats bool) *BulkProcessorService { return s } -// Backoff sets the backoff strategy to use for errors +// Backoff sets the backoff strategy to use for errors. func (s *BulkProcessorService) Backoff(backoff Backoff) *BulkProcessorService { s.backoff = backoff return s } +// RetryItemStatusCodes sets an array of status codes that indicate that a bulk +// response line item should be retried. +func (s *BulkProcessorService) RetryItemStatusCodes(retryItemStatusCodes ...int) *BulkProcessorService { + s.retryItemStatusCodes = retryItemStatusCodes + return s +} + // Do creates a new BulkProcessor and starts it. // Consider the BulkProcessor as a running instance that accepts bulk requests // and commits them to Elasticsearch, spreading the work across one or more @@ -144,6 +164,12 @@ func (s *BulkProcessorService) Backoff(backoff Backoff) *BulkProcessorService { // 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(ctx context.Context) (*BulkProcessor, error) { + + retryItemStatusCodes := make(map[int]struct{}) + for _, code := range s.retryItemStatusCodes { + retryItemStatusCodes[code] = struct{}{} + } + p := newBulkProcessor( s.c, s.beforeFn, @@ -154,7 +180,8 @@ func (s *BulkProcessorService) Do(ctx context.Context) (*BulkProcessor, error) { s.bulkSize, s.flushInterval, s.wantStats, - s.backoff) + s.backoff, + retryItemStatusCodes) err := p.Start(ctx) if err != nil { @@ -228,21 +255,22 @@ func (st *BulkProcessorWorkerStats) dup() *BulkProcessorWorkerStats { // BulkProcessor is returned by setting up a BulkProcessorService and // calling the Do method. type BulkProcessor struct { - c *Client - beforeFn BulkBeforeFunc - afterFn BulkAfterFunc - name string - bulkActions int - bulkSize int - numWorkers int - executionId int64 - requestsC chan BulkableRequest - workerWg sync.WaitGroup - workers []*bulkWorker - flushInterval time.Duration - flusherStopC chan struct{} - wantStats bool - backoff Backoff + c *Client + beforeFn BulkBeforeFunc + afterFn BulkAfterFunc + name string + bulkActions int + bulkSize int + numWorkers int + executionId int64 + requestsC chan BulkableRequest + workerWg sync.WaitGroup + workers []*bulkWorker + flushInterval time.Duration + flusherStopC chan struct{} + wantStats bool + retryItemStatusCodes map[int]struct{} + backoff Backoff startedMu sync.Mutex // guards the following block started bool @@ -263,18 +291,20 @@ func newBulkProcessor( bulkSize int, flushInterval time.Duration, wantStats bool, - backoff Backoff) *BulkProcessor { + backoff Backoff, + retryItemStatusCodes map[int]struct{}) *BulkProcessor { return &BulkProcessor{ - c: client, - beforeFn: beforeFn, - afterFn: afterFn, - name: name, - numWorkers: numWorkers, - bulkActions: bulkActions, - bulkSize: bulkSize, - flushInterval: flushInterval, - wantStats: wantStats, - backoff: backoff, + c: client, + beforeFn: beforeFn, + afterFn: afterFn, + name: name, + numWorkers: numWorkers, + bulkActions: bulkActions, + bulkSize: bulkSize, + flushInterval: flushInterval, + wantStats: wantStats, + retryItemStatusCodes: retryItemStatusCodes, + backoff: backoff, } } @@ -451,9 +481,11 @@ func (w *bulkWorker) work(ctx context.Context) { case req, open := <-w.p.requestsC: if open { // Received a new request - w.service.Add(req) - if w.commitRequired() { - err = w.commit(ctx) + if _, err = req.Source(); err == nil { + w.service.Add(req) + if w.commitRequired() { + err = w.commit(ctx) + } } } else { // Channel closed: Stop. @@ -462,6 +494,7 @@ func (w *bulkWorker) work(ctx context.Context) { err = w.commit(ctx) } } + case <-w.flushC: // Commit outstanding requests if w.service.NumberOfActions() > 0 { @@ -469,17 +502,20 @@ func (w *bulkWorker) work(ctx context.Context) { } w.flushAckC <- struct{}{} } - if !stop && err != nil { - waitForActive := func() { - // Add back pressure to prevent Add calls from filling up the request queue - ready := make(chan struct{}) - go w.waitForActiveConnection(ready) - <-ready - } - if _, ok := err.(net.Error); ok { - waitForActive() - } else if IsConnErr(err) { - waitForActive() + if err != nil { + w.p.c.errorf("elastic: bulk processor %q was unable to perform work: %v", w.p.name, err) + if !stop { + waitForActive := func() { + // Add back pressure to prevent Add calls from filling up the request queue + ready := make(chan struct{}) + go w.waitForActiveConnection(ready) + <-ready + } + if _, ok := err.(net.Error); ok { + waitForActive() + } else if IsConnErr(err) { + waitForActive() + } } } } @@ -494,7 +530,28 @@ func (w *bulkWorker) commit(ctx context.Context) error { // via exponential backoff commitFunc := func() error { var err error + // Save requests because they will be reset in service.Do + reqs := w.service.requests res, err = w.service.Do(ctx) + if err == nil { + // Overall bulk request was OK. But each bulk response item also has a status + if w.p.retryItemStatusCodes != nil && len(w.p.retryItemStatusCodes) > 0 { + // Check res.Items since some might be soft failures + if res.Items != nil && res.Errors { + // res.Items will be 1 to 1 with reqs in same order + for i, item := range res.Items { + for _, result := range item { + if _, found := w.p.retryItemStatusCodes[result.Status]; found { + w.service.Add(reqs[i]) + if err == nil { + err = ErrBulkItemRetry + } + } + } + } + } + } + } return err } // notifyFunc will be called if retry fails @@ -553,7 +610,7 @@ func (w *bulkWorker) waitForActiveConnection(ready chan<- struct{}) { return } case <-t.C: - client.healthcheck(time.Duration(3)*time.Second, true) + client.healthcheck(context.Background(), 3*time.Second, true) if client.mustActiveConn() == nil { // found an active connection // exit and signal done to the WaitGroup diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_request.go b/vendor/gopkg.in/olivere/elastic.v6/bulk_request.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/bulk_request.go rename to vendor/gopkg.in/olivere/elastic.v6/bulk_request.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request.go b/vendor/gopkg.in/olivere/elastic.v6/bulk_update_request.go similarity index 77% rename from vendor/gopkg.in/olivere/elastic.v5/bulk_update_request.go rename to vendor/gopkg.in/olivere/elastic.v6/bulk_update_request.go index bd05211b1b..c5ef0801bc 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request.go +++ b/vendor/gopkg.in/olivere/elastic.v6/bulk_update_request.go @@ -14,7 +14,7 @@ import ( // BulkUpdateRequest is a request to update a document in Elasticsearch. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html // for details. type BulkUpdateRequest struct { BulkableRequest @@ -34,6 +34,8 @@ type BulkUpdateRequest struct { detectNoop *bool doc interface{} returnSource *bool + ifSeqNo *int64 + ifPrimaryTerm *int64 source []string @@ -45,14 +47,17 @@ type bulkUpdateRequestCommand map[string]bulkUpdateRequestCommandOp //easyjson:json type bulkUpdateRequestCommandOp struct { - Id string `json:"_id,omitempty"` - Index string `json:"_index,omitempty"` - Type string `json:"_type,omitempty"` - Parent string `json:"_parent,omitempty"` - RetryOnConflict *int `json:"_retry_on_conflict,omitempty"` - Routing string `json:"_routing,omitempty"` - Version int64 `json:"_version,omitempty"` - VersionType string `json:"_version_type,omitempty"` + Index string `json:"_index,omitempty"` + Type string `json:"_type,omitempty"` + Id string `json:"_id,omitempty"` + Parent string `json:"parent,omitempty"` + // RetryOnConflict is "_retry_on_conflict" for 6.0 and "retry_on_conflict" for 6.1+. + RetryOnConflict *int `json:"retry_on_conflict,omitempty"` + Routing string `json:"routing,omitempty"` + Version int64 `json:"version,omitempty"` + VersionType string `json:"version_type,omitempty"` + IfSeqNo *int64 `json:"if_seq_no,omitempty"` + IfPrimaryTerm *int64 `json:"if_primary_term,omitempty"` } //easyjson:json @@ -60,9 +65,9 @@ type bulkUpdateRequestCommandData struct { DetectNoop *bool `json:"detect_noop,omitempty"` Doc interface{} `json:"doc,omitempty"` DocAsUpsert *bool `json:"doc_as_upsert,omitempty"` - Upsert interface{} `json:"upsert,omitempty"` Script interface{} `json:"script,omitempty"` ScriptedUpsert *bool `json:"scripted_upsert,omitempty"` + Upsert interface{} `json:"upsert,omitempty"` Source *bool `json:"_source,omitempty"` } @@ -119,8 +124,8 @@ func (r *BulkUpdateRequest) Parent(parent string) *BulkUpdateRequest { } // Script specifies an update script. -// 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 +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html#bulk-update +// and https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting.html // for details. func (r *BulkUpdateRequest) Script(script *Script) *BulkUpdateRequest { r.script = script @@ -131,7 +136,7 @@ func (r *BulkUpdateRequest) Script(script *Script) *BulkUpdateRequest { // 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 +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update.html#_literal_scripted_upsert_literal func (r *BulkUpdateRequest) ScriptedUpsert(upsert bool) *BulkUpdateRequest { r.scriptedUpsert = &upsert r.source = nil @@ -154,13 +159,27 @@ func (r *BulkUpdateRequest) Version(version int64) *BulkUpdateRequest { } // VersionType can be "internal" (default), "external", "external_gte", -// "external_gt", or "force". +// or "external_gt". func (r *BulkUpdateRequest) VersionType(versionType string) *BulkUpdateRequest { r.versionType = versionType r.source = nil return r } +// IfSeqNo indicates to only perform the index operation if the last +// operation that has changed the document has the specified sequence number. +func (r *BulkUpdateRequest) IfSeqNo(ifSeqNo int64) *BulkUpdateRequest { + r.ifSeqNo = &ifSeqNo + return r +} + +// IfPrimaryTerm indicates to only perform the index operation if the +// last operation that has changed the document has the specified primary term. +func (r *BulkUpdateRequest) IfPrimaryTerm(ifPrimaryTerm int64) *BulkUpdateRequest { + r.ifPrimaryTerm = &ifPrimaryTerm + return r +} + // Doc specifies the updated document. func (r *BulkUpdateRequest) Doc(doc interface{}) *BulkUpdateRequest { r.doc = doc @@ -171,7 +190,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/5.2/docs-update.html#_literal_doc_as_upsert_literal +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update.html#_literal_doc_as_upsert_literal // for details. func (r *BulkUpdateRequest) DocAsUpsert(docAsUpsert bool) *BulkUpdateRequest { r.docAsUpsert = &docAsUpsert @@ -217,7 +236,7 @@ func (r *BulkUpdateRequest) String() string { // 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/5.2/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html // for details. func (r *BulkUpdateRequest) Source() ([]string, error) { // { "update" : { "_index" : "test", "_type" : "type1", "_id" : "1", ... } } @@ -242,6 +261,8 @@ func (r *BulkUpdateRequest) Source() ([]string, error) { Version: r.version, VersionType: r.versionType, RetryOnConflict: r.retryOnConflict, + IfSeqNo: r.ifSeqNo, + IfPrimaryTerm: r.ifPrimaryTerm, } command := bulkUpdateRequestCommand{ "update": updateCommand, @@ -263,12 +284,28 @@ func (r *BulkUpdateRequest) Source() ([]string, error) { lines[0] = string(body) // 2nd line: {"doc" : { ... }} or {"script": {...}} + var doc interface{} + if r.doc != nil { + // Automatically serialize strings as raw JSON + switch t := r.doc.(type) { + default: + doc = r.doc + case string: + if len(t) > 0 { + doc = json.RawMessage(t) + } + case *string: + if t != nil && len(*t) > 0 { + doc = json.RawMessage(*t) + } + } + } data := bulkUpdateRequestCommandData{ DocAsUpsert: r.docAsUpsert, DetectNoop: r.detectNoop, Upsert: r.upsert, ScriptedUpsert: r.scriptedUpsert, - Doc: r.doc, + Doc: doc, Source: r.returnSource, } if r.script != nil { diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request_easyjson.go b/vendor/gopkg.in/olivere/elastic.v6/bulk_update_request_easyjson.go similarity index 81% rename from vendor/gopkg.in/olivere/elastic.v5/bulk_update_request_easyjson.go rename to vendor/gopkg.in/olivere/elastic.v6/bulk_update_request_easyjson.go index 1edd4c1278..cfc2593513 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/bulk_update_request_easyjson.go +++ b/vendor/gopkg.in/olivere/elastic.v6/bulk_update_request_easyjson.go @@ -17,7 +17,7 @@ var ( _ easyjson.Marshaler ) -func easyjson1ed00e60DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkUpdateRequestCommandOp) { +func easyjson1ed00e60DecodeGithubComOlivereElastic(in *jlexer.Lexer, out *bulkUpdateRequestCommandOp) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -36,15 +36,15 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkUp continue } switch key { - case "_id": - out.Id = string(in.String()) case "_index": out.Index = string(in.String()) case "_type": out.Type = string(in.String()) - case "_parent": + case "_id": + out.Id = string(in.String()) + case "parent": out.Parent = string(in.String()) - case "_retry_on_conflict": + case "retry_on_conflict": if in.IsNull() { in.Skip() out.RetryOnConflict = nil @@ -54,12 +54,32 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkUp } *out.RetryOnConflict = int(in.Int()) } - case "_routing": + case "routing": out.Routing = string(in.String()) - case "_version": + case "version": out.Version = int64(in.Int64()) - case "_version_type": + case "version_type": out.VersionType = string(in.String()) + case "if_seq_no": + if in.IsNull() { + in.Skip() + out.IfSeqNo = nil + } else { + if out.IfSeqNo == nil { + out.IfSeqNo = new(int64) + } + *out.IfSeqNo = int64(in.Int64()) + } + case "if_primary_term": + if in.IsNull() { + in.Skip() + out.IfPrimaryTerm = nil + } else { + if out.IfPrimaryTerm == nil { + out.IfPrimaryTerm = new(int64) + } + *out.IfPrimaryTerm = int64(in.Int64()) + } default: in.SkipRecursive() } @@ -70,20 +90,10 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV5(in *jlexer.Lexer, out *bulkUp in.Consumed() } } -func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkUpdateRequestCommandOp) { +func easyjson1ed00e60EncodeGithubComOlivereElastic(out *jwriter.Writer, in bulkUpdateRequestCommandOp) { out.RawByte('{') first := true _ = first - if in.Id != "" { - const prefix string = ",\"_id\":" - if first { - first = false - out.RawString(prefix[1:]) - } else { - out.RawString(prefix) - } - out.String(string(in.Id)) - } if in.Index != "" { const prefix string = ",\"_index\":" if first { @@ -104,8 +114,18 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU } out.String(string(in.Type)) } + if in.Id != "" { + const prefix string = ",\"_id\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.String(string(in.Id)) + } if in.Parent != "" { - const prefix string = ",\"_parent\":" + const prefix string = ",\"parent\":" if first { first = false out.RawString(prefix[1:]) @@ -115,7 +135,7 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU out.String(string(in.Parent)) } if in.RetryOnConflict != nil { - const prefix string = ",\"_retry_on_conflict\":" + const prefix string = ",\"retry_on_conflict\":" if first { first = false out.RawString(prefix[1:]) @@ -125,7 +145,7 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU out.Int(int(*in.RetryOnConflict)) } if in.Routing != "" { - const prefix string = ",\"_routing\":" + const prefix string = ",\"routing\":" if first { first = false out.RawString(prefix[1:]) @@ -135,7 +155,7 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU out.String(string(in.Routing)) } if in.Version != 0 { - const prefix string = ",\"_version\":" + const prefix string = ",\"version\":" if first { first = false out.RawString(prefix[1:]) @@ -145,7 +165,7 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU out.Int64(int64(in.Version)) } if in.VersionType != "" { - const prefix string = ",\"_version_type\":" + const prefix string = ",\"version_type\":" if first { first = false out.RawString(prefix[1:]) @@ -154,33 +174,53 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV5(out *jwriter.Writer, in bulkU } out.String(string(in.VersionType)) } + if in.IfSeqNo != nil { + const prefix string = ",\"if_seq_no\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.Int64(int64(*in.IfSeqNo)) + } + if in.IfPrimaryTerm != nil { + const prefix string = ",\"if_primary_term\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.Int64(int64(*in.IfPrimaryTerm)) + } out.RawByte('}') } // MarshalJSON supports json.Marshaler interface func (v bulkUpdateRequestCommandOp) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson1ed00e60EncodeGopkgInOlivereElasticV5(&w, v) + easyjson1ed00e60EncodeGithubComOlivereElastic(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v bulkUpdateRequestCommandOp) MarshalEasyJSON(w *jwriter.Writer) { - easyjson1ed00e60EncodeGopkgInOlivereElasticV5(w, v) + easyjson1ed00e60EncodeGithubComOlivereElastic(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *bulkUpdateRequestCommandOp) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson1ed00e60DecodeGopkgInOlivereElasticV5(&r, v) + easyjson1ed00e60DecodeGithubComOlivereElastic(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *bulkUpdateRequestCommandOp) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson1ed00e60DecodeGopkgInOlivereElasticV5(l, v) + easyjson1ed00e60DecodeGithubComOlivereElastic(l, v) } -func easyjson1ed00e60DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkUpdateRequestCommandData) { +func easyjson1ed00e60DecodeGithubComOlivereElastic1(in *jlexer.Lexer, out *bulkUpdateRequestCommandData) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -227,14 +267,6 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkU } *out.DocAsUpsert = bool(in.Bool()) } - case "upsert": - if m, ok := out.Upsert.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Upsert.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Upsert = in.Interface() - } case "script": if m, ok := out.Script.(easyjson.Unmarshaler); ok { m.UnmarshalEasyJSON(in) @@ -253,6 +285,14 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkU } *out.ScriptedUpsert = bool(in.Bool()) } + case "upsert": + if m, ok := out.Upsert.(easyjson.Unmarshaler); ok { + m.UnmarshalEasyJSON(in) + } else if m, ok := out.Upsert.(json.Unmarshaler); ok { + _ = m.UnmarshalJSON(in.Raw()) + } else { + out.Upsert = in.Interface() + } case "_source": if in.IsNull() { in.Skip() @@ -273,7 +313,7 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV51(in *jlexer.Lexer, out *bulkU in.Consumed() } } -func easyjson1ed00e60EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulkUpdateRequestCommandData) { +func easyjson1ed00e60EncodeGithubComOlivereElastic1(out *jwriter.Writer, in bulkUpdateRequestCommandData) { out.RawByte('{') first := true _ = first @@ -313,22 +353,6 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulk } out.Bool(bool(*in.DocAsUpsert)) } - if in.Upsert != nil { - const prefix string = ",\"upsert\":" - if first { - first = false - out.RawString(prefix[1:]) - } else { - out.RawString(prefix) - } - if m, ok := in.Upsert.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Upsert.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Upsert)) - } - } if in.Script != nil { const prefix string = ",\"script\":" if first { @@ -355,6 +379,22 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulk } out.Bool(bool(*in.ScriptedUpsert)) } + if in.Upsert != nil { + const prefix string = ",\"upsert\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + if m, ok := in.Upsert.(easyjson.Marshaler); ok { + m.MarshalEasyJSON(out) + } else if m, ok := in.Upsert.(json.Marshaler); ok { + out.Raw(m.MarshalJSON()) + } else { + out.Raw(json.Marshal(in.Upsert)) + } + } if in.Source != nil { const prefix string = ",\"_source\":" if first { @@ -371,27 +411,27 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV51(out *jwriter.Writer, in bulk // MarshalJSON supports json.Marshaler interface func (v bulkUpdateRequestCommandData) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson1ed00e60EncodeGopkgInOlivereElasticV51(&w, v) + easyjson1ed00e60EncodeGithubComOlivereElastic1(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v bulkUpdateRequestCommandData) MarshalEasyJSON(w *jwriter.Writer) { - easyjson1ed00e60EncodeGopkgInOlivereElasticV51(w, v) + easyjson1ed00e60EncodeGithubComOlivereElastic1(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *bulkUpdateRequestCommandData) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson1ed00e60DecodeGopkgInOlivereElasticV51(&r, v) + easyjson1ed00e60DecodeGithubComOlivereElastic1(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *bulkUpdateRequestCommandData) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson1ed00e60DecodeGopkgInOlivereElasticV51(l, v) + easyjson1ed00e60DecodeGithubComOlivereElastic1(l, v) } -func easyjson1ed00e60DecodeGopkgInOlivereElasticV52(in *jlexer.Lexer, out *bulkUpdateRequestCommand) { +func easyjson1ed00e60DecodeGithubComOlivereElastic2(in *jlexer.Lexer, out *bulkUpdateRequestCommand) { isTopLevel := in.IsStart() if in.IsNull() { in.Skip() @@ -416,7 +456,7 @@ func easyjson1ed00e60DecodeGopkgInOlivereElasticV52(in *jlexer.Lexer, out *bulkU in.Consumed() } } -func easyjson1ed00e60EncodeGopkgInOlivereElasticV52(out *jwriter.Writer, in bulkUpdateRequestCommand) { +func easyjson1ed00e60EncodeGithubComOlivereElastic2(out *jwriter.Writer, in bulkUpdateRequestCommand) { if in == nil && (out.Flags&jwriter.NilMapAsEmpty) == 0 { out.RawString(`null`) } else { @@ -439,23 +479,23 @@ func easyjson1ed00e60EncodeGopkgInOlivereElasticV52(out *jwriter.Writer, in bulk // MarshalJSON supports json.Marshaler interface func (v bulkUpdateRequestCommand) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson1ed00e60EncodeGopkgInOlivereElasticV52(&w, v) + easyjson1ed00e60EncodeGithubComOlivereElastic2(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v bulkUpdateRequestCommand) MarshalEasyJSON(w *jwriter.Writer) { - easyjson1ed00e60EncodeGopkgInOlivereElasticV52(w, v) + easyjson1ed00e60EncodeGithubComOlivereElastic2(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *bulkUpdateRequestCommand) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson1ed00e60DecodeGopkgInOlivereElasticV52(&r, v) + easyjson1ed00e60DecodeGithubComOlivereElastic2(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *bulkUpdateRequestCommand) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson1ed00e60DecodeGopkgInOlivereElasticV52(l, v) + easyjson1ed00e60DecodeGithubComOlivereElastic2(l, v) } diff --git a/vendor/gopkg.in/olivere/elastic.v5/canonicalize.go b/vendor/gopkg.in/olivere/elastic.v6/canonicalize.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/canonicalize.go rename to vendor/gopkg.in/olivere/elastic.v6/canonicalize.go diff --git a/vendor/gopkg.in/olivere/elastic.v6/cat_aliases.go b/vendor/gopkg.in/olivere/elastic.v6/cat_aliases.go new file mode 100644 index 0000000000..160ad6b571 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/cat_aliases.go @@ -0,0 +1,169 @@ +// 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 ( + "context" + "fmt" + "net/url" + "strings" + + "github.com/olivere/elastic/uritemplates" +) + +// CatAliasesService shows information about currently configured aliases +// to indices including filter and routing infos. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cat-aliases.html +// for details. +type CatAliasesService struct { + client *Client + pretty bool + local *bool + masterTimeout string + aliases []string + columns []string + sort []string // list of columns for sort order +} + +// NewCatAliasesService creates a new CatAliasesService. +func NewCatAliasesService(client *Client) *CatAliasesService { + return &CatAliasesService{ + client: client, + } +} + +// Alias specifies one or more aliases to which information should be returned. +func (s *CatAliasesService) Alias(alias ...string) *CatAliasesService { + s.aliases = alias + return s +} + +// Local indicates to return local information, i.e. do not retrieve +// the state from master node (default: false). +func (s *CatAliasesService) Local(local bool) *CatAliasesService { + s.local = &local + return s +} + +// MasterTimeout is the explicit operation timeout for connection to master node. +func (s *CatAliasesService) MasterTimeout(masterTimeout string) *CatAliasesService { + s.masterTimeout = masterTimeout + return s +} + +// Columns to return in the response. +// To get a list of all possible columns to return, run the following command +// in your terminal: +// +// Example: +// curl 'http://localhost:9200/_cat/aliases?help' +// +// You can use Columns("*") to return all possible columns. That might take +// a little longer than the default set of columns. +func (s *CatAliasesService) Columns(columns ...string) *CatAliasesService { + s.columns = columns + return s +} + +// Sort is a list of fields to sort by. +func (s *CatAliasesService) Sort(fields ...string) *CatAliasesService { + s.sort = fields + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *CatAliasesService) Pretty(pretty bool) *CatAliasesService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *CatAliasesService) buildURL() (string, url.Values, error) { + // Build URL + var ( + path string + err error + ) + + if len(s.aliases) > 0 { + path, err = uritemplates.Expand("/_cat/aliases/{name}", map[string]string{ + "name": strings.Join(s.aliases, ","), + }) + } else { + path = "/_cat/aliases" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{ + "format": []string{"json"}, // always returns as JSON + } + if s.pretty { + params.Set("pretty", "true") + } + if v := s.local; v != nil { + params.Set("local", fmt.Sprint(*v)) + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if len(s.sort) > 0 { + params.Set("s", strings.Join(s.sort, ",")) + } + if len(s.columns) > 0 { + params.Set("h", strings.Join(s.columns, ",")) + } + return path, params, nil +} + +// Do executes the operation. +func (s *CatAliasesService) Do(ctx context.Context) (CatAliasesResponse, error) { + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + var ret CatAliasesResponse + if err := s.client.decoder.Decode(res.Body, &ret); err != nil { + return nil, err + } + return ret, nil +} + +// -- Result of a get request. + +// CatAliasesResponse is the outcome of CatAliasesService.Do. +type CatAliasesResponse []CatAliasesResponseRow + +// CatAliasesResponseRow is a single row in a CatAliasesResponse. +// Notice that not all of these fields might be filled; that depends +// on the number of columns chose in the request (see CatAliasesService.Columns). +type CatAliasesResponseRow struct { + // Alias name. + Alias string `json:"alias"` + // Index the alias points to. + Index string `json:"index"` + // Filter, e.g. "*" or "-". + Filter string `json:"filter"` + // RoutingIndex specifies the index routing (or "-"). + RoutingIndex string `json:"routing.index"` + // RoutingSearch specifies the search routing (or "-"). + RoutingSearch string `json:"routing.search"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/cat_allocation.go b/vendor/gopkg.in/olivere/elastic.v6/cat_allocation.go new file mode 100644 index 0000000000..5bccd86336 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/cat_allocation.go @@ -0,0 +1,188 @@ +// 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 ( + "context" + "fmt" + "net/url" + "strings" + + "github.com/olivere/elastic/uritemplates" +) + +// CatAllocationService provides a snapshot of how many shards are allocated +// to each data node and how much disk space they are using. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cat-allocation.html +// for details. +type CatAllocationService struct { + client *Client + pretty bool + bytes string // b, k, m, or g + local *bool + masterTimeout string + nodes []string + columns []string + sort []string // list of columns for sort order +} + +// NewCatAllocationService creates a new CatAllocationService. +func NewCatAllocationService(client *Client) *CatAllocationService { + return &CatAllocationService{ + client: client, + } +} + +// NodeID specifies one or more node IDs to for information should be returned. +func (s *CatAllocationService) NodeID(nodes ...string) *CatAllocationService { + s.nodes = nodes + return s +} + +// Bytes represents the unit in which to display byte values. +// Valid values are: "b", "k", "m", or "g". +func (s *CatAllocationService) Bytes(bytes string) *CatAllocationService { + s.bytes = bytes + return s +} + +// Local indicates to return local information, i.e. do not retrieve +// the state from master node (default: false). +func (s *CatAllocationService) Local(local bool) *CatAllocationService { + s.local = &local + return s +} + +// MasterTimeout is the explicit operation timeout for connection to master node. +func (s *CatAllocationService) MasterTimeout(masterTimeout string) *CatAllocationService { + s.masterTimeout = masterTimeout + return s +} + +// Columns to return in the response. +// To get a list of all possible columns to return, run the following command +// in your terminal: +// +// Example: +// curl 'http://localhost:9200/_cat/aliases?help' +// +// You can use Columns("*") to return all possible columns. That might take +// a little longer than the default set of columns. +func (s *CatAllocationService) Columns(columns ...string) *CatAllocationService { + s.columns = columns + return s +} + +// Sort is a list of fields to sort by. +func (s *CatAllocationService) Sort(fields ...string) *CatAllocationService { + s.sort = fields + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *CatAllocationService) Pretty(pretty bool) *CatAllocationService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *CatAllocationService) buildURL() (string, url.Values, error) { + // Build URL + var ( + path string + err error + ) + + if len(s.nodes) > 0 { + path, err = uritemplates.Expand("/_cat/allocation/{node_id}", map[string]string{ + "node_id": strings.Join(s.nodes, ","), + }) + } else { + path = "/_cat/allocation" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{ + "format": []string{"json"}, // always returns as JSON + } + if s.pretty { + params.Set("pretty", "true") + } + if s.bytes != "" { + params.Set("bytes", s.bytes) + } + if v := s.local; v != nil { + params.Set("local", fmt.Sprint(*v)) + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if len(s.sort) > 0 { + params.Set("s", strings.Join(s.sort, ",")) + } + if len(s.columns) > 0 { + params.Set("h", strings.Join(s.columns, ",")) + } + return path, params, nil +} + +// Do executes the operation. +func (s *CatAllocationService) Do(ctx context.Context) (CatAllocationResponse, error) { + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + var ret CatAllocationResponse + if err := s.client.decoder.Decode(res.Body, &ret); err != nil { + return nil, err + } + return ret, nil +} + +// -- Result of a get request. + +// CatAllocationResponse is the outcome of CatAllocationService.Do. +type CatAllocationResponse []CatAllocationResponseRow + +// CatAllocationResponseRow is a single row in a CatAllocationResponse. +// Notice that not all of these fields might be filled; that depends +// on the number of columns chose in the request (see CatAllocationService.Columns). +type CatAllocationResponseRow struct { + // Shards represents the number of shards on a node. + Shards int `json:"shards,string"` + // DiskIndices represents the disk used by ES indices, e.g. "46.1kb". + DiskIndices string `json:"disk.indices"` + // DiskUsed represents the disk used (total, not just ES), e.g. "34.5gb" + DiskUsed string `json:"disk.used"` + // DiskAvail represents the disk available, e.g. "53.2gb". + DiskAvail string `json:"disk.avail"` + // DiskTotal represents the total capacity of all volumes, e.g. "87.7gb". + DiskTotal string `json:"disk.total"` + // DiskPercent represents the percent of disk used, e.g. 39. + DiskPercent int `json:"disk.percent,string"` + // Host represents the hostname of the node. + Host string `json:"host"` + // IP represents the IP address of the node. + IP string `json:"ip"` + // Node represents the node ID. + Node string `json:"node"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/cat_count.go b/vendor/gopkg.in/olivere/elastic.v6/cat_count.go new file mode 100644 index 0000000000..737f03dbe6 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/cat_count.go @@ -0,0 +1,164 @@ +// 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 ( + "context" + "fmt" + "net/url" + "strings" + + "github.com/olivere/elastic/uritemplates" +) + +// CatCountService provides quick access to the document count of the entire cluster, +// or individual indices. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cat-count.html +// for details. +type CatCountService struct { + client *Client + pretty bool + index []string + local *bool + masterTimeout string + columns []string + sort []string // list of columns for sort order +} + +// NewCatCountService creates a new CatCountService. +func NewCatCountService(client *Client) *CatCountService { + return &CatCountService{ + client: client, + } +} + +// Index specifies zero or more indices for which to return counts +// (by default counts for all indices are returned). +func (s *CatCountService) Index(index ...string) *CatCountService { + s.index = index + return s +} + +// Local indicates to return local information, i.e. do not retrieve +// the state from master node (default: false). +func (s *CatCountService) Local(local bool) *CatCountService { + s.local = &local + return s +} + +// MasterTimeout is the explicit operation timeout for connection to master node. +func (s *CatCountService) MasterTimeout(masterTimeout string) *CatCountService { + s.masterTimeout = masterTimeout + return s +} + +// Columns to return in the response. +// To get a list of all possible columns to return, run the following command +// in your terminal: +// +// Example: +// curl 'http://localhost:9200/_cat/count?help' +// +// You can use Columns("*") to return all possible columns. That might take +// a little longer than the default set of columns. +func (s *CatCountService) Columns(columns ...string) *CatCountService { + s.columns = columns + return s +} + +// Sort is a list of fields to sort by. +func (s *CatCountService) Sort(fields ...string) *CatCountService { + s.sort = fields + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *CatCountService) Pretty(pretty bool) *CatCountService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *CatCountService) buildURL() (string, url.Values, error) { + // Build URL + var ( + path string + err error + ) + + if len(s.index) > 0 { + path, err = uritemplates.Expand("/_cat/count/{index}", map[string]string{ + "index": strings.Join(s.index, ","), + }) + } else { + path = "/_cat/count" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{ + "format": []string{"json"}, // always returns as JSON + } + if s.pretty { + params.Set("pretty", "true") + } + if v := s.local; v != nil { + params.Set("local", fmt.Sprint(*v)) + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if len(s.sort) > 0 { + params.Set("s", strings.Join(s.sort, ",")) + } + if len(s.columns) > 0 { + params.Set("h", strings.Join(s.columns, ",")) + } + return path, params, nil +} + +// Do executes the operation. +func (s *CatCountService) Do(ctx context.Context) (CatCountResponse, error) { + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + var ret CatCountResponse + if err := s.client.decoder.Decode(res.Body, &ret); err != nil { + return nil, err + } + return ret, nil +} + +// -- Result of a get request. + +// CatCountResponse is the outcome of CatCountService.Do. +type CatCountResponse []CatCountResponseRow + +// CatCountResponseRow specifies the data returned for one index +// of a CatCountResponse. Notice that not all of these fields might +// be filled; that depends on the number of columns chose in the +// request (see CatCountService.Columns). +type CatCountResponseRow struct { + Epoch int64 `json:"epoch,string"` // e.g. 1527077996 + Timestamp string `json:"timestamp"` // e.g. "12:19:56" + Count int `json:"count,string"` // number of documents +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/cat_health.go b/vendor/gopkg.in/olivere/elastic.v6/cat_health.go new file mode 100644 index 0000000000..6dfeba7cc9 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/cat_health.go @@ -0,0 +1,160 @@ +// 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 ( + "context" + "fmt" + "net/url" + "strings" +) + +// CatHealthService returns a terse representation of the same information +// as /_cluster/health. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cat-health.html +// for details. +type CatHealthService struct { + client *Client + pretty bool + local *bool + masterTimeout string + columns []string + sort []string // list of columns for sort order + disableTimestamping *bool +} + +// NewCatHealthService creates a new CatHealthService. +func NewCatHealthService(client *Client) *CatHealthService { + return &CatHealthService{ + client: client, + } +} + +// Local indicates to return local information, i.e. do not retrieve +// the state from master node (default: false). +func (s *CatHealthService) Local(local bool) *CatHealthService { + s.local = &local + return s +} + +// MasterTimeout is the explicit operation timeout for connection to master node. +func (s *CatHealthService) MasterTimeout(masterTimeout string) *CatHealthService { + s.masterTimeout = masterTimeout + return s +} + +// Columns to return in the response. +// To get a list of all possible columns to return, run the following command +// in your terminal: +// +// Example: +// curl 'http://localhost:9200/_cat/indices?help' +// +// You can use Columns("*") to return all possible columns. That might take +// a little longer than the default set of columns. +func (s *CatHealthService) Columns(columns ...string) *CatHealthService { + s.columns = columns + return s +} + +// Sort is a list of fields to sort by. +func (s *CatHealthService) Sort(fields ...string) *CatHealthService { + s.sort = fields + return s +} + +// DisableTimestamping disables timestamping (default: true). +func (s *CatHealthService) DisableTimestamping(disable bool) *CatHealthService { + s.disableTimestamping = &disable + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *CatHealthService) Pretty(pretty bool) *CatHealthService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *CatHealthService) buildURL() (string, url.Values, error) { + // Build URL + path := "/_cat/health" + + // Add query string parameters + params := url.Values{ + "format": []string{"json"}, // always returns as JSON + } + if s.pretty { + params.Set("pretty", "true") + } + if v := s.local; v != nil { + params.Set("local", fmt.Sprint(*v)) + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if len(s.sort) > 0 { + params.Set("s", strings.Join(s.sort, ",")) + } + if v := s.disableTimestamping; v != nil { + params.Set("ts", fmt.Sprint(*v)) + } + if len(s.columns) > 0 { + params.Set("h", strings.Join(s.columns, ",")) + } + return path, params, nil +} + +// Do executes the operation. +func (s *CatHealthService) Do(ctx context.Context) (CatHealthResponse, error) { + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + var ret CatHealthResponse + if err := s.client.decoder.Decode(res.Body, &ret); err != nil { + return nil, err + } + return ret, nil +} + +// -- Result of a get request. + +// CatHealthResponse is the outcome of CatHealthService.Do. +type CatHealthResponse []CatHealthResponseRow + +// CatHealthResponseRow is a single row in a CatHealthResponse. +// Notice that not all of these fields might be filled; that depends +// on the number of columns chose in the request (see CatHealthService.Columns). +type CatHealthResponseRow struct { + Epoch int64 `json:"epoch,string"` // e.g. 1527077996 + Timestamp string `json:"timestamp"` // e.g. "12:19:56" + Cluster string `json:"cluster"` // cluster name, e.g. "elasticsearch" + Status string `json:"status"` // health status, e.g. "green", "yellow", or "red" + NodeTotal int `json:"node.total,string"` // total number of nodes + NodeData int `json:"node.data,string"` // number of nodes that can store data + Shards int `json:"shards,string"` // total number of shards + Pri int `json:"pri,string"` // number of primary shards + Relo int `json:"relo,string"` // number of relocating nodes + Init int `json:"init,string"` // number of initializing nodes + Unassign int `json:"unassign,string"` // number of unassigned shards + PendingTasks int `json:"pending_tasks,string"` // number of pending tasks + MaxTaskWaitTime string `json:"max_task_wait_time"` // wait time of longest task pending, e.g. "-" or time in millis + ActiveShardsPercent string `json:"active_shards_percent"` // active number of shards in percent, e.g. "100%" +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/cat_indices.go b/vendor/gopkg.in/olivere/elastic.v6/cat_indices.go new file mode 100644 index 0000000000..c8d33070f8 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/cat_indices.go @@ -0,0 +1,318 @@ +// 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 ( + "context" + "fmt" + "net/url" + "strings" + + "github.com/olivere/elastic/uritemplates" +) + +// CatIndicesService returns the list of indices plus some additional +// information about them. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cat-indices.html +// for details. +type CatIndicesService struct { + client *Client + pretty bool + index string + bytes string // b, k, m, or g + local *bool + masterTimeout string + columns []string + health string // green, yellow, or red + primaryOnly *bool // true for primary shards only + sort []string // list of columns for sort order +} + +// NewCatIndicesService creates a new CatIndicesService. +func NewCatIndicesService(client *Client) *CatIndicesService { + return &CatIndicesService{ + client: client, + } +} + +// Index is the name of the index to list (by default all indices are returned). +func (s *CatIndicesService) Index(index string) *CatIndicesService { + s.index = index + return s +} + +// Bytes represents the unit in which to display byte values. +// Valid values are: "b", "k", "m", or "g". +func (s *CatIndicesService) Bytes(bytes string) *CatIndicesService { + s.bytes = bytes + return s +} + +// Local indicates to return local information, i.e. do not retrieve +// the state from master node (default: false). +func (s *CatIndicesService) Local(local bool) *CatIndicesService { + s.local = &local + return s +} + +// MasterTimeout is the explicit operation timeout for connection to master node. +func (s *CatIndicesService) MasterTimeout(masterTimeout string) *CatIndicesService { + s.masterTimeout = masterTimeout + return s +} + +// Columns to return in the response. +// To get a list of all possible columns to return, run the following command +// in your terminal: +// +// Example: +// curl 'http://localhost:9200/_cat/indices?help' +// +// You can use Columns("*") to return all possible columns. That might take +// a little longer than the default set of columns. +func (s *CatIndicesService) Columns(columns ...string) *CatIndicesService { + s.columns = columns + return s +} + +// Health filters indices by their health status. +// Valid values are: "green", "yellow", or "red". +func (s *CatIndicesService) Health(healthState string) *CatIndicesService { + s.health = healthState + return s +} + +// PrimaryOnly when set to true returns stats only for primary shards (default: false). +func (s *CatIndicesService) PrimaryOnly(primaryOnly bool) *CatIndicesService { + s.primaryOnly = &primaryOnly + return s +} + +// Sort is a list of fields to sort by. +func (s *CatIndicesService) Sort(fields ...string) *CatIndicesService { + s.sort = fields + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *CatIndicesService) Pretty(pretty bool) *CatIndicesService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *CatIndicesService) buildURL() (string, url.Values, error) { + // Build URL + var ( + path string + err error + ) + + if s.index != "" { + path, err = uritemplates.Expand("/_cat/indices/{index}", map[string]string{ + "index": s.index, + }) + } else { + path = "/_cat/indices" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{ + "format": []string{"json"}, // always returns as JSON + } + if s.pretty { + params.Set("pretty", "true") + } + if s.bytes != "" { + params.Set("bytes", s.bytes) + } + if v := s.local; v != nil { + params.Set("local", fmt.Sprint(*v)) + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if len(s.columns) > 0 { + params.Set("h", strings.Join(s.columns, ",")) + } + if s.health != "" { + params.Set("health", s.health) + } + if v := s.primaryOnly; v != nil { + params.Set("pri", fmt.Sprint(*v)) + } + if len(s.sort) > 0 { + params.Set("s", strings.Join(s.sort, ",")) + } + return path, params, nil +} + +// Do executes the operation. +func (s *CatIndicesService) Do(ctx context.Context) (CatIndicesResponse, error) { + // Get URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + var ret CatIndicesResponse + if err := s.client.decoder.Decode(res.Body, &ret); err != nil { + return nil, err + } + return ret, nil +} + +// -- Result of a get request. + +// CatIndicesResponse is the outcome of CatIndicesService.Do. +type CatIndicesResponse []CatIndicesResponseRow + +// CatIndicesResponseRow specifies the data returned for one index +// of a CatIndicesResponse. Notice that not all of these fields might +// be filled; that depends on the number of columns chose in the +// request (see CatIndicesService.Columns). +type CatIndicesResponseRow struct { + Health string `json:"health"` // "green", "yellow", or "red" + Status string `json:"status"` // "open" or "closed" + Index string `json:"index"` // index name + UUID string `json:"uuid"` // index uuid + Pri int `json:"pri,string"` // number of primary shards + Rep int `json:"rep,string"` // number of replica shards + DocsCount int `json:"docs.count,string"` // number of available documents + DocsDeleted int `json:"docs.deleted,string"` // number of deleted documents + CreationDate int64 `json:"creation.date,string"` // index creation date (millisecond value), e.g. 1527077221644 + CreationDateString string `json:"creation.date.string"` // index creation date (as string), e.g. "2018-05-23T12:07:01.644Z" + StoreSize string `json:"store.size"` // store size of primaries & replicas, e.g. "4.6kb" + PriStoreSize string `json:"pri.store.size"` // store size of primaries, e.g. "230b" + CompletionSize string `json:"completion.size"` // size of completion on primaries & replicas + PriCompletionSize string `json:"pri.completion.size"` // size of completion on primaries + FielddataMemorySize string `json:"fielddata.memory_size"` // used fielddata cache on primaries & replicas + PriFielddataMemorySize string `json:"pri.fielddata.memory_size"` // used fielddata cache on primaries + FielddataEvictions int `json:"fielddata.evictions,string"` // fielddata evictions on primaries & replicas + PriFielddataEvictions int `json:"pri.fielddata.evictions,string"` // fielddata evictions on primaries + QueryCacheMemorySize string `json:"query_cache.memory_size"` // used query cache on primaries & replicas + PriQueryCacheMemorySize string `json:"pri.query_cache.memory_size"` // used query cache on primaries + QueryCacheEvictions int `json:"query_cache.evictions,string"` // query cache evictions on primaries & replicas + PriQueryCacheEvictions int `json:"pri.query_cache.evictions,string"` // query cache evictions on primaries + RequestCacheMemorySize string `json:"request_cache.memory_size"` // used request cache on primaries & replicas + PriRequestCacheMemorySize string `json:"pri.request_cache.memory_size"` // used request cache on primaries + RequestCacheEvictions int `json:"request_cache.evictions,string"` // request cache evictions on primaries & replicas + PriRequestCacheEvictions int `json:"pri.request_cache.evictions,string"` // request cache evictions on primaries + RequestCacheHitCount int `json:"request_cache.hit_count,string"` // request cache hit count on primaries & replicas + PriRequestCacheHitCount int `json:"pri.request_cache.hit_count,string"` // request cache hit count on primaries + RequestCacheMissCount int `json:"request_cache.miss_count,string"` // request cache miss count on primaries & replicas + PriRequestCacheMissCount int `json:"pri.request_cache.miss_count,string"` // request cache miss count on primaries + FlushTotal int `json:"flush.total"` // number of flushes on primaries & replicas + PriFlushTotal int `json:"pri.flush.total"` // number of flushes on primaries + FlushTotalTime string `json:"flush.total_time"` // time spent in flush on primaries & replicas + PriFlushTotalTime string `json:"pri.flush.total_time"` // time spent in flush on primaries + GetCurrent int `json:"get.current,string"` // number of current get ops on primaries & replicas + PriGetCurrent int `json:"pri.get.current,string"` // number of current get ops on primaries + GetTime string `json:"get.time"` // time spent in get on primaries & replicas + PriGetTime string `json:"pri.get.time"` // time spent in get on primaries + GetTotal int `json:"get.total,string"` // number of get ops on primaries & replicas + PriGetTotal int `json:"pri.get.total,string"` // number of get ops on primaries + GetExistsTime string `json:"get.exists_time"` // time spent in successful gets on primaries & replicas + PriGetExistsTime string `json:"pri.get.exists_time"` // time spent in successful gets on primaries + GetExistsTotal int `json:"get.exists_total,string"` // number of successful gets on primaries & replicas + PriGetExistsTotal int `json:"pri.get.exists_total,string"` // number of successful gets on primaries + GetMissingTime string `json:"get.missing_time"` // time spent in failed gets on primaries & replicas + PriGetMissingTime string `json:"pri.get.missing_time"` // time spent in failed gets on primaries + GetMissingTotal int `json:"get.missing_total,string"` // number of failed gets on primaries & replicas + PriGetMissingTotal int `json:"pri.get.missing_total,string"` // number of failed gets on primaries + IndexingDeleteCurrent int `json:"indexing.delete_current,string"` // number of current deletions on primaries & replicas + PriIndexingDeleteCurrent int `json:"pri.indexing.delete_current,string"` // number of current deletions on primaries + IndexingDeleteTime string `json:"indexing.delete_time"` // time spent in deletions on primaries & replicas + PriIndexingDeleteTime string `json:"pri.indexing.delete_time"` // time spent in deletions on primaries + IndexingDeleteTotal int `json:"indexing.delete_total,string"` // number of delete ops on primaries & replicas + PriIndexingDeleteTotal int `json:"pri.indexing.delete_total,string"` // number of delete ops on primaries + IndexingIndexCurrent int `json:"indexing.index_current,string"` // number of current indexing on primaries & replicas + PriIndexingIndexCurrent int `json:"pri.indexing.index_current,string"` // number of current indexing on primaries + IndexingIndexTime string `json:"indexing.index_time"` // time spent in indexing on primaries & replicas + PriIndexingIndexTime string `json:"pri.indexing.index_time"` // time spent in indexing on primaries + IndexingIndexTotal int `json:"indexing.index_total,string"` // number of index ops on primaries & replicas + PriIndexingIndexTotal int `json:"pri.indexing.index_total,string"` // number of index ops on primaries + IndexingIndexFailed int `json:"indexing.index_failed,string"` // number of failed indexing ops on primaries & replicas + PriIndexingIndexFailed int `json:"pri.indexing.index_failed,string"` // number of failed indexing ops on primaries + MergesCurrent int `json:"merges.current,string"` // number of current merges on primaries & replicas + PriMergesCurrent int `json:"pri.merges.current,string"` // number of current merges on primaries + MergesCurrentDocs int `json:"merges.current_docs,string"` // number of current merging docs on primaries & replicas + PriMergesCurrentDocs int `json:"pri.merges.current_docs,string"` // number of current merging docs on primaries + MergesCurrentSize string `json:"merges.current_size"` // size of current merges on primaries & replicas + PriMergesCurrentSize string `json:"pri.merges.current_size"` // size of current merges on primaries + MergesTotal int `json:"merges.total,string"` // number of completed merge ops on primaries & replicas + PriMergesTotal int `json:"pri.merges.total,string"` // number of completed merge ops on primaries + MergesTotalDocs int `json:"merges.total_docs,string"` // docs merged on primaries & replicas + PriMergesTotalDocs int `json:"pri.merges.total_docs,string"` // docs merged on primaries + MergesTotalSize string `json:"merges.total_size"` // size merged on primaries & replicas + PriMergesTotalSize string `json:"pri.merges.total_size"` // size merged on primaries + MergesTotalTime string `json:"merges.total_time"` // time spent in merges on primaries & replicas + PriMergesTotalTime string `json:"pri.merges.total_time"` // time spent in merges on primaries + RefreshTotal int `json:"refresh.total,string"` // total refreshes on primaries & replicas + PriRefreshTotal int `json:"pri.refresh.total,string"` // total refreshes on primaries + RefreshTime string `json:"refresh.time"` // time spent in refreshes on primaries & replicas + PriRefreshTime string `json:"pri.refresh.time"` // time spent in refreshes on primaries + RefreshListeners int `json:"refresh.listeners,string"` // number of pending refresh listeners on primaries & replicas + PriRefreshListeners int `json:"pri.refresh.listeners,string"` // number of pending refresh listeners on primaries + SearchFetchCurrent int `json:"search.fetch_current,string"` // current fetch phase ops on primaries & replicas + PriSearchFetchCurrent int `json:"pri.search.fetch_current,string"` // current fetch phase ops on primaries + SearchFetchTime string `json:"search.fetch_time"` // time spent in fetch phase on primaries & replicas + PriSearchFetchTime string `json:"pri.search.fetch_time"` // time spent in fetch phase on primaries + SearchFetchTotal int `json:"search.fetch_total,string"` // total fetch ops on primaries & replicas + PriSearchFetchTotal int `json:"pri.search.fetch_total,string"` // total fetch ops on primaries + SearchOpenContexts int `json:"search.open_contexts,string"` // open search contexts on primaries & replicas + PriSearchOpenContexts int `json:"pri.search.open_contexts,string"` // open search contexts on primaries + SearchQueryCurrent int `json:"search.query_current,string"` // current query phase ops on primaries & replicas + PriSearchQueryCurrent int `json:"pri.search.query_current,string"` // current query phase ops on primaries + SearchQueryTime string `json:"search.query_time"` // time spent in query phase on primaries & replicas, e.g. "0s" + PriSearchQueryTime string `json:"pri.search.query_time"` // time spent in query phase on primaries, e.g. "0s" + SearchQueryTotal int `json:"search.query_total,string"` // total query phase ops on primaries & replicas + PriSearchQueryTotal int `json:"pri.search.query_total,string"` // total query phase ops on primaries + SearchScrollCurrent int `json:"search.scroll_current,string"` // open scroll contexts on primaries & replicas + PriSearchScrollCurrent int `json:"pri.search.scroll_current,string"` // open scroll contexts on primaries + SearchScrollTime string `json:"search.scroll_time"` // time scroll contexts held open on primaries & replicas, e.g. "0s" + PriSearchScrollTime string `json:"pri.search.scroll_time"` // time scroll contexts held open on primaries, e.g. "0s" + SearchScrollTotal int `json:"search.scroll_total,string"` // completed scroll contexts on primaries & replicas + PriSearchScrollTotal int `json:"pri.search.scroll_total,string"` // completed scroll contexts on primaries + SegmentsCount int `json:"segments.count,string"` // number of segments on primaries & replicas + PriSegmentsCount int `json:"pri.segments.count,string"` // number of segments on primaries + SegmentsMemory string `json:"segments.memory"` // memory used by segments on primaries & replicas, e.g. "1.3kb" + PriSegmentsMemory string `json:"pri.segments.memory"` // memory used by segments on primaries, e.g. "1.3kb" + SegmentsIndexWriterMemory string `json:"segments.index_writer_memory"` // memory used by index writer on primaries & replicas, e.g. "0b" + PriSegmentsIndexWriterMemory string `json:"pri.segments.index_writer_memory"` // memory used by index writer on primaries, e.g. "0b" + SegmentsVersionMapMemory string `json:"segments.version_map_memory"` // memory used by version map on primaries & replicas, e.g. "0b" + PriSegmentsVersionMapMemory string `json:"pri.segments.version_map_memory"` // memory used by version map on primaries, e.g. "0b" + SegmentsFixedBitsetMemory string `json:"segments.fixed_bitset_memory"` // memory used by fixed bit sets for nested object field types and type filters for types referred in _parent fields on primaries & replicas, e.g. "0b" + PriSegmentsFixedBitsetMemory string `json:"pri.segments.fixed_bitset_memory"` // memory used by fixed bit sets for nested object field types and type filters for types referred in _parent fields on primaries, e.g. "0b" + WarmerCurrent int `json:"warmer.count,string"` // current warmer ops on primaries & replicas + PriWarmerCurrent int `json:"pri.warmer.count,string"` // current warmer ops on primaries + WarmerTotal int `json:"warmer.total,string"` // total warmer ops on primaries & replicas + PriWarmerTotal int `json:"pri.warmer.total,string"` // total warmer ops on primaries + WarmerTotalTime string `json:"warmer.total_time"` // time spent in warmers on primaries & replicas, e.g. "47s" + PriWarmerTotalTime string `json:"pri.warmer.total_time"` // time spent in warmers on primaries, e.g. "47s" + SuggestCurrent int `json:"suggest.current,string"` // number of current suggest ops on primaries & replicas + PriSuggestCurrent int `json:"pri.suggest.current,string"` // number of current suggest ops on primaries + SuggestTime string `json:"suggest.time"` // time spend in suggest on primaries & replicas, "31s" + PriSuggestTime string `json:"pri.suggest.time"` // time spend in suggest on primaries, e.g. "31s" + SuggestTotal int `json:"suggest.total,string"` // number of suggest ops on primaries & replicas + PriSuggestTotal int `json:"pri.suggest.total,string"` // number of suggest ops on primaries + MemoryTotal string `json:"memory.total"` // total user memory on primaries & replicas, e.g. "1.5kb" + PriMemoryTotal string `json:"pri.memory.total"` // total user memory on primaries, e.g. "1.5kb" +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/clear_scroll.go b/vendor/gopkg.in/olivere/elastic.v6/clear_scroll.go similarity index 89% rename from vendor/gopkg.in/olivere/elastic.v5/clear_scroll.go rename to vendor/gopkg.in/olivere/elastic.v6/clear_scroll.go index 83e592875c..4cf88c768a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/clear_scroll.go +++ b/vendor/gopkg.in/olivere/elastic.v6/clear_scroll.go @@ -12,7 +12,7 @@ import ( // ClearScrollService clears one or more scroll contexts by their ids. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-scroll.html#_clear_scroll_api +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-scroll.html#_clear_scroll_api // for details. type ClearScrollService struct { client *Client @@ -49,7 +49,7 @@ func (s *ClearScrollService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } return path, params, nil } @@ -85,7 +85,12 @@ func (s *ClearScrollService) Do(ctx context.Context) (*ClearScrollResponse, erro } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "DELETE", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/client.go b/vendor/gopkg.in/olivere/elastic.v6/client.go similarity index 84% rename from vendor/gopkg.in/olivere/elastic.v5/client.go rename to vendor/gopkg.in/olivere/elastic.v6/client.go index 5433ed40c7..ea7a86fd40 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/client.go +++ b/vendor/gopkg.in/olivere/elastic.v6/client.go @@ -21,12 +21,12 @@ import ( "github.com/pkg/errors" - "gopkg.in/olivere/elastic.v5/config" + "github.com/olivere/elastic/config" ) const ( // Version is the current version of Elastic. - Version = "5.0.82" + Version = "6.2.23" // 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. @@ -134,8 +134,8 @@ type Client struct { 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) + requiredPlugins []string // list of required plugins retrier Retrier // strategy for retries } @@ -158,7 +158,7 @@ type Client struct { // // If the sniffer is enabled (the default), the new client then sniffes // the cluster via the Nodes Info API -// (see https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-nodes-info.html#cluster-nodes-info). +// (see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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. @@ -190,147 +190,16 @@ type Client struct { // An error is also returned when some configuration option is invalid or // the new client cannot sniff the cluster (if enabled). func NewClient(options ...ClientOptionFunc) (*Client, error) { - // Set up the client - c := &Client{ - c: http.DefaultClient, - conns: make([]*conn, 0), - cindex: -1, - scheme: DefaultScheme, - decoder: &DefaultDecoder{}, - healthcheckEnabled: DefaultHealthcheckEnabled, - healthcheckTimeoutStartup: DefaultHealthcheckTimeoutStartup, - healthcheckTimeout: DefaultHealthcheckTimeout, - healthcheckInterval: DefaultHealthcheckInterval, - healthcheckStop: make(chan bool), - snifferEnabled: DefaultSnifferEnabled, - 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 - for _, option := range options { - if err := option(c); err != nil { - return nil, err - } - } - - // 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 { - return nil, err - } - } - - if c.snifferEnabled { - // Sniff the cluster initially - if err := c.sniff(c.snifferTimeoutStartup); err != nil { - return nil, err - } - } else { - // Do not sniff the cluster initially. Use the provided URLs instead. - for _, url := range c.urls { - c.conns = append(c.conns, newConn(url, url)) - } - } - - if c.healthcheckEnabled { - // Perform an initial health check - c.healthcheck(c.healthcheckTimeoutStartup, true) - } - // Ensure that we have at least one connection available - if err := c.mustActiveConn(); err != nil { - return nil, err - } - - // Check the required plugins - for _, plugin := range c.requiredPlugins { - found, err := c.HasPlugin(plugin) - if err != nil { - return nil, err - } - if !found { - return nil, fmt.Errorf("elastic: plugin %s not found", plugin) - } - } - - if c.snifferEnabled { - go c.sniffer() // periodically update cluster information - } - if c.healthcheckEnabled { - go c.healthchecker() // start goroutine periodically ping all nodes of the cluster - } - - c.mu.Lock() - c.running = true - c.mu.Unlock() - - return c, nil + return DialContext(context.Background(), options...) } // NewClientFromConfig initializes a client from a configuration. func NewClientFromConfig(cfg *config.Config) (*Client, error) { - var options []ClientOptionFunc - if cfg != nil { - if cfg.URL != "" { - options = append(options, SetURL(cfg.URL)) - } - if cfg.Errorlog != "" { - f, err := os.OpenFile(cfg.Errorlog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return nil, errors.Wrap(err, "unable to initialize error log") - } - l := log.New(f, "", 0) - options = append(options, SetErrorLog(l)) - } - if cfg.Tracelog != "" { - f, err := os.OpenFile(cfg.Tracelog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return nil, errors.Wrap(err, "unable to initialize trace log") - } - l := log.New(f, "", 0) - options = append(options, SetTraceLog(l)) - } - if cfg.Infolog != "" { - f, err := os.OpenFile(cfg.Infolog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return nil, errors.Wrap(err, "unable to initialize info log") - } - l := log.New(f, "", 0) - options = append(options, SetInfoLog(l)) - } - if cfg.Username != "" || cfg.Password != "" { - options = append(options, SetBasicAuth(cfg.Username, cfg.Password)) - } - if cfg.Sniff != nil { - options = append(options, SetSniff(*cfg.Sniff)) - } + options, err := configToOptions(cfg) + if err != nil { + return nil, err } - return NewClient(options...) + return DialContext(context.Background(), options...) } // NewSimpleClient creates a new short-lived Client that can be used in @@ -424,6 +293,174 @@ func NewSimpleClient(options ...ClientOptionFunc) (*Client, error) { return c, nil } +// Dial will call DialContext with a background context. +func Dial(options ...ClientOptionFunc) (*Client, error) { + return DialContext(context.Background(), options...) +} + +// DialContext will connect to Elasticsearch, just like NewClient does. +// +// The context is honoured in terms of e.g. cancellation. +func DialContext(ctx context.Context, options ...ClientOptionFunc) (*Client, error) { + // Set up the client + c := &Client{ + c: http.DefaultClient, + conns: make([]*conn, 0), + cindex: -1, + scheme: DefaultScheme, + decoder: &DefaultDecoder{}, + healthcheckEnabled: DefaultHealthcheckEnabled, + healthcheckTimeoutStartup: DefaultHealthcheckTimeoutStartup, + healthcheckTimeout: DefaultHealthcheckTimeout, + healthcheckInterval: DefaultHealthcheckInterval, + healthcheckStop: make(chan bool), + snifferEnabled: DefaultSnifferEnabled, + 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 + for _, option := range options { + if err := option(c); err != nil { + return nil, err + } + } + + // 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(ctx, c.healthcheckTimeoutStartup); err != nil { + return nil, err + } + } + + if c.snifferEnabled { + // Sniff the cluster initially + if err := c.sniff(ctx, c.snifferTimeoutStartup); err != nil { + return nil, err + } + } else { + // Do not sniff the cluster initially. Use the provided URLs instead. + for _, url := range c.urls { + c.conns = append(c.conns, newConn(url, url)) + } + } + + if c.healthcheckEnabled { + // Perform an initial health check + c.healthcheck(ctx, c.healthcheckTimeoutStartup, true) + } + // Ensure that we have at least one connection available + if err := c.mustActiveConn(); err != nil { + return nil, err + } + + // Check the required plugins + for _, plugin := range c.requiredPlugins { + found, err := c.HasPlugin(plugin) + if err != nil { + return nil, err + } + if !found { + return nil, fmt.Errorf("elastic: plugin %s not found", plugin) + } + } + + if c.snifferEnabled { + go c.sniffer() // periodically update cluster information + } + if c.healthcheckEnabled { + go c.healthchecker() // start goroutine periodically ping all nodes of the cluster + } + + c.mu.Lock() + c.running = true + c.mu.Unlock() + + return c, nil +} + +// DialWithConfig will use the configuration settings parsed from config package +// to connect to Elasticsearch. +// +// The context is honoured in terms of e.g. cancellation. +func DialWithConfig(ctx context.Context, cfg *config.Config) (*Client, error) { + options, err := configToOptions(cfg) + if err != nil { + return nil, err + } + return DialContext(ctx, options...) +} + +func configToOptions(cfg *config.Config) ([]ClientOptionFunc, error) { + var options []ClientOptionFunc + if cfg != nil { + if cfg.URL != "" { + options = append(options, SetURL(cfg.URL)) + } + if cfg.Errorlog != "" { + f, err := os.OpenFile(cfg.Errorlog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return nil, errors.Wrap(err, "unable to initialize error log") + } + l := log.New(f, "", 0) + options = append(options, SetErrorLog(l)) + } + if cfg.Tracelog != "" { + f, err := os.OpenFile(cfg.Tracelog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return nil, errors.Wrap(err, "unable to initialize trace log") + } + l := log.New(f, "", 0) + options = append(options, SetTraceLog(l)) + } + if cfg.Infolog != "" { + f, err := os.OpenFile(cfg.Infolog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return nil, errors.Wrap(err, "unable to initialize info log") + } + l := log.New(f, "", 0) + options = append(options, SetInfoLog(l)) + } + if cfg.Username != "" || cfg.Password != "" { + options = append(options, SetBasicAuth(cfg.Username, cfg.Password)) + } + if cfg.Sniff != nil { + options = append(options, SetSniff(*cfg.Sniff)) + } + /* + if cfg.Healthcheck != nil { + options = append(options, SetHealthcheck(*cfg.Healthcheck)) + } + */ + } + return options, nil +} + // SetHttpClient can be used to specify the http.Client to use when making // HTTP requests to Elasticsearch. func SetHttpClient(httpClient *http.Client) ClientOptionFunc { @@ -816,7 +853,7 @@ func (c *Client) sniffer() { c.snifferStop <- true return case <-ticker.C: - c.sniff(timeout) + c.sniff(context.Background(), timeout) } } } @@ -826,7 +863,7 @@ func (c *Client) sniffer() { // by the preceding sniffing process (if sniffing is enabled). // // If sniffing is disabled, this is a no-op. -func (c *Client) sniff(timeout time.Duration) error { +func (c *Client) sniff(parentCtx context.Context, timeout time.Duration) error { c.mu.RLock() if !c.snifferEnabled { c.mu.RUnlock() @@ -863,7 +900,7 @@ func (c *Client) sniff(timeout time.Duration) error { // Start sniffing on all found URLs ch := make(chan []*conn, len(urls)) - ctx, cancel := context.WithTimeout(context.Background(), timeout) + ctx, cancel := context.WithTimeout(parentCtx, timeout) defer cancel() for _, url := range urls { @@ -879,6 +916,13 @@ func (c *Client) sniff(timeout time.Duration) error { return nil } case <-ctx.Done(): + if err := ctx.Err(); err != nil { + switch { + case IsContextErr(err): + return err + } + return errors.Wrapf(ErrNoClient, "sniff timeout: %v", err) + } // We get here if no cluster responds in time return errors.Wrap(ErrNoClient, "sniff timeout") } @@ -967,7 +1011,9 @@ func (c *Client) updateConns(conns []*conn) { for _, conn := range conns { var found bool for _, oldConn := range c.conns { - if oldConn.NodeID() == conn.NodeID() { + // Notice that e.g. in a Kubernetes cluster the NodeID might be + // stable while the URL has changed. + if oldConn.NodeID() == conn.NodeID() && oldConn.URL() == conn.URL() { // Take over the old connection newConns = append(newConns, oldConn) found = true @@ -1003,7 +1049,7 @@ func (c *Client) healthchecker() { c.healthcheckStop <- true return case <-ticker.C: - c.healthcheck(timeout, false) + c.healthcheck(context.Background(), timeout, false) } } } @@ -1012,7 +1058,7 @@ func (c *Client) healthchecker() { // the node state, it marks connections as dead, sets them alive etc. // If healthchecks are disabled and force is false, this is a no-op. // The timeout specifies how long to wait for a response from Elasticsearch. -func (c *Client) healthcheck(timeout time.Duration, force bool) { +func (c *Client) healthcheck(parentCtx context.Context, timeout time.Duration, force bool) { c.mu.RLock() if !c.healthcheckEnabled && !force { c.mu.RUnlock() @@ -1029,7 +1075,7 @@ func (c *Client) healthcheck(timeout time.Duration, force bool) { for _, conn := range conns { // Run the HEAD request against ES with a timeout - ctx, cancel := context.WithTimeout(context.Background(), timeout) + ctx, cancel := context.WithTimeout(parentCtx, timeout) defer cancel() // Goroutine executes the HTTP request, returns an error and sets status @@ -1077,7 +1123,7 @@ func (c *Client) healthcheck(timeout time.Duration, force bool) { // startupHealthcheck is used at startup to check if the server is available // at all. -func (c *Client) startupHealthcheck(timeout time.Duration) error { +func (c *Client) startupHealthcheck(parentCtx context.Context, timeout time.Duration) error { c.mu.Lock() urls := c.urls basicAuth := c.basicAuth @@ -1088,7 +1134,8 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error { // If we don't get a connection after "timeout", we bail. var lastErr error start := time.Now() - for { + done := false + for !done { for _, url := range urls { req, err := http.NewRequest("HEAD", url, nil) if err != nil { @@ -1097,7 +1144,7 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error { if basicAuth { req.SetBasicAuth(basicAuthUsername, basicAuthPassword) } - ctx, cancel := context.WithTimeout(req.Context(), timeout) + ctx, cancel := context.WithTimeout(parentCtx, timeout) defer cancel() req = req.WithContext(ctx) res, err := c.c.Do(req) @@ -1107,12 +1154,22 @@ func (c *Client) startupHealthcheck(timeout time.Duration) error { lastErr = err } } - time.Sleep(1 * time.Second) - if time.Since(start) > timeout { + select { + case <-parentCtx.Done(): + lastErr = parentCtx.Err() + done = true break + case <-time.After(1 * time.Second): + if time.Since(start) > timeout { + done = true + break + } } } if lastErr != nil { + if IsContextErr(lastErr) { + return lastErr + } return errors.Wrapf(ErrNoClient, "health check timeout: %v", lastErr) } return errors.Wrap(ErrNoClient, "health check timeout") @@ -1175,48 +1232,24 @@ func (c *Client) mustActiveConn() error { // PerformRequestOptions must be passed into PerformRequest. type PerformRequestOptions struct { - Method string - Path string - Params url.Values - Body interface{} - ContentType string - IgnoreErrors []int - Retrier Retrier + Method string + Path string + Params url.Values + Body interface{} + ContentType string + IgnoreErrors []int + Retrier Retrier + Headers http.Header + MaxResponseSize int64 } // PerformRequest does a HTTP request to Elasticsearch. -// See PerformRequestWithContentType for details. -func (c *Client) PerformRequest(ctx context.Context, method, path string, params url.Values, body interface{}, ignoreErrors ...int) (*Response, error) { - return c.PerformRequestWithOptions(ctx, PerformRequestOptions{ - Method: method, - Path: path, - Params: params, - Body: body, - ContentType: "application/json", - IgnoreErrors: ignoreErrors, - }) -} - -// PerformRequestWithContentType executes a HTTP request with a specific content type. // 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) PerformRequestWithContentType(ctx context.Context, method, path string, params url.Values, body interface{}, contentType string, ignoreErrors ...int) (*Response, error) { - return c.PerformRequestWithOptions(ctx, PerformRequestOptions{ - Method: method, - Path: path, - Params: params, - Body: body, - ContentType: contentType, - IgnoreErrors: ignoreErrors, - }) -} - -// PerformRequestWithOptions executes a HTTP request with the specified options. -// It returns a response (which might be nil) and an error on failure. -func (c *Client) PerformRequestWithOptions(ctx context.Context, opt PerformRequestOptions) (*Response, error) { +func (c *Client) PerformRequest(ctx context.Context, opt PerformRequestOptions) (*Response, error) { start := time.Now().UTC() c.mu.RLock() @@ -1256,7 +1289,7 @@ func (c *Client) PerformRequestWithOptions(ctx context.Context, opt PerformReque n++ if !retried { // Force a healtcheck as all connections seem to be dead. - c.healthcheck(timeout, false) + c.healthcheck(ctx, timeout, false) } wait, ok, rerr := retrier.Retry(ctx, n, nil, nil, err) if rerr != nil { @@ -1287,6 +1320,14 @@ func (c *Client) PerformRequestWithOptions(ctx context.Context, opt PerformReque req.Header.Set("Content-Type", opt.ContentType) } + if len(opt.Headers) > 0 { + for key, value := range opt.Headers { + for _, v := range value { + req.Header.Add(key, v) + } + } + } + // Set body if opt.Body != nil { err = req.SetBody(opt.Body, gzipEnabled) @@ -1329,18 +1370,23 @@ func (c *Client) PerformRequestWithOptions(ctx context.Context, opt PerformReque // Tracing c.dumpResponse(res) + // Log deprecation warnings as errors + if s := res.Header.Get("Warning"); s != "" { + c.errorf(s) + } + // Check for errors if err := checkResponse((*http.Request)(req), res, opt.IgnoreErrors...); err != nil { // No retry if request succeeded // We still try to return a response. - resp, _ = c.newResponse(res) + resp, _ = c.newResponse(res, opt.MaxResponseSize) return resp, err } // We successfully made a request with this connection conn.MarkAsHealthy() - resp, err = c.newResponse(res) + resp, err = c.newResponse(res, opt.MaxResponseSize) if err != nil { return nil, err } @@ -1412,7 +1458,7 @@ func (c *Client) BulkProcessor() *BulkProcessorService { // Reindex copies data from a source index into a destination index. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-reindex.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-reindex.html // for details on the Reindex API. func (c *Client) Reindex() *ReindexService { return NewReindexService(c) @@ -1439,11 +1485,6 @@ func (c *Client) Search(indices ...string) *SearchService { return NewSearchService(c).Index(indices...) } -// Suggest returns a service to return suggestions. -func (c *Client) Suggest(indices ...string) *SuggestService { - return NewSuggestService(c).Index(indices...) -} - // MultiSearch is the entry point for multi searches. func (c *Client) MultiSearch() *MultiSearchService { return NewMultiSearchService(c) @@ -1477,11 +1518,6 @@ func (c *Client) FieldCaps(indices ...string) *FieldCapsService { return NewFieldCapsService(c).Index(indices...) } -// FieldStats returns statistical information about fields in indices. -func (c *Client) FieldStats(indices ...string) *FieldStatsService { - return NewFieldStatsService(c).Index(indices...) -} - // Exists checks if a document exists. func (c *Client) Exists() *ExistsService { return NewExistsService(c) @@ -1591,6 +1627,15 @@ func (c *Client) Flush(indices ...string) *IndicesFlushService { return NewIndicesFlushService(c).Index(indices...) } +// SyncedFlush performs a synced flush. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-synced-flush.html +// for more details on synched flushes and how they differ from a normal +// Flush. +func (c *Client) SyncedFlush(indices ...string) *IndicesSyncedFlushService { + return NewIndicesSyncedFlushService(c).Index(indices...) +} + // Alias enables the caller to add and/or remove aliases. func (c *Client) Alias() *AliasService { return NewAliasService(c) @@ -1601,24 +1646,6 @@ func (c *Client) Aliases() *AliasesService { return NewAliasesService(c) } -// GetTemplate gets a search template. -// Use IndexXXXTemplate funcs to manage index templates. -func (c *Client) GetTemplate() *GetTemplateService { - return NewGetTemplateService(c) -} - -// PutTemplate creates or updates a search template. -// Use IndexXXXTemplate funcs to manage index templates. -func (c *Client) PutTemplate() *PutTemplateService { - return NewPutTemplateService(c) -} - -// DeleteTemplate deletes a search template. -// Use IndexXXXTemplate funcs to manage index templates. -func (c *Client) DeleteTemplate() *DeleteTemplateService { - return NewDeleteTemplateService(c) -} - // IndexGetTemplate gets an index template. // Use XXXTemplate funcs to manage search templates. func (c *Client) IndexGetTemplate(names ...string) *IndicesGetTemplateService { @@ -1660,12 +1687,7 @@ func (c *Client) GetFieldMapping() *IndicesGetFieldMappingService { // -- cat APIs -- -// TODO cat aliases -// TODO cat allocation -// TODO cat count // TODO cat fielddata -// TODO cat health -// TODO cat indices // TODO cat master // TODO cat nodes // TODO cat pending tasks @@ -1675,6 +1697,31 @@ func (c *Client) GetFieldMapping() *IndicesGetFieldMappingService { // TODO cat shards // TODO cat segments +// CatAliases returns information about aliases. +func (c *Client) CatAliases() *CatAliasesService { + return NewCatAliasesService(c) +} + +// CatAllocation returns information about the allocation across nodes. +func (c *Client) CatAllocation() *CatAllocationService { + return NewCatAllocationService(c) +} + +// CatCount returns document counts for indices. +func (c *Client) CatCount() *CatCountService { + return NewCatCountService(c) +} + +// CatHealth returns information about cluster health. +func (c *Client) CatHealth() *CatHealthService { + return NewCatHealthService(c) +} + +// CatIndices returns information about indices. +func (c *Client) CatIndices() *CatIndicesService { + return NewCatIndicesService(c) +} + // -- Ingest APIs -- // IngestPutPipeline adds pipelines and updates existing pipelines in @@ -1706,6 +1753,12 @@ func (c *Client) ClusterHealth() *ClusterHealthService { return NewClusterHealthService(c) } +// ClusterReroute allows for manual changes to the allocation of +// individual shards in the cluster. +func (c *Client) ClusterReroute() *ClusterRerouteService { + return NewClusterRerouteService(c) +} + // ClusterState retrieves the state of the cluster. func (c *Client) ClusterState() *ClusterStateService { return NewClusterStateService(c) @@ -1755,7 +1808,7 @@ func (c *Client) TasksGetTask() *TasksGetTaskService { // TODO Snapshot Status // SnapshotCreate creates a snapshot. -func (c *Client) SnapshotCreate(repository string, snapshot string) *SnapshotCreateService { +func (c *Client) SnapshotCreate(repository, snapshot string) *SnapshotCreateService { return NewSnapshotCreateService(c).Repository(repository).Snapshot(snapshot) } @@ -1764,6 +1817,11 @@ func (c *Client) SnapshotCreateRepository(repository string) *SnapshotCreateRepo return NewSnapshotCreateRepositoryService(c).Repository(repository) } +// SnapshotDelete deletes a snapshot in a snapshot repository. +func (c *Client) SnapshotDelete(repository, snapshot string) *SnapshotDeleteService { + return NewSnapshotDeleteService(c).Repository(repository).Snapshot(snapshot) +} + // SnapshotDeleteRepository deletes a snapshot repository. func (c *Client) SnapshotDeleteRepository(repositories ...string) *SnapshotDeleteRepositoryService { return NewSnapshotDeleteRepositoryService(c).Repository(repositories...) @@ -1774,11 +1832,156 @@ func (c *Client) SnapshotGetRepository(repositories ...string) *SnapshotGetRepos return NewSnapshotGetRepositoryService(c).Repository(repositories...) } +// SnapshotGet lists snapshot for a repository. +func (c *Client) SnapshotGet(repository string) *SnapshotGetService { + return NewSnapshotGetService(c).Repository(repository) +} + // SnapshotVerifyRepository verifies a snapshot repository. func (c *Client) SnapshotVerifyRepository(repository string) *SnapshotVerifyRepositoryService { return NewSnapshotVerifyRepositoryService(c).Repository(repository) } +// SnapshotRestore restores the specified indices from a given snapshot +func (c *Client) SnapshotRestore(repository, snapshot string) *SnapshotRestoreService { + return NewSnapshotRestoreService(c).Repository(repository).Snapshot(snapshot) +} + +// -- Scripting APIs -- + +// GetScript reads a stored script in Elasticsearch. +// Use PutScript for storing a script. +func (c *Client) GetScript() *GetScriptService { + return NewGetScriptService(c) +} + +// PutScript allows saving a stored script in Elasticsearch. +func (c *Client) PutScript() *PutScriptService { + return NewPutScriptService(c) +} + +// DeleteScript allows removing a stored script from Elasticsearch. +func (c *Client) DeleteScript() *DeleteScriptService { + return NewDeleteScriptService(c) +} + +// -- X-Pack General -- + +// XPackInfo gets information on the xpack plugins enabled on the cluster + +func (c *Client) XPackInfo() *XPackInfoService { + return NewXPackInfoService(c) +} + +// -- X-Pack Index Lifecycle Management -- + +// XPackIlmPutLifecycle adds or modifies an ilm policy. +func (c *Client) XPackIlmPutLifecycle() *XPackIlmPutLifecycleService { + return NewXPackIlmPutLifecycleService(c) +} + +// XPackIlmGettLifecycle gets an ilm policy. +func (c *Client) XPackIlmGetLifecycle() *XPackIlmGetLifecycleService { + return NewXPackIlmGetLifecycleService(c) +} + +// XPackIlmDeleteLifecycle deletes an ilm policy. +func (c *Client) XPackIlmDeleteLifecycle() *XPackIlmDeleteLifecycleService { + return NewXPackIlmDeleteLifecycleService(c) +} + +// -- X-Pack Security -- + +// XPackSecurityGetRoleMapping gets a role mapping. +func (c *Client) XPackSecurityGetRoleMapping(roleMappingName string) *XPackSecurityGetRoleMappingService { + return NewXPackSecurityGetRoleMappingService(c).Name(roleMappingName) +} + +// XPackSecurityPutRoleMapping adds a role mapping. +func (c *Client) XPackSecurityPutRoleMapping(roleMappingName string) *XPackSecurityPutRoleMappingService { + return NewXPackSecurityPutRoleMappingService(c).Name(roleMappingName) +} + +// XPackSecurityDeleteRoleMapping deletes a role mapping. +func (c *Client) XPackSecurityDeleteRoleMapping(roleMappingName string) *XPackSecurityDeleteRoleMappingService { + return NewXPackSecurityDeleteRoleMappingService(c).Name(roleMappingName) +} + +// XPackSecurityGetRole gets a role. +func (c *Client) XPackSecurityGetRole(roleName string) *XPackSecurityGetRoleService { + return NewXPackSecurityGetRoleService(c).Name(roleName) +} + +// XPackSecurityPutRole adds a role. +func (c *Client) XPackSecurityPutRole(roleName string) *XPackSecurityPutRoleService { + return NewXPackSecurityPutRoleService(c).Name(roleName) +} + +// XPackSecurityDeleteRole deletes a role. +func (c *Client) XPackSecurityDeleteRole(roleName string) *XPackSecurityDeleteRoleService { + return NewXPackSecurityDeleteRoleService(c).Name(roleName) +} + +// TODO: Clear role cache API +// https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-role-cache.html + +// -- X-Pack Watcher -- + +// XPackWatchPut adds a watch. +func (c *Client) XPackWatchPut(watchId string) *XPackWatcherPutWatchService { + return NewXPackWatcherPutWatchService(c).Id(watchId) +} + +// XPackWatchGet gets a watch. +func (c *Client) XPackWatchGet(watchId string) *XPackWatcherGetWatchService { + return NewXPackWatcherGetWatchService(c).Id(watchId) +} + +// XPackWatchDelete deletes a watch. +func (c *Client) XPackWatchDelete(watchId string) *XPackWatcherDeleteWatchService { + return NewXPackWatcherDeleteWatchService(c).Id(watchId) +} + +// XPackWatchExecute executes a watch. +func (c *Client) XPackWatchExecute() *XPackWatcherExecuteWatchService { + return NewXPackWatcherExecuteWatchService(c) +} + +// XPackWatchAck acknowledging a watch. +func (c *Client) XPackWatchAck(watchId string) *XPackWatcherAckWatchService { + return NewXPackWatcherAckWatchService(c).WatchId(watchId) +} + +// XPackWatchActivate activates a watch. +func (c *Client) XPackWatchActivate(watchId string) *XPackWatcherActivateWatchService { + return NewXPackWatcherActivateWatchService(c).WatchId(watchId) +} + +// XPackWatchDeactivate deactivates a watch. +func (c *Client) XPackWatchDeactivate(watchId string) *XPackWatcherDeactivateWatchService { + return NewXPackWatcherDeactivateWatchService(c).WatchId(watchId) +} + +// XPackWatchStats returns the current Watcher metrics. +func (c *Client) XPackWatchStats() *XPackWatcherStatsService { + return NewXPackWatcherStatsService(c) +} + +// XPackWatchStart starts a watch. +func (c *Client) XPackWatchStart() *XPackWatcherStartService { + return NewXPackWatcherStartService(c) +} + +// XPackWatchStop stops a watch. +func (c *Client) XPackWatchStop() *XPackWatcherStopService { + return NewXPackWatcherStopService(c) +} + +// XPackWatchRestart restarts a watch. +func (c *Client) XPackWatchRestart() *XPackWatcherRestartService { + return NewXPackWatcherRestartService(c) +} + // -- Helpers and shortcuts -- // ElasticsearchVersion returns the version number of Elasticsearch diff --git a/vendor/gopkg.in/olivere/elastic.v5/cluster_health.go b/vendor/gopkg.in/olivere/elastic.v6/cluster_health.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/cluster_health.go rename to vendor/gopkg.in/olivere/elastic.v6/cluster_health.go index a3ee72cd1e..f960cfe8ea 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/cluster_health.go +++ b/vendor/gopkg.in/olivere/elastic.v6/cluster_health.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // ClusterHealthService allows to get a very simple status on the health of the cluster. @@ -131,7 +131,7 @@ func (s *ClusterHealthService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.level != "" { params.Set("level", s.level) @@ -179,7 +179,11 @@ func (s *ClusterHealthService) Do(ctx context.Context) (*ClusterHealthResponse, } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v6/cluster_reroute.go b/vendor/gopkg.in/olivere/elastic.v6/cluster_reroute.go new file mode 100644 index 0000000000..7e30ded461 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/cluster_reroute.go @@ -0,0 +1,390 @@ +// 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 ( + "context" + "errors" + "fmt" + "net/url" + "strings" +) + +// ClusterRerouteService allows for manual changes to the allocation of +// individual shards in the cluster. For example, a shard can be moved from +// one node to another explicitly, an allocation can be cancelled, and +// an unassigned shard can be explicitly allocated to a specific node. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cluster-reroute.html +// for details. +type ClusterRerouteService struct { + client *Client + metrics []string + pretty bool + dryRun *bool + explain *bool + retryFailed *bool + masterTimeout string + timeout string + commands []AllocationCommand + body interface{} +} + +// NewClusterRerouteService creates a new ClusterRerouteService. +func NewClusterRerouteService(client *Client) *ClusterRerouteService { + return &ClusterRerouteService{ + client: client, + } +} + +// Metric limits the information returned to the specified metric. +// It can be one of: "_all", "blocks", "metadata", "nodes", "routing_table", "master_node", "version". +// Defaults to all but metadata. +func (s *ClusterRerouteService) Metric(metrics ...string) *ClusterRerouteService { + s.metrics = append(s.metrics, metrics...) + return s +} + +// DryRun indicates whether to simulate the operation only and return the +// resulting state. +func (s *ClusterRerouteService) DryRun(dryRun bool) *ClusterRerouteService { + s.dryRun = &dryRun + return s +} + +// Explain, when set to true, returns an explanation of why the commands +// can or cannot be executed. +func (s *ClusterRerouteService) Explain(explain bool) *ClusterRerouteService { + s.explain = &explain + return s +} + +// RetryFailed indicates whether to retry allocation of shards that are blocked +// due to too many subsequent allocation failures. +func (s *ClusterRerouteService) RetryFailed(retryFailed bool) *ClusterRerouteService { + s.retryFailed = &retryFailed + return s +} + +// MasterTimeout specifies an explicit timeout for connection to master. +func (s *ClusterRerouteService) MasterTimeout(masterTimeout string) *ClusterRerouteService { + s.masterTimeout = masterTimeout + return s +} + +// Timeout specifies an explicit operationtimeout. +func (s *ClusterRerouteService) Timeout(timeout string) *ClusterRerouteService { + s.timeout = timeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *ClusterRerouteService) Pretty(pretty bool) *ClusterRerouteService { + s.pretty = pretty + return s +} + +// Add adds one or more commands to be executed. +func (s *ClusterRerouteService) Add(commands ...AllocationCommand) *ClusterRerouteService { + s.commands = append(s.commands, commands...) + return s +} + +// Body specifies the body to be sent. +// If you specify Body, the commands passed via Add are ignored. +// In other words: Body takes precedence over Add. +func (s *ClusterRerouteService) Body(body interface{}) *ClusterRerouteService { + s.body = body + return s +} + +// buildURL builds the URL for the operation. +func (s *ClusterRerouteService) buildURL() (string, url.Values, error) { + // Build URL + path := "/_cluster/reroute" + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + if v := s.dryRun; v != nil { + params.Set("dry_run", fmt.Sprint(*v)) + } + if v := s.explain; v != nil { + params.Set("explain", fmt.Sprint(*v)) + } + if v := s.retryFailed; v != nil { + params.Set("retry_failed", fmt.Sprint(*v)) + } + if len(s.metrics) > 0 { + params.Set("metric", strings.Join(s.metrics, ",")) + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *ClusterRerouteService) Validate() error { + if s.body == nil && len(s.commands) == 0 { + return errors.New("missing allocate commands or raw body") + } + return nil +} + +// Do executes the operation. +func (s *ClusterRerouteService) Do(ctx context.Context) (*ClusterRerouteResponse, 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.body != nil { + body = s.body + } else { + commands := make([]interface{}, len(s.commands)) + for i, cmd := range s.commands { + src, err := cmd.Source() + if err != nil { + return nil, err + } + commands[i] = map[string]interface{}{ + cmd.Name(): src, + } + } + query := make(map[string]interface{}) + query["commands"] = commands + body = query + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(ClusterRerouteResponse) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// ClusterRerouteResponse is the response of ClusterRerouteService.Do. +type ClusterRerouteResponse struct { + State *ClusterStateResponse `json:"state"` + Explanations []RerouteExplanation `json:"explanations,omitempty"` +} + +// RerouteExplanation is returned in ClusterRerouteResponse if +// the "explain" parameter is set to "true". +type RerouteExplanation struct { + Command string `json:"command"` + Parameters map[string]interface{} `json:"parameters"` + Decisions []RerouteDecision `json:"decisions"` +} + +// RerouteDecision is a decision the decider made while rerouting. +type RerouteDecision interface{} + +// -- Allocation commands -- + +// AllocationCommand is a command to be executed in a call +// to Cluster Reroute API. +type AllocationCommand interface { + Name() string + Source() (interface{}, error) +} + +var _ AllocationCommand = (*MoveAllocationCommand)(nil) + +// MoveAllocationCommand moves a shard from a specific node to +// another node. +type MoveAllocationCommand struct { + index string + shardId int + fromNode string + toNode string +} + +// NewMoveAllocationCommand creates a new MoveAllocationCommand. +func NewMoveAllocationCommand(index string, shardId int, fromNode, toNode string) *MoveAllocationCommand { + return &MoveAllocationCommand{ + index: index, + shardId: shardId, + fromNode: fromNode, + toNode: toNode, + } +} + +// Name of the command in a request to the Cluster Reroute API. +func (cmd *MoveAllocationCommand) Name() string { return "move" } + +// Source generates the (inner) JSON to be used when serializing the command. +func (cmd *MoveAllocationCommand) Source() (interface{}, error) { + source := make(map[string]interface{}) + source["index"] = cmd.index + source["shard"] = cmd.shardId + source["from_node"] = cmd.fromNode + source["to_node"] = cmd.toNode + return source, nil +} + +var _ AllocationCommand = (*CancelAllocationCommand)(nil) + +// CancelAllocationCommand cancels relocation, or recovery of a given shard on a node. +type CancelAllocationCommand struct { + index string + shardId int + node string + allowPrimary bool +} + +// NewCancelAllocationCommand creates a new CancelAllocationCommand. +func NewCancelAllocationCommand(index string, shardId int, node string, allowPrimary bool) *CancelAllocationCommand { + return &CancelAllocationCommand{ + index: index, + shardId: shardId, + node: node, + allowPrimary: allowPrimary, + } +} + +// Name of the command in a request to the Cluster Reroute API. +func (cmd *CancelAllocationCommand) Name() string { return "cancel" } + +// Source generates the (inner) JSON to be used when serializing the command. +func (cmd *CancelAllocationCommand) Source() (interface{}, error) { + source := make(map[string]interface{}) + source["index"] = cmd.index + source["shard"] = cmd.shardId + source["node"] = cmd.node + source["allow_primary"] = cmd.allowPrimary + return source, nil +} + +var _ AllocationCommand = (*AllocateStalePrimaryAllocationCommand)(nil) + +// AllocateStalePrimaryAllocationCommand allocates an unassigned stale +// primary shard to a specific node. Use with extreme care as this will +// result in data loss. Allocation deciders are ignored. +type AllocateStalePrimaryAllocationCommand struct { + index string + shardId int + node string + acceptDataLoss bool +} + +// NewAllocateStalePrimaryAllocationCommand creates a new +// AllocateStalePrimaryAllocationCommand. +func NewAllocateStalePrimaryAllocationCommand(index string, shardId int, node string, acceptDataLoss bool) *AllocateStalePrimaryAllocationCommand { + return &AllocateStalePrimaryAllocationCommand{ + index: index, + shardId: shardId, + node: node, + acceptDataLoss: acceptDataLoss, + } +} + +// Name of the command in a request to the Cluster Reroute API. +func (cmd *AllocateStalePrimaryAllocationCommand) Name() string { return "allocate_stale_primary" } + +// Source generates the (inner) JSON to be used when serializing the command. +func (cmd *AllocateStalePrimaryAllocationCommand) Source() (interface{}, error) { + source := make(map[string]interface{}) + source["index"] = cmd.index + source["shard"] = cmd.shardId + source["node"] = cmd.node + source["accept_data_loss"] = cmd.acceptDataLoss + return source, nil +} + +var _ AllocationCommand = (*AllocateReplicaAllocationCommand)(nil) + +// AllocateReplicaAllocationCommand allocates an unassigned replica shard +// to a specific node. Checks if allocation deciders allow allocation. +type AllocateReplicaAllocationCommand struct { + index string + shardId int + node string +} + +// NewAllocateReplicaAllocationCommand creates a new +// AllocateReplicaAllocationCommand. +func NewAllocateReplicaAllocationCommand(index string, shardId int, node string) *AllocateReplicaAllocationCommand { + return &AllocateReplicaAllocationCommand{ + index: index, + shardId: shardId, + node: node, + } +} + +// Name of the command in a request to the Cluster Reroute API. +func (cmd *AllocateReplicaAllocationCommand) Name() string { return "allocate_replica" } + +// Source generates the (inner) JSON to be used when serializing the command. +func (cmd *AllocateReplicaAllocationCommand) Source() (interface{}, error) { + source := make(map[string]interface{}) + source["index"] = cmd.index + source["shard"] = cmd.shardId + source["node"] = cmd.node + return source, nil +} + +// AllocateEmptyPrimaryAllocationCommand allocates an unassigned empty +// primary shard to a specific node. Use with extreme care as this will +// result in data loss. Allocation deciders are ignored. +type AllocateEmptyPrimaryAllocationCommand struct { + index string + shardId int + node string + acceptDataLoss bool +} + +// NewAllocateEmptyPrimaryAllocationCommand creates a new +// AllocateEmptyPrimaryAllocationCommand. +func NewAllocateEmptyPrimaryAllocationCommand(index string, shardId int, node string, acceptDataLoss bool) *AllocateEmptyPrimaryAllocationCommand { + return &AllocateEmptyPrimaryAllocationCommand{ + index: index, + shardId: shardId, + node: node, + acceptDataLoss: acceptDataLoss, + } +} + +// Name of the command in a request to the Cluster Reroute API. +func (cmd *AllocateEmptyPrimaryAllocationCommand) Name() string { return "allocate_empty_primary" } + +// Source generates the (inner) JSON to be used when serializing the command. +func (cmd *AllocateEmptyPrimaryAllocationCommand) Source() (interface{}, error) { + source := make(map[string]interface{}) + source["index"] = cmd.index + source["shard"] = cmd.shardId + source["node"] = cmd.node + source["accept_data_loss"] = cmd.acceptDataLoss + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/cluster_state.go b/vendor/gopkg.in/olivere/elastic.v6/cluster_state.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v5/cluster_state.go rename to vendor/gopkg.in/olivere/elastic.v6/cluster_state.go index d6e608211d..a3369a3950 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/cluster_state.go +++ b/vendor/gopkg.in/olivere/elastic.v6/cluster_state.go @@ -10,12 +10,12 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // ClusterStateService allows to get a comprehensive state information of the whole cluster. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-state.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cluster-state.html // for details. type ClusterStateService struct { client *Client @@ -123,7 +123,7 @@ func (s *ClusterStateService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.allowNoIndices != nil { params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) @@ -165,7 +165,11 @@ func (s *ClusterStateService) Do(ctx context.Context) (*ClusterStateResponse, er } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -180,16 +184,16 @@ func (s *ClusterStateService) Do(ctx context.Context) (*ClusterStateResponse, er // ClusterStateResponse is the response of ClusterStateService.Do. type ClusterStateResponse struct { - ClusterName string `json:"cluster_name"` - Version int64 `json:"version"` - StateUUID string `json:"state_uuid"` - MasterNode string `json:"master_node"` - Blocks map[string]*clusterBlocks `json:"blocks"` - Nodes map[string]*discoveryNode `json:"nodes"` - Metadata *clusterStateMetadata `json:"metadata"` - RoutingTable map[string]*clusterStateRoutingTable `json:"routing_table"` - RoutingNodes *clusterStateRoutingNode `json:"routing_nodes"` - Customs map[string]interface{} `json:"customs"` + ClusterName string `json:"cluster_name"` + Version int64 `json:"version"` + StateUUID string `json:"state_uuid"` + MasterNode string `json:"master_node"` + Blocks map[string]*clusterBlocks `json:"blocks"` + Nodes map[string]*discoveryNode `json:"nodes"` + Metadata *clusterStateMetadata `json:"metadata"` + RoutingTable *clusterStateRoutingTable `json:"routing_table"` + RoutingNodes *clusterStateRoutingNode `json:"routing_nodes"` + Customs map[string]interface{} `json:"customs"` } type clusterBlocks struct { @@ -235,10 +239,10 @@ type clusterStateRoutingNode struct { } type indexTemplateMetaData struct { - Template string `json:"template"` // e.g. "store-*" - Order int `json:"order"` - Settings map[string]interface{} `json:"settings"` // index settings - Mappings map[string]interface{} `json:"mappings"` // type name -> mapping + IndexPatterns []string `json:"index_patterns"` // e.g. ["store-*"] + Order int `json:"order"` + Settings map[string]interface{} `json:"settings"` // index settings + Mappings map[string]interface{} `json:"mappings"` // type name -> mapping } type indexMetaData struct { diff --git a/vendor/gopkg.in/olivere/elastic.v5/cluster_stats.go b/vendor/gopkg.in/olivere/elastic.v6/cluster_stats.go similarity index 72% rename from vendor/gopkg.in/olivere/elastic.v5/cluster_stats.go rename to vendor/gopkg.in/olivere/elastic.v6/cluster_stats.go index 8c5374d0f1..4a51dfdc9a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/cluster_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v6/cluster_stats.go @@ -10,11 +10,11 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // ClusterStatsService is documented at -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/cluster-stats.html. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cluster-stats.html. type ClusterStatsService struct { client *Client pretty bool @@ -78,7 +78,7 @@ func (s *ClusterStatsService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.flatSettings != nil { params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings)) @@ -108,7 +108,11 @@ func (s *ClusterStatsService) Do(ctx context.Context) (*ClusterStatsResponse, er } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -125,23 +129,21 @@ func (s *ClusterStatsService) Do(ctx context.Context) (*ClusterStatsResponse, er type ClusterStatsResponse struct { Timestamp int64 `json:"timestamp"` ClusterName string `json:"cluster_name"` - ClusterUUID string `json:"uuid"` - Status string `json:"status"` + ClusterUUID string `json:"cluster_uuid"` + Status string `json:"status,omitempty"` // e.g. green Indices *ClusterStatsIndices `json:"indices"` Nodes *ClusterStatsNodes `json:"nodes"` } type ClusterStatsIndices struct { - Count int `json:"count"` - Shards *ClusterStatsIndicesShards `json:"shards"` - Docs *ClusterStatsIndicesDocs `json:"docs"` - Store *ClusterStatsIndicesStore `json:"store"` - FieldData *ClusterStatsIndicesFieldData `json:"fielddata"` - FilterCache *ClusterStatsIndicesFilterCache `json:"filter_cache"` - IdCache *ClusterStatsIndicesIdCache `json:"id_cache"` - Completion *ClusterStatsIndicesCompletion `json:"completion"` - Segments *ClusterStatsIndicesSegments `json:"segments"` - Percolate *ClusterStatsIndicesPercolate `json:"percolate"` + Count int `json:"count"` // number of indices + Shards *ClusterStatsIndicesShards `json:"shards"` + Docs *ClusterStatsIndicesDocs `json:"docs"` + Store *ClusterStatsIndicesStore `json:"store"` + FieldData *ClusterStatsIndicesFieldData `json:"fielddata"` + QueryCache *ClusterStatsIndicesQueryCache `json:"query_cache"` + Completion *ClusterStatsIndicesCompletion `json:"completion"` + Segments *ClusterStatsIndicesSegments `json:"segments"` } type ClusterStatsIndicesShards struct { @@ -175,10 +177,8 @@ type ClusterStatsIndicesDocs struct { } type ClusterStatsIndicesStore struct { - Size string `json:"size"` // e.g. "5.3gb" - SizeInBytes int64 `json:"size_in_bytes"` - ThrottleTime string `json:"throttle_time"` // e.g. "0s" - ThrottleTimeInMillis int64 `json:"throttle_time_in_millis"` + Size string `json:"size"` // e.g. "5.3gb" + SizeInBytes int64 `json:"size_in_bytes"` } type ClusterStatsIndicesFieldData struct { @@ -188,52 +188,56 @@ type ClusterStatsIndicesFieldData struct { Fields map[string]struct { MemorySize string `json:"memory_size"` // e.g. "61.3kb" MemorySizeInBytes int64 `json:"memory_size_in_bytes"` - } `json:"fields"` + } `json:"fields,omitempty"` } -type ClusterStatsIndicesFilterCache struct { +type ClusterStatsIndicesQueryCache struct { MemorySize string `json:"memory_size"` // e.g. "61.3kb" 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 ClusterStatsIndicesIdCache struct { - MemorySize string `json:"memory_size"` // e.g. "61.3kb" - MemorySizeInBytes int64 `json:"memory_size_in_bytes"` -} - type ClusterStatsIndicesCompletion struct { Size string `json:"size"` // e.g. "61.3kb" SizeInBytes int64 `json:"size_in_bytes"` Fields map[string]struct { Size string `json:"size"` // e.g. "61.3kb" SizeInBytes int64 `json:"size_in_bytes"` - } `json:"fields"` + } `json:"fields,omitempty"` } type ClusterStatsIndicesSegments struct { - Count int64 `json:"count"` - Memory string `json:"memory"` // e.g. "61.3kb" - MemoryInBytes int64 `json:"memory_in_bytes"` - IndexWriterMemory string `json:"index_writer_memory"` // e.g. "61.3kb" - IndexWriterMemoryInBytes int64 `json:"index_writer_memory_in_bytes"` - IndexWriterMaxMemory string `json:"index_writer_max_memory"` // e.g. "61.3kb" - IndexWriterMaxMemoryInBytes int64 `json:"index_writer_max_memory_in_bytes"` - VersionMapMemory string `json:"version_map_memory"` // e.g. "61.3kb" - VersionMapMemoryInBytes int64 `json:"version_map_memory_in_bytes"` - FixedBitSet string `json:"fixed_bit_set"` // e.g. "61.3kb" - FixedBitSetInBytes int64 `json:"fixed_bit_set_memory_in_bytes"` + Count int64 `json:"count"` + Memory string `json:"memory"` // e.g. "61.3kb" + MemoryInBytes int64 `json:"memory_in_bytes"` + TermsMemory string `json:"terms_memory"` // e.g. "61.3kb" + TermsMemoryInBytes int64 `json:"terms_memory_in_bytes"` + StoredFieldsMemory string `json:"stored_fields_memory"` // e.g. "61.3kb" + StoredFieldsMemoryInBytes int64 `json:"stored_fields_memory_in_bytes"` + NormsMemory string `json:"norms_memory"` // e.g. "61.3kb" + NormsMemoryInBytes int64 `json:"norms_memory_in_bytes"` + PointsMemory string `json:"points_memory"` // e.g. "61.3kb" + PointsMemoryInBytes int64 `json:"points_memory_in_bytes"` + DocValuesMemory string `json:"doc_values_memory"` // e.g. "61.3kb" + DocValuesMemoryInBytes int64 `json:"doc_values_memory_in_bytes"` + IndexWriterMemory string `json:"index_writer_memory"` // e.g. "61.3kb" + IndexWriterMemoryInBytes int64 `json:"index_writer_memory_in_bytes"` + VersionMapMemory string `json:"version_map_memory"` // e.g. "61.3kb" + VersionMapMemoryInBytes int64 `json:"version_map_memory_in_bytes"` + FixedBitSet string `json:"fixed_bit_set"` // e.g. "61.3kb" + FixedBitSetInBytes int64 `json:"fixed_bit_set_memory_in_bytes"` + FileSizes map[string]*ClusterStatsIndicesSegmentsFile `json:"file_sizes"` } -type ClusterStatsIndicesPercolate struct { - Total int64 `json:"total"` - // TODO(oe) The JSON tag here is wrong as of ES 1.5.2 it seems - Time string `json:"get_time"` // e.g. "1s" - TimeInBytes int64 `json:"time_in_millis"` - Current int64 `json:"current"` - MemorySize string `json:"memory_size"` // e.g. "61.3kb" - MemorySizeInBytes int64 `json:"memory_sitze_in_bytes"` - Queries int64 `json:"queries"` +type ClusterStatsIndicesSegmentsFile struct { + Size string `json:"size"` // e.g. "61.3kb" + SizeInBytes int64 `json:"size_in_bytes"` + Description string `json:"description,omitempty"` } // --- diff --git a/vendor/gopkg.in/olivere/elastic.v5/connection.go b/vendor/gopkg.in/olivere/elastic.v6/connection.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/connection.go rename to vendor/gopkg.in/olivere/elastic.v6/connection.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/count.go b/vendor/gopkg.in/olivere/elastic.v6/count.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/count.go rename to vendor/gopkg.in/olivere/elastic.v6/count.go index be6960d00c..bcd929a0ce 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/count.go +++ b/vendor/gopkg.in/olivere/elastic.v6/count.go @@ -8,10 +8,9 @@ import ( "context" "fmt" "net/url" - "strconv" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // CountService is a convenient service for determining the @@ -216,7 +215,7 @@ func (s *CountService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.allowNoIndices != nil { params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) @@ -258,7 +257,7 @@ func (s *CountService) buildURL() (string, url.Values, error) { params.Set("routing", s.routing) } if s.terminateAfter != nil { - params.Set("terminate_after", strconv.Itoa(*s.terminateAfter)) + params.Set("terminate_after", fmt.Sprintf("%v", *s.terminateAfter)) } return path, params, nil } @@ -298,7 +297,12 @@ func (s *CountService) Do(ctx context.Context) (int64, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) if err != nil { return 0, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/decoder.go b/vendor/gopkg.in/olivere/elastic.v6/decoder.go similarity index 68% rename from vendor/gopkg.in/olivere/elastic.v5/decoder.go rename to vendor/gopkg.in/olivere/elastic.v6/decoder.go index 9cd2cf720d..9133ccd910 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/decoder.go +++ b/vendor/gopkg.in/olivere/elastic.v6/decoder.go @@ -5,6 +5,7 @@ package elastic import ( + "bytes" "encoding/json" ) @@ -24,3 +25,14 @@ type DefaultDecoder struct{} func (u *DefaultDecoder) Decode(data []byte, v interface{}) error { return json.Unmarshal(data, v) } + +// NumberDecoder uses json.NewDecoder, with UseNumber() enabled, from +// the Go standard library to decode JSON data. +type NumberDecoder struct{} + +// Decode decodes with json.Unmarshal from the Go standard library. +func (u *NumberDecoder) Decode(data []byte, v interface{}) error { + dec := json.NewDecoder(bytes.NewReader(data)) + dec.UseNumber() + return dec.Decode(v) +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/delete.go b/vendor/gopkg.in/olivere/elastic.v6/delete.go similarity index 82% rename from vendor/gopkg.in/olivere/elastic.v5/delete.go rename to vendor/gopkg.in/olivere/elastic.v6/delete.go index 194277ebde..a7c5aa8544 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/delete.go +++ b/vendor/gopkg.in/olivere/elastic.v6/delete.go @@ -7,17 +7,16 @@ package elastic import ( "context" "fmt" + "net/http" "net/url" - "net/http" - - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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/5.2/docs-delete.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-delete.html // for details. type DeleteService struct { client *Client @@ -32,6 +31,8 @@ type DeleteService struct { waitForActiveShards string parent string refresh string + ifSeqNo *int64 + ifPrimaryTerm *int64 } // NewDeleteService creates a new DeleteService. @@ -100,11 +101,28 @@ func (s *DeleteService) Parent(parent string) *DeleteService { } // Refresh the index after performing the operation. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html +// for details. func (s *DeleteService) Refresh(refresh string) *DeleteService { s.refresh = refresh return s } +// IfSeqNo indicates to only perform the delete operation if the last +// operation that has changed the document has the specified sequence number. +func (s *DeleteService) IfSeqNo(seqNo int64) *DeleteService { + s.ifSeqNo = &seqNo + return s +} + +// IfPrimaryTerm indicates to only perform the delete operation if the +// last operation that has changed the document has the specified primary term. +func (s *DeleteService) IfPrimaryTerm(primaryTerm int64) *DeleteService { + s.ifPrimaryTerm = &primaryTerm + return s +} + // Pretty indicates that the JSON response be indented and human readable. func (s *DeleteService) Pretty(pretty bool) *DeleteService { s.pretty = pretty @@ -126,7 +144,7 @@ func (s *DeleteService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.refresh != "" { params.Set("refresh", s.refresh) @@ -149,6 +167,12 @@ func (s *DeleteService) buildURL() (string, url.Values, error) { if s.parent != "" { params.Set("parent", s.parent) } + if v := s.ifSeqNo; v != nil { + params.Set("if_seq_no", fmt.Sprintf("%d", *v)) + } + if v := s.ifPrimaryTerm; v != nil { + params.Set("if_primary_term", fmt.Sprintf("%d", *v)) + } return path, params, nil } @@ -186,7 +210,12 @@ func (s *DeleteService) Do(ctx context.Context) (*DeleteResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil, http.StatusNotFound) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + IgnoreErrors: []int{http.StatusNotFound}, + }) if err != nil { return nil, err } @@ -219,5 +248,4 @@ type DeleteResponse struct { PrimaryTerm int64 `json:"_primary_term,omitempty"` Status int `json:"status,omitempty"` ForcedRefresh bool `json:"forced_refresh,omitempty"` - Found bool `json:"found,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/delete_by_query.go b/vendor/gopkg.in/olivere/elastic.v6/delete_by_query.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v5/delete_by_query.go rename to vendor/gopkg.in/olivere/elastic.v6/delete_by_query.go index a890bd84fa..b277ebc3bd 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/delete_by_query.go +++ b/vendor/gopkg.in/olivere/elastic.v6/delete_by_query.go @@ -7,14 +7,15 @@ package elastic import ( "context" "fmt" + "net/http" "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // DeleteByQueryService deletes documents that match a query. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-delete-by-query.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-delete-by-query.html. type DeleteByQueryService struct { client *Client index []string @@ -48,6 +49,7 @@ type DeleteByQueryService struct { searchTimeout string searchType string size *int + slices interface{} sort []string stats []string storedFields []string @@ -240,6 +242,9 @@ func (s *DeleteByQueryService) Query(query Query) *DeleteByQueryService { } // Refresh indicates whether the effected indexes should be refreshed. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html +// for details. func (s *DeleteByQueryService) Refresh(refresh string) *DeleteByQueryService { s.refresh = refresh return s @@ -298,6 +303,16 @@ func (s *DeleteByQueryService) Size(size int) *DeleteByQueryService { return s } +// Slices represents the number of slices (default: 1). +// It used to be a number, but can be set to "auto" as of 6.7. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-delete-by-query.html#docs-delete-by-query-automatic-slice +// for details. +func (s *DeleteByQueryService) Slices(slices interface{}) *DeleteByQueryService { + s.slices = slices + return s +} + // Sort is a list of : pairs. func (s *DeleteByQueryService) Sort(sort ...string) *DeleteByQueryService { s.sort = append(s.sort, sort...) @@ -504,6 +519,9 @@ func (s *DeleteByQueryService) buildURL() (string, url.Values, error) { if s.size != nil { params.Set("size", fmt.Sprintf("%d", *s.size)) } + if s.slices != nil { + params.Set("slices", fmt.Sprintf("%v", s.slices)) + } if len(s.sort) > 0 { params.Set("sort", strings.Join(s.sort, ",")) } @@ -598,7 +616,12 @@ func (s *DeleteByQueryService) Do(ctx context.Context) (*BulkIndexByScrollRespon } // Get response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -611,19 +634,75 @@ func (s *DeleteByQueryService) Do(ctx context.Context) (*BulkIndexByScrollRespon return ret, nil } +// DoAsync executes the delete-by-query operation asynchronously by starting a new task. +// Callers need to use the Task Management API to watch the outcome of the reindexing +// operation. +func (s *DeleteByQueryService) DoAsync(ctx context.Context) (*StartTaskResult, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // DoAsync only makes sense with WaitForCompletion set to true + if s.waitForCompletion != nil && *s.waitForCompletion { + return nil, fmt.Errorf("cannot start a task with WaitForCompletion set to true") + } + f := false + s.waitForCompletion = &f + + // 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 HTTP response + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(StartTaskResult) + 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"` - SliceId *int64 `json:"slice_id,omitempty"` - TimedOut bool `json:"timed_out"` - Total int64 `json:"total"` - Updated int64 `json:"updated,omitempty"` - Created int64 `json:"created,omitempty"` - Deleted int64 `json:"deleted"` - Batches int64 `json:"batches"` - VersionConflicts int64 `json:"version_conflicts"` - Noops int64 `json:"noops"` + Header http.Header `json:"-"` + Took int64 `json:"took"` + SliceId *int64 `json:"slice_id,omitempty"` + TimedOut bool `json:"timed_out"` + Total int64 `json:"total"` + Updated int64 `json:"updated,omitempty"` + Created int64 `json:"created,omitempty"` + 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"` diff --git a/vendor/gopkg.in/olivere/elastic.v5/doc.go b/vendor/gopkg.in/olivere/elastic.v6/doc.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/doc.go rename to vendor/gopkg.in/olivere/elastic.v6/doc.go diff --git a/vendor/gopkg.in/olivere/elastic.v6/docker-compose.yml b/vendor/gopkg.in/olivere/elastic.v6/docker-compose.yml new file mode 100644 index 0000000000..8984588fab --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/docker-compose.yml @@ -0,0 +1,55 @@ +version: '3' + +services: + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.2 + hostname: elasticsearch + environment: + - cluster.name=elasticsearch + - bootstrap.memory_lock=true + # - http.host=0.0.0.0 + # - transport.host=127.0.0.1 + # - network.host=_local_ + - network.publish_host=127.0.0.1 + - "ES_JAVA_OPTS=-Xms1g -Xmx1g" + ulimits: + nproc: 65536 + nofile: + soft: 65536 + hard: 65536 + memlock: + soft: -1 + hard: -1 + # volumes: + # - ./data/elasticsearch:/usr/share/elasticsearch/data + ports: + - 9200:9200 + platinum: + image: docker.elastic.co/elasticsearch/elasticsearch:6.8.2 + hostname: elasticsearch-platinum + environment: + - cluster.name=platinum + - bootstrap.memory_lock=true + - xpack.ilm.enabled=true + - xpack.license.self_generated.type=trial + - xpack.security.enabled=true + - xpack.watcher.enabled=true + # - http.host=0.0.0.0 + # - transport.host=127.0.0.1 + # - network.host=_local_ + - http.port=9210 + - network.publish_host=127.0.0.1 + - "ES_JAVA_OPTS=-Xms1g -Xmx1g" + - ELASTIC_PASSWORD=elastic + ulimits: + nproc: 65536 + nofile: + soft: 65536 + hard: 65536 + memlock: + soft: -1 + hard: -1 + # volumes: + # - ./data/elasticsearch-platinum:/usr/share/elasticsearch/data + ports: + - 9210:9210 diff --git a/vendor/gopkg.in/olivere/elastic.v6/docvalue_field.go b/vendor/gopkg.in/olivere/elastic.v6/docvalue_field.go new file mode 100644 index 0000000000..e73cd24b15 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/docvalue_field.go @@ -0,0 +1,42 @@ +// 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 + +// DocvalueField represents a docvalue field, its name and +// its format (optional). +type DocvalueField struct { + Field string + Format string +} + +// Source serializes the DocvalueField into JSON. +func (d DocvalueField) Source() (interface{}, error) { + if d.Format == "" { + return d.Field, nil + } + return map[string]interface{}{ + "field": d.Field, + "format": d.Format, + }, nil +} + +// DocvalueFields is a slice of DocvalueField instances. +type DocvalueFields []DocvalueField + +// Source serializes the DocvalueFields into JSON. +func (d DocvalueFields) Source() (interface{}, error) { + if d == nil { + return nil, nil + } + v := make([]interface{}, 0) + for _, f := range d { + src, err := f.Source() + if err != nil { + return nil, err + } + v = append(v, src) + } + return v, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/errors.go b/vendor/gopkg.in/olivere/elastic.v6/errors.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/errors.go rename to vendor/gopkg.in/olivere/elastic.v6/errors.go index 3463268e39..3dbc037184 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/errors.go +++ b/vendor/gopkg.in/olivere/elastic.v6/errors.go @@ -137,6 +137,14 @@ func IsConflict(err interface{}) bool { return IsStatusCode(err, http.StatusConflict) } +// IsForbidden returns true if the given error indicates that Elasticsearch +// returned HTTP status 403. This happens e.g. due to a missing license. +// The err parameter can be of type *elastic.Error, elastic.Error, +// *http.Response or int (indicating the HTTP status code). +func IsForbidden(err interface{}) bool { + return IsStatusCode(err, http.StatusForbidden) +} + // IsStatusCode returns true if the given error indicates that the Elasticsearch // operation returned the specified HTTP status code. The err parameter can be of // type *http.Response, *Error, Error, or int (indicating the HTTP status code). diff --git a/vendor/gopkg.in/olivere/elastic.v5/exists.go b/vendor/gopkg.in/olivere/elastic.v6/exists.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v5/exists.go rename to vendor/gopkg.in/olivere/elastic.v6/exists.go index 7cae2bde81..011b933804 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/exists.go +++ b/vendor/gopkg.in/olivere/elastic.v6/exists.go @@ -10,12 +10,12 @@ import ( "net/http" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // ExistsService checks for the existence of a document using HEAD. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-get.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-get.html // for details. type ExistsService struct { client *Client @@ -69,6 +69,9 @@ func (s *ExistsService) Realtime(realtime bool) *ExistsService { } // Refresh the shard containing the document before performing the operation. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html +// for details. func (s *ExistsService) Refresh(refresh string) *ExistsService { s.refresh = refresh return s @@ -107,7 +110,7 @@ func (s *ExistsService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.realtime != nil { params.Set("realtime", fmt.Sprintf("%v", *s.realtime)) @@ -159,7 +162,12 @@ func (s *ExistsService) Do(ctx context.Context) (bool, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "HEAD", + Path: path, + Params: params, + IgnoreErrors: []int{404}, + }) if err != nil { return false, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/explain.go b/vendor/gopkg.in/olivere/elastic.v6/explain.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/explain.go rename to vendor/gopkg.in/olivere/elastic.v6/explain.go index bdfa00f1df..88e82f95d4 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/explain.go +++ b/vendor/gopkg.in/olivere/elastic.v6/explain.go @@ -10,12 +10,12 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // ExplainService computes a score explanation for a query and // a specific document. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-explain.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-explain.html. type ExplainService struct { client *Client pretty bool @@ -208,7 +208,7 @@ func (s *ExplainService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if len(s.xSource) > 0 { params.Set("_source", strings.Join(s.xSource, ",")) @@ -298,7 +298,12 @@ func (s *ExplainService) Do(ctx context.Context) (*ExplainResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/fetch_source_context.go b/vendor/gopkg.in/olivere/elastic.v6/fetch_source_context.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/fetch_source_context.go rename to vendor/gopkg.in/olivere/elastic.v6/fetch_source_context.go index 53e7fcd90b..82703f32d8 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/fetch_source_context.go +++ b/vendor/gopkg.in/olivere/elastic.v6/fetch_source_context.go @@ -14,7 +14,7 @@ import ( // with various endpoints, e.g. when searching for documents, retrieving // individual documents, or even updating documents. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-request-source-filtering.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-source-filtering.html // for details. type FetchSourceContext struct { fetchSource bool diff --git a/vendor/gopkg.in/olivere/elastic.v5/field_caps.go b/vendor/gopkg.in/olivere/elastic.v6/field_caps.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v5/field_caps.go rename to vendor/gopkg.in/olivere/elastic.v6/field_caps.go index 78b343370f..e2c07527cb 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/field_caps.go +++ b/vendor/gopkg.in/olivere/elastic.v6/field_caps.go @@ -11,12 +11,12 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // FieldCapsService allows retrieving the capabilities of fields among multiple indices. // -// See http://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-field-caps.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-field-caps.html // for details type FieldCapsService struct { client *Client @@ -152,7 +152,13 @@ func (s *FieldCapsService) Do(ctx context.Context) (*FieldCapsResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body, http.StatusNotFound) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + IgnoreErrors: []int{http.StatusNotFound}, + }) if err != nil { return nil, err } @@ -182,9 +188,13 @@ type FieldCapsRequest struct { // FieldCapsResponse contains field capabilities. type FieldCapsResponse struct { - Fields map[string]FieldCaps `json:"fields,omitempty"` + Fields map[string]FieldCapsType `json:"fields,omitempty"` // Name -> type -> caps } +// FieldCapsType represents a mapping from type (e.g. keyword) +// to capabilities. +type FieldCapsType map[string]FieldCaps // type -> caps + // FieldCaps contains capabilities of an individual field. type FieldCaps struct { Type string `json:"type"` diff --git a/vendor/gopkg.in/olivere/elastic.v5/geo_point.go b/vendor/gopkg.in/olivere/elastic.v6/geo_point.go similarity index 89% rename from vendor/gopkg.in/olivere/elastic.v5/geo_point.go rename to vendor/gopkg.in/olivere/elastic.v6/geo_point.go index fb243671d2..4ef0e1ad47 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/geo_point.go +++ b/vendor/gopkg.in/olivere/elastic.v6/geo_point.go @@ -5,6 +5,7 @@ package elastic import ( + "encoding/json" "fmt" "strconv" "strings" @@ -24,6 +25,11 @@ func (pt *GeoPoint) Source() map[string]float64 { } } +// MarshalJSON encodes the GeoPoint to JSON. +func (pt *GeoPoint) MarshalJSON() ([]byte, error) { + return json.Marshal(pt.Source()) +} + // GeoPointFromLatLon initializes a new GeoPoint by latitude and longitude. func GeoPointFromLatLon(lat, lon float64) *GeoPoint { return &GeoPoint{Lat: lat, Lon: lon} diff --git a/vendor/gopkg.in/olivere/elastic.v5/get.go b/vendor/gopkg.in/olivere/elastic.v6/get.go similarity index 82% rename from vendor/gopkg.in/olivere/elastic.v5/get.go rename to vendor/gopkg.in/olivere/elastic.v6/get.go index ef569e1740..b267a3acd6 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/get.go +++ b/vendor/gopkg.in/olivere/elastic.v6/get.go @@ -11,13 +11,13 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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/5.2/docs-get.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-get.html // for details. type GetService struct { client *Client @@ -103,6 +103,9 @@ func (s *GetService) FetchSourceContext(fetchSourceContext *FetchSourceContext) } // Refresh the shard containing the document before performing the operation. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html +// for details. func (s *GetService) Refresh(refresh string) *GetService { s.refresh = refresh return s @@ -172,7 +175,7 @@ func (s *GetService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.routing != "" { params.Set("routing", s.routing) @@ -223,7 +226,11 @@ func (s *GetService) Do(ctx context.Context) (*GetResult, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -240,16 +247,18 @@ func (s *GetService) Do(ctx context.Context) (*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) - 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 + SeqNo *int64 `json:"_seq_no"` + PrimaryTerm *int64 `json:"_primary_term"` + 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.v5/highlight.go b/vendor/gopkg.in/olivere/elastic.v6/highlight.go similarity index 99% rename from vendor/gopkg.in/olivere/elastic.v5/highlight.go rename to vendor/gopkg.in/olivere/elastic.v6/highlight.go index 579072a8de..6955742c3d 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/highlight.go +++ b/vendor/gopkg.in/olivere/elastic.v6/highlight.go @@ -6,7 +6,7 @@ package elastic // Highlight allows highlighting search results on one or more fields. // For details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-highlighting.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-highlighting.html type Highlight struct { fields []*HighlighterField tagsSchema *string diff --git a/vendor/gopkg.in/olivere/elastic.v5/index.go b/vendor/gopkg.in/olivere/elastic.v6/index.go similarity index 86% rename from vendor/gopkg.in/olivere/elastic.v5/index.go rename to vendor/gopkg.in/olivere/elastic.v6/index.go index 0fc7b6fddb..42cdacc69b 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/index.go +++ b/vendor/gopkg.in/olivere/elastic.v6/index.go @@ -9,13 +9,13 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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/5.2/docs-index_.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-index_.html // for details. type IndexService struct { client *Client @@ -34,6 +34,8 @@ type IndexService struct { refresh string waitForActiveShards string pipeline string + ifSeqNo *int64 + ifPrimaryTerm *int64 bodyJson interface{} bodyString string } @@ -80,6 +82,9 @@ func (s *IndexService) Pipeline(pipeline string) *IndexService { } // Refresh the index after performing the operation. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html +// for details. func (s *IndexService) Refresh(refresh string) *IndexService { s.refresh = refresh return s @@ -139,6 +144,20 @@ func (s *IndexService) VersionType(versionType string) *IndexService { return s } +// IfSeqNo indicates to only perform the index operation if the last +// operation that has changed the document has the specified sequence number. +func (s *IndexService) IfSeqNo(seqNo int64) *IndexService { + s.ifSeqNo = &seqNo + return s +} + +// IfPrimaryTerm indicates to only perform the index operation if the +// last operation that has changed the document has the specified primary term. +func (s *IndexService) IfPrimaryTerm(primaryTerm int64) *IndexService { + s.ifPrimaryTerm = &primaryTerm + return s +} + // Pretty indicates that the JSON response be indented and human readable. func (s *IndexService) Pretty(pretty bool) *IndexService { s.pretty = pretty @@ -172,7 +191,7 @@ func (s *IndexService) buildURL() (string, string, url.Values, error) { }) } else { // Automatic ID generation - // See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html#index-creation + // See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-index_.html#index-creation method = "POST" path, err = uritemplates.Expand("/{index}/{type}/", map[string]string{ "index": s.index, @@ -186,7 +205,7 @@ func (s *IndexService) buildURL() (string, string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.waitForActiveShards != "" { params.Set("wait_for_active_shards", s.waitForActiveShards) @@ -221,6 +240,12 @@ func (s *IndexService) buildURL() (string, string, url.Values, error) { if s.versionType != "" { params.Set("version_type", s.versionType) } + if v := s.ifSeqNo; v != nil { + params.Set("if_seq_no", fmt.Sprintf("%d", *v)) + } + if v := s.ifPrimaryTerm; v != nil { + params.Set("if_primary_term", fmt.Sprintf("%d", *v)) + } return method, path, params, nil } @@ -264,7 +289,12 @@ func (s *IndexService) Do(ctx context.Context) (*IndexResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, method, path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: method, + Path: path, + Params: params, + Body: 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.v6/indices_analyze.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v5/indices_analyze.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_analyze.go index b9000f128a..5cd0049824 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_analyze.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_analyze.go @@ -9,13 +9,13 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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 +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-analyze.html // for detail. type IndicesAnalyzeService struct { client *Client @@ -152,7 +152,7 @@ func (s *IndicesAnalyzeService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.format != "" { params.Set("format", s.format) @@ -185,11 +185,16 @@ func (s *IndicesAnalyzeService) Do(ctx context.Context) (*IndicesAnalyzeResponse } 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 + // See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-analyze.html body = s.request } - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -233,11 +238,12 @@ type IndicesAnalyzeResponse struct { } 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"` + Token string `json:"token"` + StartOffset int `json:"start_offset"` + EndOffset int `json:"end_offset"` + Type string `json:"type"` + Position int `json:"position"` + PositionLength int `json:"positionLength"` // seems to be wrong in 6.8 (no snake_case), see https://github.com/elastic/elasticsearch/blob/6.8/server/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeResponse.java } type IndicesAnalyzeResponseDetail struct { diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_close.go b/vendor/gopkg.in/olivere/elastic.v6/indices_close.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v5/indices_close.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_close.go index 9388bc973d..f04de6d6f5 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_close.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_close.go @@ -9,12 +9,12 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesCloseService closes an index. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-open-close.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-open-close.html // for details. type IndicesCloseService struct { client *Client @@ -134,7 +134,11 @@ func (s *IndicesCloseService) Do(ctx context.Context) (*IndicesCloseResponse, er } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -149,5 +153,7 @@ func (s *IndicesCloseService) Do(ctx context.Context) (*IndicesCloseResponse, er // IndicesCloseResponse is the response of IndicesCloseService.Do. type IndicesCloseResponse struct { - Acknowledged bool `json:"acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_create.go b/vendor/gopkg.in/olivere/elastic.v6/indices_create.go similarity index 66% rename from vendor/gopkg.in/olivere/elastic.v5/indices_create.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_create.go index dfd17ac098..ee01d19ec7 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_create.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_create.go @@ -9,21 +9,23 @@ import ( "errors" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesCreateService creates a new index. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-create-index.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-create-index.html // for details. type IndicesCreateService struct { - client *Client - pretty bool - index string - timeout string - masterTimeout string - bodyJson interface{} - bodyString string + client *Client + pretty bool + index string + timeout string + masterTimeout string + includeTypeName *bool + updateAllTypes *bool + bodyJson interface{} + bodyString string } // NewIndicesCreateService returns a new IndicesCreateService. @@ -49,6 +51,20 @@ func (s *IndicesCreateService) MasterTimeout(masterTimeout string) *IndicesCreat return s } +// IncludeTypeName indicates whether a type should be expected in the +// body of the mappings. +func (s *IndicesCreateService) IncludeTypeName(include bool) *IndicesCreateService { + s.includeTypeName = &include + return s +} + +// UpdateAllTypes indicates whether to update the mapping for all fields +// with the same name across all types or not. +func (s *IndicesCreateService) UpdateAllTypes(update bool) *IndicesCreateService { + s.updateAllTypes = &update + return s +} + // Body specifies the configuration of the index as a string. // It is an alias for BodyString. func (b *IndicesCreateService) Body(body string) *IndicesCreateService { @@ -91,7 +107,7 @@ func (b *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, er params := make(url.Values) if b.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if b.masterTimeout != "" { params.Set("master_timeout", b.masterTimeout) @@ -99,6 +115,20 @@ func (b *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, er if b.timeout != "" { params.Set("timeout", b.timeout) } + if v := b.includeTypeName; v != nil { + if *v { + params.Set("include_type_name", "true") + } else { + params.Set("include_type_name", "false") + } + } + if v := b.updateAllTypes; v != nil && *v { + if *v { + params.Set("update_all_types", "true") + } else { + params.Set("update_all_types", "false") + } + } // Setup HTTP request body var body interface{} @@ -109,7 +139,12 @@ func (b *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, er } // Get response - res, err := b.client.PerformRequest(ctx, "PUT", path, params, body) + res, err := b.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -125,6 +160,7 @@ func (b *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, er // IndicesCreateResult is the outcome of creating a new index. type IndicesCreateResult struct { - Acknowledged bool `json:"acknowledged"` - ShardsAcknowledged bool `json:"shards_acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_delete.go b/vendor/gopkg.in/olivere/elastic.v6/indices_delete.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/indices_delete.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_delete.go index 9971852370..22a7e02f49 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_delete.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_delete.go @@ -10,12 +10,12 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesDeleteService allows to delete existing indices. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-delete-index.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-delete-index.html // for details. type IndicesDeleteService struct { client *Client @@ -71,7 +71,7 @@ func (s *IndicesDeleteService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.timeout != "" { params.Set("timeout", s.timeout) @@ -108,7 +108,11 @@ func (s *IndicesDeleteService) Do(ctx context.Context) (*IndicesDeleteResponse, } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_delete_template.go b/vendor/gopkg.in/olivere/elastic.v6/indices_delete_template.go similarity index 86% rename from vendor/gopkg.in/olivere/elastic.v5/indices_delete_template.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_delete_template.go index d1b88d4bb9..dc8509c06e 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_delete_template.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_delete_template.go @@ -9,11 +9,11 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesDeleteTemplateService deletes index templates. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-templates.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-templates.html. type IndicesDeleteTemplateService struct { client *Client pretty bool @@ -66,7 +66,7 @@ func (s *IndicesDeleteTemplateService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.timeout != "" { params.Set("timeout", s.timeout) @@ -103,7 +103,11 @@ func (s *IndicesDeleteTemplateService) Do(ctx context.Context) (*IndicesDeleteTe } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -118,5 +122,7 @@ func (s *IndicesDeleteTemplateService) Do(ctx context.Context) (*IndicesDeleteTe // IndicesDeleteTemplateResponse is the response of IndicesDeleteTemplateService.Do. type IndicesDeleteTemplateResponse struct { - Acknowledged bool `json:"acknowledged,omitempty"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_exists.go b/vendor/gopkg.in/olivere/elastic.v6/indices_exists.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v5/indices_exists.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_exists.go index 928006e09f..cc15ebce89 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_exists.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_exists.go @@ -11,12 +11,12 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesExistsService checks if an index or indices exist or not. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-exists.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-exists.html // for details. type IndicesExistsService struct { client *Client @@ -90,7 +90,7 @@ func (s *IndicesExistsService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.local != nil { params.Set("local", fmt.Sprintf("%v", *s.local)) @@ -133,7 +133,12 @@ func (s *IndicesExistsService) Do(ctx context.Context) (bool, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "HEAD", + Path: path, + Params: params, + IgnoreErrors: []int{404}, + }) if err != nil { return false, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_exists_template.go b/vendor/gopkg.in/olivere/elastic.v6/indices_exists_template.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/indices_exists_template.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_exists_template.go index 873d8c00c3..40b06e895e 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_exists_template.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_exists_template.go @@ -10,7 +10,7 @@ import ( "net/http" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesExistsTemplateService checks if a given template exists. @@ -62,7 +62,7 @@ func (s *IndicesExistsTemplateService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.local != nil { params.Set("local", fmt.Sprintf("%v", *s.local)) @@ -96,7 +96,12 @@ func (s *IndicesExistsTemplateService) Do(ctx context.Context) (bool, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "HEAD", + Path: path, + Params: params, + IgnoreErrors: []int{404}, + }) if err != nil { return false, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_exists_type.go b/vendor/gopkg.in/olivere/elastic.v6/indices_exists_type.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v5/indices_exists_type.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_exists_type.go index 95eb8f1d39..1238bdf6cb 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_exists_type.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_exists_type.go @@ -11,12 +11,12 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesExistsTypeService checks if one or more types exist in one or more indices. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-types-exists.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-types-exists.html // for details. type IndicesExistsTypeService struct { client *Client @@ -97,7 +97,7 @@ func (s *IndicesExistsTypeService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.ignoreUnavailable != nil { params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) @@ -143,7 +143,12 @@ func (s *IndicesExistsTypeService) Do(ctx context.Context) (bool, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "HEAD", path, params, nil, 404) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "HEAD", + Path: path, + Params: params, + IgnoreErrors: []int{404}, + }) if err != nil { return false, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_flush.go b/vendor/gopkg.in/olivere/elastic.v6/indices_flush.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/indices_flush.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_flush.go index 27fadb9948..03df1ab449 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_flush.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_flush.go @@ -10,14 +10,14 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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/5.2/indices-flush.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-flush.html // for details. type IndicesFlushService struct { client *Client @@ -110,7 +110,7 @@ func (s *IndicesFlushService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.force != nil { params.Set("force", fmt.Sprintf("%v", *s.force)) @@ -149,7 +149,11 @@ func (s *IndicesFlushService) Do(ctx context.Context) (*IndicesFlushResponse, er } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v6/indices_flush_synced.go b/vendor/gopkg.in/olivere/elastic.v6/indices_flush_synced.go new file mode 100644 index 0000000000..c52bc4b381 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_flush_synced.go @@ -0,0 +1,230 @@ +// 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + "strings" + + "github.com/olivere/elastic/uritemplates" +) + +// IndicesSyncedFlushService performs a normal flush, then adds a generated +// unique marked (sync_id) to all shards. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-synced-flush.html +// for details. +type IndicesSyncedFlushService struct { + client *Client + pretty bool + index []string + ignoreUnavailable *bool + allowNoIndices *bool + expandWildcards string +} + +// NewIndicesSyncedFlushService creates a new IndicesSyncedFlushService. +func NewIndicesSyncedFlushService(client *Client) *IndicesSyncedFlushService { + return &IndicesSyncedFlushService{ + client: client, + } +} + +// Index is a list of index names; use `_all` or empty string for all indices. +func (s *IndicesSyncedFlushService) Index(indices ...string) *IndicesSyncedFlushService { + s.index = append(s.index, indices...) + return s +} + +// IgnoreUnavailable indicates whether specified concrete indices should be +// ignored when unavailable (missing or closed). +func (s *IndicesSyncedFlushService) IgnoreUnavailable(ignoreUnavailable bool) *IndicesSyncedFlushService { + 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 *IndicesSyncedFlushService) AllowNoIndices(allowNoIndices bool) *IndicesSyncedFlushService { + s.allowNoIndices = &allowNoIndices + return s +} + +// ExpandWildcards specifies whether to expand wildcard expression to +// concrete indices that are open, closed or both.. +func (s *IndicesSyncedFlushService) ExpandWildcards(expandWildcards string) *IndicesSyncedFlushService { + s.expandWildcards = expandWildcards + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *IndicesSyncedFlushService) Pretty(pretty bool) *IndicesSyncedFlushService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *IndicesSyncedFlushService) buildURL() (string, url.Values, error) { + // Build URL + var err error + var path string + + if len(s.index) > 0 { + path, err = uritemplates.Expand("/{index}/_flush/synced", map[string]string{ + "index": strings.Join(s.index, ","), + }) + } else { + path = "/_flush/synced" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + 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) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *IndicesSyncedFlushService) Validate() error { + return nil +} + +// Do executes the service. +func (s *IndicesSyncedFlushService) Do(ctx context.Context) (*IndicesSyncedFlushResponse, 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, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(IndicesSyncedFlushResponse) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// -- Result of a flush request. + +// IndicesSyncedFlushResponse is the outcome of a synched flush call. +type IndicesSyncedFlushResponse struct { + Shards *ShardsInfo `json:"_shards"` + Index map[string]*IndicesShardsSyncedFlushResult `json:"-"` + + // TODO Add information about the indices here from the root level + // It looks like this: + // { + // "_shards" : { + // "total" : 4, + // "successful" : 4, + // "failed" : 0 + // }, + // "elastic-test" : { + // "total" : 1, + // "successful" : 1, + // "failed" : 0 + // }, + // "elastic-test2" : { + // "total" : 1, + // "successful" : 1, + // "failed" : 0 + // }, + // "elastic-orders" : { + // "total" : 1, + // "successful" : 1, + // "failed" : 0 + // }, + // "elastic-nosource-test" : { + // "total" : 1, + // "successful" : 1, + // "failed" : 0 + // } + // } +} + +// IndicesShardsSyncedFlushResult represents synced flush information about +// a specific index. +type IndicesShardsSyncedFlushResult struct { + Total int `json:"total"` + Successful int `json:"successful"` + Failed int `json:"failed"` + Failures []IndicesShardsSyncedFlushResultFailure `json:"failures,omitempty"` +} + +// IndicesShardsSyncedFlushResultFailure represents a failure of a synced +// flush operation. +type IndicesShardsSyncedFlushResultFailure struct { + Shard int `json:"shard"` + Reason string `json:"reason"` + Routing struct { + State string `json:"state"` + Primary bool `json:"primary"` + Node string `json:"node"` + RelocatingNode *string `json:"relocating_node"` + Shard int `json:"shard"` + Index string `json:"index"` + ExpectedShardSizeInBytes int64 `json:"expected_shard_size_in_bytes,omitempty"` + // recoverySource + // allocationId + // unassignedInfo + } `json:"routing"` +} + +// UnmarshalJSON parses the output from Synced Flush API. +func (resp *IndicesSyncedFlushResponse) UnmarshalJSON(data []byte) error { + m := make(map[string]json.RawMessage) + err := json.Unmarshal(data, &m) + if err != nil { + return err + } + resp.Index = make(map[string]*IndicesShardsSyncedFlushResult) + for k, v := range m { + if k == "_shards" { + if err := json.Unmarshal(v, &resp.Shards); err != nil { + return err + } + } else { + ix := new(IndicesShardsSyncedFlushResult) + if err := json.Unmarshal(v, &ix); err != nil { + return err + } + resp.Index[k] = ix + } + } + return nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_forcemerge.go b/vendor/gopkg.in/olivere/elastic.v6/indices_forcemerge.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/indices_forcemerge.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_forcemerge.go index 011bb66d2d..2a1726f128 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_forcemerge.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_forcemerge.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesForcemergeService allows to force merging of one or more indices. @@ -30,7 +30,6 @@ type IndicesForcemergeService struct { ignoreUnavailable *bool maxNumSegments interface{} onlyExpungeDeletes *bool - operationThreading interface{} } // NewIndicesForcemergeService creates a new IndicesForcemergeService. @@ -94,11 +93,6 @@ func (s *IndicesForcemergeService) OnlyExpungeDeletes(onlyExpungeDeletes bool) * return s } -func (s *IndicesForcemergeService) OperationThreading(operationThreading interface{}) *IndicesForcemergeService { - s.operationThreading = operationThreading - return s -} - // Pretty indicates that the JSON response be indented and human readable. func (s *IndicesForcemergeService) Pretty(pretty bool) *IndicesForcemergeService { s.pretty = pretty @@ -125,7 +119,7 @@ func (s *IndicesForcemergeService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.allowNoIndices != nil { params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) @@ -145,9 +139,6 @@ func (s *IndicesForcemergeService) buildURL() (string, url.Values, error) { if s.onlyExpungeDeletes != nil { params.Set("only_expunge_deletes", fmt.Sprintf("%v", *s.onlyExpungeDeletes)) } - if s.operationThreading != nil { - params.Set("operation_threading", fmt.Sprintf("%v", s.operationThreading)) - } return path, params, nil } @@ -170,7 +161,11 @@ func (s *IndicesForcemergeService) Do(ctx context.Context) (*IndicesForcemergeRe } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_get.go b/vendor/gopkg.in/olivere/elastic.v6/indices_get.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/indices_get.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_get.go index 3b80c246d3..8b89b0b14a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_get.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_get.go @@ -10,12 +10,12 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesGetService retrieves information about one or more indices. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-index.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-index.html // for more details. type IndicesGetService struct { client *Client @@ -131,7 +131,7 @@ func (s *IndicesGetService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.expandWildcards != "" { params.Set("expand_wildcards", s.expandWildcards) @@ -180,7 +180,11 @@ func (s *IndicesGetService) Do(ctx context.Context) (map[string]*IndicesGetRespo } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_get_aliases.go b/vendor/gopkg.in/olivere/elastic.v6/indices_get_aliases.go similarity index 66% rename from vendor/gopkg.in/olivere/elastic.v5/indices_get_aliases.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_get_aliases.go index 530d7bdcd2..37494eafb1 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_get_aliases.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_get_aliases.go @@ -10,14 +10,16 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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. +// AliasesService returns the aliases associated with one or more indices, or the +// indices associated with one or more aliases, or a combination of those filters. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-aliases.html. type AliasesService struct { client *Client index []string + alias []string pretty bool } @@ -41,21 +43,31 @@ func (s *AliasesService) Index(index ...string) *AliasesService { return s } +// Alias adds one or more aliases. +func (s *AliasesService) Alias(alias ...string) *AliasesService { + s.alias = append(s.alias, alias...) + return s +} + // buildURL builds the URL for the operation. func (s *AliasesService) buildURL() (string, url.Values, error) { var err error var path string if len(s.index) > 0 { - path, err = uritemplates.Expand("/{index}/_aliases", map[string]string{ + path, err = uritemplates.Expand("/{index}/_alias/{alias}", map[string]string{ "index": strings.Join(s.index, ","), + "alias": strings.Join(s.alias, ","), }) } else { - path = "/_aliases" + path, err = uritemplates.Expand("/_alias/{alias}", map[string]string{ + "alias": strings.Join(s.alias, ","), + }) } if err != nil { return "", url.Values{}, err } + path = strings.TrimSuffix(path, "/") // Add query string parameters params := url.Values{} @@ -72,7 +84,11 @@ func (s *AliasesService) Do(ctx context.Context) (*AliasesResult, error) { } // Get response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -88,7 +104,11 @@ func (s *AliasesService) Do(ctx context.Context) (*AliasesResult, error) { // ... // }, // } - indexMap := make(map[string]interface{}) + indexMap := make(map[string]struct { + Aliases map[string]struct { + IsWriteIndex bool `json:"is_write_index"` + } `json:"aliases"` + }) if err := s.client.decoder.Decode(res.Body, &indexMap); err != nil { return nil, err } @@ -98,21 +118,19 @@ func (s *AliasesService) Do(ctx context.Context) (*AliasesResult, error) { Indices: make(map[string]indexResult), } for indexName, indexData := range indexMap { + if indexData.Aliases == nil { + continue + } + indexOut, found := ret.Indices[indexName] if !found { indexOut = indexResult{Aliases: make([]aliasResult, 0)} } // { "aliases" : { ... } } - indexDataMap, ok := indexData.(map[string]interface{}) - if ok { - aliasesData, ok := indexDataMap["aliases"].(map[string]interface{}) - if ok { - for aliasName, _ := range aliasesData { - aliasRes := aliasResult{AliasName: aliasName} - indexOut.Aliases = append(indexOut.Aliases, aliasRes) - } - } + for aliasName, aliasData := range indexData.Aliases { + aliasRes := aliasResult{AliasName: aliasName, IsWriteIndex: aliasData.IsWriteIndex} + indexOut.Aliases = append(indexOut.Aliases, aliasRes) } ret.Indices[indexName] = indexOut @@ -123,6 +141,7 @@ func (s *AliasesService) Do(ctx context.Context) (*AliasesResult, error) { // -- Result of an alias request. +// AliasesResult is the outcome of calling AliasesService.Do. type AliasesResult struct { Indices map[string]indexResult } @@ -132,9 +151,11 @@ type indexResult struct { } type aliasResult struct { - AliasName string + AliasName string + IsWriteIndex bool } +// IndicesByAlias returns all indices given a specific alias name. func (ar AliasesResult) IndicesByAlias(aliasName string) []string { var indices []string for indexName, indexInfo := range ar.Indices { @@ -147,6 +168,7 @@ func (ar AliasesResult) IndicesByAlias(aliasName string) []string { return indices } +// HasAlias returns true if the index has a specific alias. func (ir indexResult) HasAlias(aliasName string) bool { for _, alias := range ir.Aliases { if alias.AliasName == aliasName { diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_get_field_mapping.go b/vendor/gopkg.in/olivere/elastic.v6/indices_get_field_mapping.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/indices_get_field_mapping.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_get_field_mapping.go index 3cb43d54b9..3430bb4e89 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_get_field_mapping.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_get_field_mapping.go @@ -10,13 +10,13 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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 +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-field-mapping.html // for details. type IndicesGetFieldMappingService struct { client *Client @@ -131,7 +131,7 @@ func (s *IndicesGetFieldMappingService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.ignoreUnavailable != nil { params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) @@ -170,7 +170,11 @@ func (s *IndicesGetFieldMappingService) Do(ctx context.Context) (map[string]inte } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_get_mapping.go b/vendor/gopkg.in/olivere/elastic.v6/indices_get_mapping.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/indices_get_mapping.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_get_mapping.go index 3b22589157..a6f65706b5 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_get_mapping.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_get_mapping.go @@ -10,13 +10,13 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesGetMappingService retrieves the mapping definitions for an index or // index/type. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-mapping.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-mapping.html // for details. type IndicesGetMappingService struct { client *Client @@ -119,7 +119,7 @@ func (s *IndicesGetMappingService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.ignoreUnavailable != nil { params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) @@ -156,7 +156,11 @@ func (s *IndicesGetMappingService) Do(ctx context.Context) (map[string]interface } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_get_settings.go b/vendor/gopkg.in/olivere/elastic.v6/indices_get_settings.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/indices_get_settings.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_get_settings.go index 0e8f28d709..c2e974baf9 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_get_settings.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_get_settings.go @@ -10,13 +10,13 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesGetSettingsService allows to retrieve settings of one // or more indices. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-get-settings.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-get-settings.html // for more details. type IndicesGetSettingsService struct { client *Client @@ -125,7 +125,7 @@ func (s *IndicesGetSettingsService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.ignoreUnavailable != nil { params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) @@ -164,7 +164,11 @@ func (s *IndicesGetSettingsService) Do(ctx context.Context) (map[string]*Indices } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_get_template.go b/vendor/gopkg.in/olivere/elastic.v6/indices_get_template.go similarity index 81% rename from vendor/gopkg.in/olivere/elastic.v5/indices_get_template.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_get_template.go index 15590dc06f..0ae6207727 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_get_template.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_get_template.go @@ -10,11 +10,11 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesGetTemplateService returns an index template. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-templates.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-templates.html. type IndicesGetTemplateService struct { client *Client pretty bool @@ -75,7 +75,7 @@ func (s *IndicesGetTemplateService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.flatSettings != nil { params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings)) @@ -105,7 +105,11 @@ func (s *IndicesGetTemplateService) Do(ctx context.Context) (map[string]*Indices } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -120,10 +124,10 @@ func (s *IndicesGetTemplateService) Do(ctx context.Context) (map[string]*Indices // IndicesGetTemplateResponse is the response of IndicesGetTemplateService.Do. type IndicesGetTemplateResponse struct { - Order int `json:"order,omitempty"` - Version int `json:"version,omitempty"` - Template string `json:"template,omitempty"` - Settings map[string]interface{} `json:"settings,omitempty"` - Mappings map[string]interface{} `json:"mappings,omitempty"` - Aliases map[string]interface{} `json:"aliases,omitempty"` + Order int `json:"order,omitempty"` + Version int `json:"version,omitempty"` + IndexPatterns []string `json:"index_patterns,omitempty"` + Settings map[string]interface{} `json:"settings,omitempty"` + Mappings map[string]interface{} `json:"mappings,omitempty"` + Aliases map[string]interface{} `json:"aliases,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_open.go b/vendor/gopkg.in/olivere/elastic.v6/indices_open.go similarity index 76% rename from vendor/gopkg.in/olivere/elastic.v5/indices_open.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_open.go index 38277c385c..6b6f9de893 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_open.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_open.go @@ -9,22 +9,23 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesOpenService opens an index. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-open-close.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-open-close.html // for details. type IndicesOpenService struct { - client *Client - pretty bool - index string - timeout string - masterTimeout string - ignoreUnavailable *bool - allowNoIndices *bool - expandWildcards string + client *Client + pretty bool + index string + timeout string + masterTimeout string + ignoreUnavailable *bool + allowNoIndices *bool + expandWildcards string + waitForActiveShards string } // NewIndicesOpenService creates and initializes a new IndicesOpenService. @@ -72,6 +73,14 @@ func (s *IndicesOpenService) ExpandWildcards(expandWildcards string) *IndicesOpe return s } +// WaitForActiveShards specifies the number of shards that must be allocated +// before the Open operation returns. Valid values are "all" or an integer +// between 0 and number_of_replicas+1 (default: 0) +func (s *IndicesOpenService) WaitForActiveShards(waitForActiveShards string) *IndicesOpenService { + s.waitForActiveShards = waitForActiveShards + return s +} + // Pretty indicates that the JSON response be indented and human readable. func (s *IndicesOpenService) Pretty(pretty bool) *IndicesOpenService { s.pretty = pretty @@ -91,7 +100,7 @@ func (s *IndicesOpenService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.timeout != "" { params.Set("timeout", s.timeout) @@ -108,6 +117,9 @@ func (s *IndicesOpenService) buildURL() (string, url.Values, error) { if s.expandWildcards != "" { params.Set("expand_wildcards", s.expandWildcards) } + if s.waitForActiveShards != "" { + params.Set("wait_for_active_shards", s.waitForActiveShards) + } return path, params, nil } @@ -138,7 +150,11 @@ func (s *IndicesOpenService) Do(ctx context.Context) (*IndicesOpenResponse, erro } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -153,5 +169,7 @@ func (s *IndicesOpenService) Do(ctx context.Context) (*IndicesOpenResponse, erro // IndicesOpenResponse is the response of IndicesOpenService.Do. type IndicesOpenResponse struct { - Acknowledged bool `json:"acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_put_alias.go b/vendor/gopkg.in/olivere/elastic.v6/indices_put_alias.go similarity index 80% rename from vendor/gopkg.in/olivere/elastic.v5/indices_put_alias.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_put_alias.go index 5d965bd669..e6aae1cd37 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_put_alias.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_put_alias.go @@ -26,6 +26,7 @@ type AliasAddAction struct { routing string searchRouting string indexRouting string + isWriteIndex *bool } // NewAliasAddAction returns an action to add an alias. @@ -76,6 +77,12 @@ func (a *AliasAddAction) SearchRouting(routing ...string) *AliasAddAction { return a } +// IsWriteIndex associates an is_write_index flag to the alias. +func (a *AliasAddAction) IsWriteIndex(flag bool) *AliasAddAction { + a.isWriteIndex = &flag + return a +} + // Validate checks if the operation is valid. func (a *AliasAddAction) Validate() error { var invalid []string @@ -88,6 +95,9 @@ func (a *AliasAddAction) Validate() error { if len(invalid) > 0 { return fmt.Errorf("missing required fields: %v", invalid) } + if a.isWriteIndex != nil && len(a.index) > 1 { + return fmt.Errorf("more than 1 target index specified in operation with 'is_write_index' flag present") + } return nil } @@ -123,6 +133,9 @@ func (a *AliasAddAction) Source() (interface{}, error) { if len(a.searchRouting) > 0 { act["search_routing"] = a.searchRouting } + if a.isWriteIndex != nil { + act["is_write_index"] = *a.isWriteIndex + } return src, nil } @@ -189,10 +202,43 @@ func (a *AliasRemoveAction) Source() (interface{}, error) { return src, nil } +// AliasRemoveIndexAction is an action to remove an index during an alias +// operation. +type AliasRemoveIndexAction struct { + index string // index name +} + +// NewAliasRemoveIndexAction returns an action to remove an index. +func NewAliasRemoveIndexAction(index string) *AliasRemoveIndexAction { + return &AliasRemoveIndexAction{ + index: index, + } +} + +// Validate checks if the operation is valid. +func (a *AliasRemoveIndexAction) Validate() error { + if a.index == "" { + return fmt.Errorf("missing required field: index") + } + return nil +} + +// Source returns the JSON-serializable data. +func (a *AliasRemoveIndexAction) Source() (interface{}, error) { + if err := a.Validate(); err != nil { + return nil, err + } + src := make(map[string]interface{}) + act := make(map[string]interface{}) + src["remove_index"] = act + act["index"] = 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 +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-aliases.html // for details. type AliasService struct { client *Client @@ -274,7 +320,12 @@ func (s *AliasService) Do(ctx context.Context) (*AliasResult, error) { body["actions"] = actions // Get response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -291,5 +342,7 @@ func (s *AliasService) Do(ctx context.Context) (*AliasResult, error) { // AliasResult is the outcome of calling Do on AliasService. type AliasResult struct { - Acknowledged bool `json:"acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_put_mapping.go b/vendor/gopkg.in/olivere/elastic.v6/indices_put_mapping.go similarity index 81% rename from vendor/gopkg.in/olivere/elastic.v5/indices_put_mapping.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_put_mapping.go index 03f26ca919..67d12da47f 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_put_mapping.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_put_mapping.go @@ -10,13 +10,13 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesPutMappingService allows to register specific mapping definition // for a specific type. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-put-mapping.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-put-mapping.html // for details. type IndicesPutMappingService struct { client *Client @@ -27,6 +27,7 @@ type IndicesPutMappingService struct { ignoreUnavailable *bool allowNoIndices *bool expandWildcards string + includeTypeName *bool updateAllTypes *bool timeout string bodyJson map[string]interface{} @@ -94,10 +95,17 @@ func (s *IndicesPutMappingService) ExpandWildcards(expandWildcards string) *Indi return s } -// UpdateAllTypes, if true, indicates that all fields that span multiple indices -// should be updated (default: false). -func (s *IndicesPutMappingService) UpdateAllTypes(updateAllTypes bool) *IndicesPutMappingService { - s.updateAllTypes = &updateAllTypes +// IncludeTypeName indicates whether to update the mapping for all fields +// with the same name across all types or not. +func (s *IndicesPutMappingService) IncludeTypeName(include bool) *IndicesPutMappingService { + s.includeTypeName = &include + return s +} + +// UpdateAllTypes indicates whether to update the mapping for all fields +// with the same name across all types or not. +func (s *IndicesPutMappingService) UpdateAllTypes(update bool) *IndicesPutMappingService { + s.updateAllTypes = &update return s } @@ -142,7 +150,7 @@ func (s *IndicesPutMappingService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.ignoreUnavailable != nil { params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) @@ -153,8 +161,19 @@ func (s *IndicesPutMappingService) buildURL() (string, url.Values, error) { if s.expandWildcards != "" { params.Set("expand_wildcards", s.expandWildcards) } - if s.updateAllTypes != nil { - params.Set("update_all_types", fmt.Sprintf("%v", *s.updateAllTypes)) + if v := s.includeTypeName; v != nil { + if *v { + params.Set("include_type_name", "true") + } else { + params.Set("include_type_name", "false") + } + } + if v := s.updateAllTypes; v != nil && *v { + if *v { + params.Set("update_all_types", "true") + } else { + params.Set("update_all_types", "false") + } } if s.timeout != "" { params.Set("timeout", s.timeout) @@ -202,7 +221,12 @@ func (s *IndicesPutMappingService) Do(ctx context.Context) (*PutMappingResponse, } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -217,5 +241,7 @@ func (s *IndicesPutMappingService) Do(ctx context.Context) (*PutMappingResponse, // PutMappingResponse is the response of IndicesPutMappingService.Do. type PutMappingResponse struct { - Acknowledged bool `json:"acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_put_settings.go b/vendor/gopkg.in/olivere/elastic.v6/indices_put_settings.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v5/indices_put_settings.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_put_settings.go index 20ae95207e..b10bc36635 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_put_settings.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_put_settings.go @@ -10,14 +10,14 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesPutSettingsService changes specific index level settings in // real time. // // See the documentation at -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-update-settings.html. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-update-settings.html. type IndicesPutSettingsService struct { client *Client pretty bool @@ -118,7 +118,7 @@ func (s *IndicesPutSettingsService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.allowNoIndices != nil { params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) @@ -165,7 +165,12 @@ func (s *IndicesPutSettingsService) Do(ctx context.Context) (*IndicesPutSettings } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -180,5 +185,7 @@ func (s *IndicesPutSettingsService) Do(ctx context.Context) (*IndicesPutSettings // IndicesPutSettingsResponse is the response of IndicesPutSettingsService.Do. type IndicesPutSettingsResponse struct { - Acknowledged bool `json:"acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_put_template.go b/vendor/gopkg.in/olivere/elastic.v6/indices_put_template.go similarity index 80% rename from vendor/gopkg.in/olivere/elastic.v5/indices_put_template.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_put_template.go index 49df95f545..2e7a23d9c0 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_put_template.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_put_template.go @@ -9,24 +9,25 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesPutTemplateService creates or updates index mappings. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-templates.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-templates.html. type IndicesPutTemplateService struct { - client *Client - pretty bool - name string - cause string - order interface{} - version *int - create *bool - timeout string - masterTimeout string - flatSettings *bool - bodyJson interface{} - bodyString string + client *Client + pretty bool + name string + cause string + order interface{} + version *int + create *bool + timeout string + masterTimeout string + flatSettings *bool + includeTypeName *bool + bodyJson interface{} + bodyString string } // NewIndicesPutTemplateService creates a new IndicesPutTemplateService. @@ -87,6 +88,13 @@ func (s *IndicesPutTemplateService) Create(create bool) *IndicesPutTemplateServi return s } +// IncludeTypeName indicates whether to update the mapping for all fields +// with the same name across all types or not. +func (s *IndicesPutTemplateService) IncludeTypeName(include bool) *IndicesPutTemplateService { + s.includeTypeName = &include + return s +} + // Pretty indicates that the JSON response be indented and human readable. func (s *IndicesPutTemplateService) Pretty(pretty bool) *IndicesPutTemplateService { s.pretty = pretty @@ -118,7 +126,7 @@ func (s *IndicesPutTemplateService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.order != nil { params.Set("order", fmt.Sprintf("%v", s.order)) @@ -141,6 +149,13 @@ func (s *IndicesPutTemplateService) buildURL() (string, url.Values, error) { if s.flatSettings != nil { params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings)) } + if v := s.includeTypeName; v != nil { + if *v { + params.Set("include_type_name", "true") + } else { + params.Set("include_type_name", "false") + } + } return path, params, nil } @@ -181,7 +196,12 @@ func (s *IndicesPutTemplateService) Do(ctx context.Context) (*IndicesPutTemplate } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -196,5 +216,7 @@ func (s *IndicesPutTemplateService) Do(ctx context.Context) (*IndicesPutTemplate // IndicesPutTemplateResponse is the response of IndicesPutTemplateService.Do. type IndicesPutTemplateResponse struct { - Acknowledged bool `json:"acknowledged,omitempty"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_refresh.go b/vendor/gopkg.in/olivere/elastic.v6/indices_refresh.go similarity index 88% rename from vendor/gopkg.in/olivere/elastic.v5/indices_refresh.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_refresh.go index 2e6bc60f7c..a300735d0d 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_refresh.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_refresh.go @@ -10,11 +10,11 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // RefreshService explicitly refreshes one or more indices. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/indices-refresh.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-refresh.html. type RefreshService struct { client *Client index []string @@ -73,7 +73,11 @@ func (s *RefreshService) Do(ctx context.Context) (*RefreshResult, error) { } // Get response - res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_rollover.go b/vendor/gopkg.in/olivere/elastic.v6/indices_rollover.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/indices_rollover.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_rollover.go index ef1cad0333..ed2b2c9f63 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_rollover.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_rollover.go @@ -10,14 +10,14 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-rollover-index.html. type IndicesRolloverService struct { client *Client pretty bool @@ -189,10 +189,10 @@ func (s *IndicesRolloverService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.dryRun { - params.Set("dry_run", "1") + params.Set("dry_run", "true") } if s.masterTimeout != "" { params.Set("master_timeout", s.masterTimeout) @@ -242,7 +242,12 @@ func (s *IndicesRolloverService) Do(ctx context.Context) (*IndicesRolloverRespon } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_segments.go b/vendor/gopkg.in/olivere/elastic.v6/indices_segments.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v5/indices_segments.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_segments.go index e8e896b3b4..584cc969e6 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_segments.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_segments.go @@ -11,7 +11,7 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesSegmentsService provides low level segments information that a @@ -20,7 +20,7 @@ import ( // optimization information, data "wasted" on deletes, and so on. // // Find further documentation at -// https://www.elastic.co/guide/en/elasticsearch/reference/5.6/indices-segments.html. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-segments.html. type IndicesSegmentsService struct { client *Client pretty bool @@ -154,7 +154,7 @@ func (s *IndicesSegmentsService) Do(ctx context.Context) (*IndicesSegmentsRespon } // Get HTTP response - res, err := s.client.PerformRequestWithOptions(ctx, PerformRequestOptions{ + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ Method: "GET", Path: path, Params: params, @@ -217,7 +217,16 @@ type IndexSegmentsDetails struct { Version string `json:"version,omitempty"` Compound bool `json:"compound,omitempty"` MergeId string `json:"merge_id,omitempty"` + Sort []*IndexSegmentsSort `json:"sort,omitempty"` RAMTree []*IndexSegmentsRamTree `json:"ram_tree,omitempty"` + Attributes map[string]string `json:"attributes,omitempty"` +} + +type IndexSegmentsSort struct { + Field string `json:"field,omitempty"` + Mode string `json:"mode,omitempty"` + Missing interface{} `json:"missing,omitempty"` + Reverse bool `json:"reverse,omitempty"` } type IndexSegmentsRamTree struct { diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_shrink.go b/vendor/gopkg.in/olivere/elastic.v6/indices_shrink.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v5/indices_shrink.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_shrink.go index ea20804a6b..7a0eaf5680 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_shrink.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_shrink.go @@ -10,14 +10,14 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-shrink-index.html. type IndicesShrinkService struct { client *Client pretty bool @@ -102,7 +102,7 @@ func (s *IndicesShrinkService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.masterTimeout != "" { params.Set("master_timeout", s.masterTimeout) @@ -153,7 +153,12 @@ func (s *IndicesShrinkService) Do(ctx context.Context) (*IndicesShrinkResponse, } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -168,6 +173,7 @@ func (s *IndicesShrinkService) Do(ctx context.Context) (*IndicesShrinkResponse, // IndicesShrinkResponse is the response of IndicesShrinkService.Do. type IndicesShrinkResponse struct { - Acknowledged bool `json:"acknowledged"` - ShardsAcknowledged bool `json:"shards_acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/indices_stats.go b/vendor/gopkg.in/olivere/elastic.v6/indices_stats.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/indices_stats.go rename to vendor/gopkg.in/olivere/elastic.v6/indices_stats.go index 1ebbd8983a..6ff98b62b0 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/indices_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v6/indices_stats.go @@ -10,11 +10,11 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IndicesStatsService provides stats on various metrics of one or more -// indices. See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-stats.html. +// indices. See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-stats.html. type IndicesStatsService struct { client *Client pretty bool @@ -135,7 +135,7 @@ func (s *IndicesStatsService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if len(s.groups) > 0 { params.Set("groups", strings.Join(s.groups, ",")) @@ -180,7 +180,11 @@ func (s *IndicesStatsService) Do(ctx context.Context) (*IndicesStatsResponse, er } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -240,25 +244,20 @@ type IndexStatsDocs struct { } type IndexStatsStore struct { - Size string `json:"size,omitempty"` // human size, e.g. 119.3mb - SizeInBytes int64 `json:"size_in_bytes,omitempty"` - ThrottleTime string `json:"throttle_time,omitempty"` // human time, e.g. 0s - ThrottleTimeInMillis int64 `json:"throttle_time_in_millis,omitempty"` + Size string `json:"size,omitempty"` // human size, e.g. 119.3mb + SizeInBytes int64 `json:"size_in_bytes,omitempty"` } type IndexStatsIndexing struct { - IndexTotal int64 `json:"index_total,omitempty"` - IndexTime string `json:"index_time,omitempty"` - IndexTimeInMillis int64 `json:"index_time_in_millis,omitempty"` - IndexCurrent int64 `json:"index_current,omitempty"` - DeleteTotal int64 `json:"delete_total,omitempty"` - DeleteTime string `json:"delete_time,omitempty"` - DeleteTimeInMillis int64 `json:"delete_time_in_millis,omitempty"` - DeleteCurrent int64 `json:"delete_current,omitempty"` - NoopUpdateTotal int64 `json:"noop_update_total,omitempty"` - IsThrottled bool `json:"is_throttled,omitempty"` - ThrottleTime string `json:"throttle_time,omitempty"` - ThrottleTimeInMillis int64 `json:"throttle_time_in_millis,omitempty"` + IndexTotal int64 `json:"index_total,omitempty"` + IndexTime string `json:"index_time,omitempty"` + IndexTimeInMillis int64 `json:"index_time_in_millis,omitempty"` + IndexCurrent int64 `json:"index_current,omitempty"` + DeleteTotal int64 `json:"delete_total,omitempty"` + DeleteTime string `json:"delete_time,omitempty"` + DeleteTimeInMillis int64 `json:"delete_time_in_millis,omitempty"` + DeleteCurrent int64 `json:"delete_current,omitempty"` + NoopUpdateTotal int64 `json:"noop_update_total,omitempty"` } type IndexStatsGet struct { diff --git a/vendor/gopkg.in/olivere/elastic.v5/ingest_delete_pipeline.go b/vendor/gopkg.in/olivere/elastic.v6/ingest_delete_pipeline.go similarity index 88% rename from vendor/gopkg.in/olivere/elastic.v5/ingest_delete_pipeline.go rename to vendor/gopkg.in/olivere/elastic.v6/ingest_delete_pipeline.go index 1e33d9707e..01c044872a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/ingest_delete_pipeline.go +++ b/vendor/gopkg.in/olivere/elastic.v6/ingest_delete_pipeline.go @@ -10,11 +10,11 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IngestDeletePipelineService deletes pipelines by ID. -// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.2/delete-pipeline-api.html. +// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/6.8/delete-pipeline-api.html. type IngestDeletePipelineService struct { client *Client pretty bool @@ -67,7 +67,7 @@ func (s *IngestDeletePipelineService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.masterTimeout != "" { params.Set("master_timeout", s.masterTimeout) @@ -104,7 +104,11 @@ func (s *IngestDeletePipelineService) Do(ctx context.Context) (*IngestDeletePipe } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -119,5 +123,7 @@ func (s *IngestDeletePipelineService) Do(ctx context.Context) (*IngestDeletePipe // IngestDeletePipelineResponse is the response of IngestDeletePipelineService.Do. type IngestDeletePipelineResponse struct { - Acknowledged bool `json:"acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/ingest_get_pipeline.go b/vendor/gopkg.in/olivere/elastic.v6/ingest_get_pipeline.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/ingest_get_pipeline.go rename to vendor/gopkg.in/olivere/elastic.v6/ingest_get_pipeline.go index 48b9df30ea..bb3c41032b 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/ingest_get_pipeline.go +++ b/vendor/gopkg.in/olivere/elastic.v6/ingest_get_pipeline.go @@ -10,11 +10,11 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // IngestGetPipelineService returns pipelines based on ID. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/get-pipeline-api.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/get-pipeline-api.html // for documentation. type IngestGetPipelineService struct { client *Client @@ -68,7 +68,7 @@ func (s *IngestGetPipelineService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.masterTimeout != "" { params.Set("master_timeout", s.masterTimeout) @@ -95,7 +95,11 @@ func (s *IngestGetPipelineService) Do(ctx context.Context) (IngestGetPipelineRes } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/ingest_put_pipeline.go b/vendor/gopkg.in/olivere/elastic.v6/ingest_put_pipeline.go similarity index 89% rename from vendor/gopkg.in/olivere/elastic.v5/ingest_put_pipeline.go rename to vendor/gopkg.in/olivere/elastic.v6/ingest_put_pipeline.go index 315453e9dd..0d3878ef90 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/ingest_put_pipeline.go +++ b/vendor/gopkg.in/olivere/elastic.v6/ingest_put_pipeline.go @@ -10,13 +10,13 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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. +// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/6.8/put-pipeline-api.html. type IngestPutPipelineService struct { client *Client pretty bool @@ -84,7 +84,7 @@ func (s *IngestPutPipelineService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.masterTimeout != "" { params.Set("master_timeout", s.masterTimeout) @@ -132,7 +132,12 @@ func (s *IngestPutPipelineService) Do(ctx context.Context) (*IngestPutPipelineRe } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -147,5 +152,7 @@ func (s *IngestPutPipelineService) Do(ctx context.Context) (*IngestPutPipelineRe // IngestPutPipelineResponse is the response of IngestPutPipelineService.Do. type IngestPutPipelineResponse struct { - Acknowledged bool `json:"acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/ingest_simulate_pipeline.go b/vendor/gopkg.in/olivere/elastic.v6/ingest_simulate_pipeline.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v5/ingest_simulate_pipeline.go rename to vendor/gopkg.in/olivere/elastic.v6/ingest_simulate_pipeline.go index 04015b4599..ba4c868547 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/ingest_simulate_pipeline.go +++ b/vendor/gopkg.in/olivere/elastic.v6/ingest_simulate_pipeline.go @@ -10,14 +10,14 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/simulate-pipeline-api.html. type IngestSimulatePipelineService struct { client *Client pretty bool @@ -85,7 +85,7 @@ func (s *IngestSimulatePipelineService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.verbose != nil { params.Set("verbose", fmt.Sprintf("%v", *s.verbose)) @@ -127,7 +127,12 @@ func (s *IngestSimulatePipelineService) Do(ctx context.Context) (*IngestSimulate } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/inner_hit.go b/vendor/gopkg.in/olivere/elastic.v6/inner_hit.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v5/inner_hit.go rename to vendor/gopkg.in/olivere/elastic.v6/inner_hit.go index c371fbf791..9bc1097eb6 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/inner_hit.go +++ b/vendor/gopkg.in/olivere/elastic.v6/inner_hit.go @@ -96,11 +96,21 @@ func (hit *InnerHit) DocvalueFields(docvalueFields ...string) *InnerHit { return hit } +func (hit *InnerHit) DocvalueFieldsWithFormat(docvalueFields ...DocvalueField) *InnerHit { + hit.source.DocvalueFieldsWithFormat(docvalueFields...) + return hit +} + func (hit *InnerHit) DocvalueField(docvalueField string) *InnerHit { hit.source.DocvalueField(docvalueField) return hit } +func (hit *InnerHit) DocvalueFieldWithFormat(docvalueField DocvalueField) *InnerHit { + hit.source.DocvalueFieldWithFormat(docvalueField) + return hit +} + func (hit *InnerHit) ScriptFields(scriptFields ...*ScriptField) *InnerHit { hit.source.ScriptFields(scriptFields...) return hit diff --git a/vendor/gopkg.in/olivere/elastic.v5/logger.go b/vendor/gopkg.in/olivere/elastic.v6/logger.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/logger.go rename to vendor/gopkg.in/olivere/elastic.v6/logger.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/mget.go b/vendor/gopkg.in/olivere/elastic.v6/mget.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v5/mget.go rename to vendor/gopkg.in/olivere/elastic.v6/mget.go index 0f2894854a..a23d5214c6 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/mget.go +++ b/vendor/gopkg.in/olivere/elastic.v6/mget.go @@ -16,7 +16,7 @@ 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/5.2/docs-multi-get.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-multi-get.html // for details. type MgetService struct { client *Client @@ -45,6 +45,9 @@ func (s *MgetService) Preference(preference string) *MgetService { } // Refresh the shard containing the document before performing the operation. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html +// for details. func (s *MgetService) Refresh(refresh string) *MgetService { s.refresh = refresh return s @@ -124,7 +127,12 @@ func (s *MgetService) Do(ctx context.Context) (*MgetResponse, error) { } // Get response - res, err := s.client.PerformRequest(ctx, "GET", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -194,8 +202,8 @@ func (item *MultiGetItem) Version(version int64) *MultiGetItem { return item } -// VersionType can be "internal", "external", "external_gt", "external_gte", -// or "force". See org.elasticsearch.index.VersionType in Elasticsearch source. +// VersionType can be "internal", "external", "external_gt", or "external_gte". +// See org.elasticsearch.index.VersionType in Elasticsearch source. // It is "internal" by default. func (item *MultiGetItem) VersionType(versionType string) *MultiGetItem { item.versionType = versionType diff --git a/vendor/gopkg.in/olivere/elastic.v5/msearch.go b/vendor/gopkg.in/olivere/elastic.v6/msearch.go similarity index 66% rename from vendor/gopkg.in/olivere/elastic.v5/msearch.go rename to vendor/gopkg.in/olivere/elastic.v6/msearch.go index bdedded4a1..c95f6af31c 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/msearch.go +++ b/vendor/gopkg.in/olivere/elastic.v6/msearch.go @@ -14,17 +14,18 @@ import ( // MultiSearch executes one or more searches in one roundtrip. type MultiSearchService struct { - client *Client - requests []*SearchRequest - indices []string - pretty bool + client *Client + requests []*SearchRequest + indices []string + pretty bool maxConcurrentRequests *int preFilterShardSize *int + restTotalHitsAsInt *bool } func NewMultiSearchService(client *Client) *MultiSearchService { builder := &MultiSearchService{ - client: client, + client: client, } return builder } @@ -54,6 +55,18 @@ func (s *MultiSearchService) PreFilterShardSize(size int) *MultiSearchService { return s } +// RestTotalHitsAsInt is a flag that is temporarily available for ES 7.x +// servers to return total hits as an int64 instead of a response structure. +// +// Warning: Using it indicates that you are using elastic.v6 with ES 7.x, +// which is an unsupported scenario. Use at your own risk. +// This option will also be removed with ES 8.x. +// See https://www.elastic.co/guide/en/elasticsearch/reference/7.0/breaking-changes-7.0.html#hits-total-now-object-search-response. +func (s *MultiSearchService) RestTotalHitsAsInt(v bool) *MultiSearchService { + s.restTotalHitsAsInt = &v + return s +} + func (s *MultiSearchService) Do(ctx context.Context) (*MultiSearchResult, error) { // Build url path := "/_msearch" @@ -61,13 +74,16 @@ func (s *MultiSearchService) Do(ctx context.Context) (*MultiSearchResult, error) // Parameters params := make(url.Values) if s.pretty { - params.Set("pretty", fmt.Sprintf("%v", s.pretty)) + params.Set("pretty", fmt.Sprint(s.pretty)) } if v := s.maxConcurrentRequests; v != nil { - params.Set("max_concurrent_searches", fmt.Sprintf("%v", *v)) + params.Set("max_concurrent_searches", fmt.Sprint(*v)) } if v := s.preFilterShardSize; v != nil { - params.Set("pre_filter_shard_size", fmt.Sprintf("%v", *v)) + params.Set("pre_filter_shard_size", fmt.Sprint(*v)) + } + if v := s.restTotalHitsAsInt; v != nil { + params.Set("rest_total_hits_as_int", fmt.Sprint(*v)) } // Set body @@ -92,7 +108,12 @@ func (s *MultiSearchService) Do(ctx context.Context) (*MultiSearchResult, error) body := strings.Join(lines, "\n") + "\n" // add trailing \n // Get response - res, err := s.client.PerformRequest(ctx, "GET", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/mtermvectors.go b/vendor/gopkg.in/olivere/elastic.v6/mtermvectors.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/mtermvectors.go rename to vendor/gopkg.in/olivere/elastic.v6/mtermvectors.go index da0ca70c5d..ecd7a1d9cc 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/mtermvectors.go +++ b/vendor/gopkg.in/olivere/elastic.v6/mtermvectors.go @@ -11,14 +11,14 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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/5.2/docs-multi-termvectors.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-multi-termvectors.html // for documentation. type MultiTermvectorService struct { client *Client @@ -198,7 +198,7 @@ func (s *MultiTermvectorService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.fieldStatistics != nil { params.Set("field_statistics", fmt.Sprintf("%v", *s.fieldStatistics)) @@ -278,7 +278,12 @@ func (s *MultiTermvectorService) Do(ctx context.Context) (*MultiTermvectorRespon } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v6/nodes_info.go b/vendor/gopkg.in/olivere/elastic.v6/nodes_info.go new file mode 100644 index 0000000000..3490d7f1c8 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/nodes_info.go @@ -0,0 +1,366 @@ +// 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 ( + "context" + "fmt" + "net/url" + "strings" + "time" + + "github.com/olivere/elastic/uritemplates" +) + +// NodesInfoService allows to retrieve one or more or all of the +// cluster nodes information. +// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/6.8/cluster-nodes-info.html. +type NodesInfoService struct { + client *Client + pretty bool + nodeId []string + metric []string + flatSettings *bool + human *bool +} + +// NewNodesInfoService creates a new NodesInfoService. +func NewNodesInfoService(client *Client) *NodesInfoService { + return &NodesInfoService{ + client: client, + nodeId: []string{"_all"}, + metric: []string{"_all"}, + } +} + +// 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 *NodesInfoService) NodeId(nodeId ...string) *NodesInfoService { + s.nodeId = append(s.nodeId, nodeId...) + return s +} + +// Metric is a list of metrics you wish returned. Leave empty to return all. +// Valid metrics are: settings, os, process, jvm, thread_pool, network, +// transport, http, and plugins. +func (s *NodesInfoService) Metric(metric ...string) *NodesInfoService { + s.metric = append(s.metric, metric...) + return s +} + +// FlatSettings returns settings in flat format (default: false). +func (s *NodesInfoService) FlatSettings(flatSettings bool) *NodesInfoService { + s.flatSettings = &flatSettings + return s +} + +// Human indicates whether to return time and byte values in human-readable format. +func (s *NodesInfoService) Human(human bool) *NodesInfoService { + s.human = &human + return s +} + +// Pretty indicates whether to indent the returned JSON. +func (s *NodesInfoService) Pretty(pretty bool) *NodesInfoService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *NodesInfoService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_nodes/{node_id}/{metric}", map[string]string{ + "node_id": strings.Join(s.nodeId, ","), + "metric": strings.Join(s.metric, ","), + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.flatSettings != nil { + params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings)) + } + if s.human != nil { + params.Set("human", fmt.Sprintf("%v", *s.human)) + } + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *NodesInfoService) Validate() error { + return nil +} + +// Do executes the operation. +func (s *NodesInfoService) Do(ctx context.Context) (*NodesInfoResponse, 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, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(NodesInfoResponse) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// NodesInfoResponse is the response of NodesInfoService.Do. +type NodesInfoResponse struct { + ClusterName string `json:"cluster_name"` + Nodes map[string]*NodesInfoNode `json:"nodes"` +} + +// NodesInfoNode represents information about a node in the cluster. +type NodesInfoNode struct { + // 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 the IP address, e.g. "192.168.1.2" + IP string `json:"ip"` + // Version is the Elasticsearch version running on the node, e.g. "1.4.3" + Version string `json:"version"` + // BuildHash is the Elasticsearch build bash, e.g. "36a29a7" + BuildHash string `json:"build_hash"` + + // TotalIndexingBuffer represents the total heap allowed to be used to + // hold recently indexed documents before they must be written to disk. + TotalIndexingBuffer int64 `json:"total_indexing_buffer"` // e.g. 16gb + // TotalIndexingBufferInBytes is the same as TotalIndexingBuffer, but + // expressed in bytes. + TotalIndexingBufferInBytes string `json:"total_indexing_buffer_in_bytes"` + + // Roles of the node, e.g. [master, ingest, data] + Roles []string `json:"roles"` + + // Attributes of the node. + Attributes map[string]string `json:"attributes"` + + // Settings of the node, e.g. paths and pidfile. + Settings map[string]interface{} `json:"settings"` + + // OS information, e.g. CPU and memory. + OS *NodesInfoNodeOS `json:"os"` + + // Process information, e.g. max file descriptors. + Process *NodesInfoNodeProcess `json:"process"` + + // JVM information, e.g. VM version. + JVM *NodesInfoNodeJVM `json:"jvm"` + + // ThreadPool information. + ThreadPool *NodesInfoNodeThreadPool `json:"thread_pool"` + + // Network information. + Transport *NodesInfoNodeTransport `json:"transport"` + + // HTTP information. + HTTP *NodesInfoNodeHTTP `json:"http"` + + // Plugins information. + Plugins []*NodesInfoNodePlugin `json:"plugins"` + + // Modules information. + Modules []*NodesInfoNodeModule `json:"modules"` + + // Ingest information. + Ingest *NodesInfoNodeIngest `json:"ingest"` +} + +// HasRole returns true if the node fulfills the given role. +func (n *NodesInfoNode) HasRole(role string) bool { + for _, r := range n.Roles { + if r == role { + return true + } + } + return false +} + +// IsMaster returns true if the node is a master node. +func (n *NodesInfoNode) IsMaster() bool { + return n.HasRole("master") +} + +// IsData returns true if the node is a data node. +func (n *NodesInfoNode) IsData() bool { + return n.HasRole("data") +} + +// IsIngest returns true if the node is an ingest node. +func (n *NodesInfoNode) IsIngest() bool { + return n.HasRole("ingest") +} + +// NodesInfoNodeOS represents OS-specific details about a node. +type NodesInfoNodeOS struct { + RefreshInterval string `json:"refresh_interval"` // e.g. 1s + RefreshIntervalInMillis int `json:"refresh_interval_in_millis"` // e.g. 1000 + Name string `json:"name"` // e.g. Linux + Arch string `json:"arch"` // e.g. amd64 + Version string `json:"version"` // e.g. 4.9.87-linuxkit-aufs + AvailableProcessors int `json:"available_processors"` // e.g. 4 + AllocatedProcessors int `json:"allocated_processors"` // e.g. 4 +} + +// NodesInfoNodeProcess represents process-related information. +type NodesInfoNodeProcess struct { + RefreshInterval string `json:"refresh_interval"` // e.g. 1s + RefreshIntervalInMillis int64 `json:"refresh_interval_in_millis"` // e.g. 1000 + ID int `json:"id"` // process id, e.g. 87079 + Mlockall bool `json:"mlockall"` // e.g. false +} + +// NodesInfoNodeJVM represents JVM-related information. +type NodesInfoNodeJVM struct { + PID int `json:"pid"` // process id, e.g. 87079 + Version string `json:"version"` // e.g. "1.8.0_161" + VMName string `json:"vm_name"` // e.g. "OpenJDK 64-Bit Server VM" + VMVersion string `json:"vm_version"` // e.g. "25.161-b14" + VMVendor string `json:"vm_vendor"` // e.g. "Oracle Corporation" + StartTime time.Time `json:"start_time"` // e.g. "2018-03-30T11:06:36.644Z" + StartTimeInMillis int64 `json:"start_time_in_millis"` // e.g. 1522407996644 + + // Mem information + Mem struct { + HeapInit string `json:"heap_init"` // e.g. "1gb" + HeapInitInBytes int `json:"heap_init_in_bytes"` // e.g. 1073741824 + HeapMax string `json:"heap_max"` // e.g. "1007.3mb" + HeapMaxInBytes int `json:"heap_max_in_bytes"` // e.g. 1056309248 + NonHeapInit string `json:"non_heap_init"` // e.g. "2.4mb" + NonHeapInitInBytes int `json:"non_heap_init_in_bytes"` // e.g. 2555904 + NonHeapMax string `json:"non_heap_max"` // e.g. "0b" + NonHeapMaxInBytes int `json:"non_heap_max_in_bytes"` // e.g. 0 + DirectMax string `json:"direct_max"` // e.g. "1007.3mb" + DirectMaxInBytes int `json:"direct_max_in_bytes"` // e.g. 1056309248 + } `json:"mem"` + + GCCollectors []string `json:"gc_collectors"` // e.g. ["ParNew", "ConcurrentMarkSweep"] + MemoryPools []string `json:"memory_pools"` // e.g. ["Code Cache", "Metaspace", "Compressed Class Space", "Par Eden Space", "Par Survivor Space", "CMS Old Gen"] + + // UsingCompressedOrdinaryObjectPointers should be a bool, but is a + // string in 6.2.3. We use an interface{} for now so that it won't break + // when this will be fixed in later versions of Elasticsearch. + UsingCompressedOrdinaryObjectPointers interface{} `json:"using_compressed_ordinary_object_pointers"` + + InputArguments []string `json:"input_arguments"` // e.g. ["-Xms1g", "-Xmx1g" ...] +} + +// NodesInfoNodeThreadPool represents information about the thread pool. +type NodesInfoNodeThreadPool struct { + ForceMerge *NodesInfoNodeThreadPoolSection `json:"force_merge"` + FetchShardStarted *NodesInfoNodeThreadPoolSection `json:"fetch_shard_started"` + Listener *NodesInfoNodeThreadPoolSection `json:"listener"` + Index *NodesInfoNodeThreadPoolSection `json:"index"` + Refresh *NodesInfoNodeThreadPoolSection `json:"refresh"` + Generic *NodesInfoNodeThreadPoolSection `json:"generic"` + Warmer *NodesInfoNodeThreadPoolSection `json:"warmer"` + Search *NodesInfoNodeThreadPoolSection `json:"search"` + Flush *NodesInfoNodeThreadPoolSection `json:"flush"` + FetchShardStore *NodesInfoNodeThreadPoolSection `json:"fetch_shard_store"` + Management *NodesInfoNodeThreadPoolSection `json:"management"` + Get *NodesInfoNodeThreadPoolSection `json:"get"` + Bulk *NodesInfoNodeThreadPoolSection `json:"bulk"` + Snapshot *NodesInfoNodeThreadPoolSection `json:"snapshot"` + + Percolate *NodesInfoNodeThreadPoolSection `json:"percolate"` // check + Bench *NodesInfoNodeThreadPoolSection `json:"bench"` // check + Suggest *NodesInfoNodeThreadPoolSection `json:"suggest"` // deprecated + Optimize *NodesInfoNodeThreadPoolSection `json:"optimize"` // deprecated + Merge *NodesInfoNodeThreadPoolSection `json:"merge"` // deprecated +} + +// NodesInfoNodeThreadPoolSection represents information about a certain +// type of thread pool, e.g. for indexing or searching. +type NodesInfoNodeThreadPoolSection struct { + Type string `json:"type"` // e.g. fixed, scaling, or fixed_auto_queue_size + Min int `json:"min"` // e.g. 4 + Max int `json:"max"` // e.g. 4 + KeepAlive string `json:"keep_alive"` // e.g. "5m" + QueueSize interface{} `json:"queue_size"` // e.g. "1k" or -1 +} + +// NodesInfoNodeTransport represents transport-related information. +type NodesInfoNodeTransport struct { + BoundAddress []string `json:"bound_address"` + PublishAddress string `json:"publish_address"` + Profiles map[string]*NodesInfoNodeTransportProfile `json:"profiles"` +} + +// NodesInfoNodeTransportProfile represents a transport profile. +type NodesInfoNodeTransportProfile struct { + BoundAddress []string `json:"bound_address"` + PublishAddress string `json:"publish_address"` +} + +// NodesInfoNodeHTTP represents HTTP-related information. +type NodesInfoNodeHTTP struct { + BoundAddress []string `json:"bound_address"` // e.g. ["127.0.0.1:9200", "[fe80::1]:9200", "[::1]:9200"] + PublishAddress string `json:"publish_address"` // e.g. "127.0.0.1:9300" + MaxContentLength string `json:"max_content_length"` // e.g. "100mb" + MaxContentLengthInBytes int64 `json:"max_content_length_in_bytes"` +} + +// NodesInfoNodePlugin represents information about a plugin. +type NodesInfoNodePlugin struct { + Name string `json:"name"` // e.g. "ingest-geoip" + Version string `json:"version"` // e.g. "6.2.3" + ElasticsearchVersion string `json:"elasticsearch_version"` + JavaVersion string `json:"java_version"` + Description string `json:"description"` // e.g. "Ingest processor ..." + Classname string `json:"classname"` // e.g. "org.elasticsearch.ingest.geoip.IngestGeoIpPlugin" + ExtendedPlugins []string `json:"extended_plugins"` + HasNativeController bool `json:"has_native_controller"` + RequiresKeystore bool `json:"requires_keystore"` +} + +// NodesInfoNodeModule represents information about a module. +type NodesInfoNodeModule struct { + Name string `json:"name"` // e.g. "ingest-geoip" + Version string `json:"version"` // e.g. "6.2.3" + ElasticsearchVersion string `json:"elasticsearch_version"` + JavaVersion string `json:"java_version"` + Description string `json:"description"` // e.g. "Ingest processor ..." + Classname string `json:"classname"` // e.g. "org.elasticsearch.ingest.geoip.IngestGeoIpPlugin" + ExtendedPlugins []string `json:"extended_plugins"` + HasNativeController bool `json:"has_native_controller"` + RequiresKeystore bool `json:"requires_keystore"` +} + +// NodesInfoNodeIngest represents information about the ingester. +type NodesInfoNodeIngest struct { + Processors []*NodesInfoNodeIngestProcessorInfo `json:"processors"` +} + +// NodesInfoNodeIngestProcessorInfo represents ingest processor info. +type NodesInfoNodeIngestProcessorInfo struct { + Type string `json:"type"` // e.g. append, convert, date etc. +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/nodes_stats.go b/vendor/gopkg.in/olivere/elastic.v6/nodes_stats.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/nodes_stats.go rename to vendor/gopkg.in/olivere/elastic.v6/nodes_stats.go index a955bb4260..7c5f0c9d61 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/nodes_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v6/nodes_stats.go @@ -11,7 +11,7 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // NodesStatsService returns node statistics. @@ -165,7 +165,7 @@ func (s *NodesStatsService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if len(s.completionFields) > 0 { params.Set("completion_fields", strings.Join(s.completionFields, ",")) @@ -213,7 +213,11 @@ func (s *NodesStatsService) Do(ctx context.Context) (*NodesStatsResponse, error) } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -316,26 +320,21 @@ type NodesStatsDocsStats struct { } 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"` + Size string `json:"size"` + SizeInBytes int64 `json:"size_in_bytes"` } 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"` + 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"` Types map[string]*NodesStatsIndexingStats `json:"types"` // stats for individual types } @@ -495,10 +494,8 @@ type NodesStatsRequestCacheStats struct { } 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"` + CurrentAsSource int `json:"current_as_source"` + CurrentAsTarget int `json:"current_as_target"` } type NodesStatsNodeOS struct { diff --git a/vendor/gopkg.in/olivere/elastic.v5/ping.go b/vendor/gopkg.in/olivere/elastic.v6/ping.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/ping.go rename to vendor/gopkg.in/olivere/elastic.v6/ping.go index a97ddeceb4..5c2d34f009 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/ping.go +++ b/vendor/gopkg.in/olivere/elastic.v6/ping.go @@ -86,7 +86,7 @@ func (s *PingService) Do(ctx context.Context) (*PingResult, int, error) { params.Set("timeout", s.timeout) } if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if len(params) > 0 { url_ += "?" + params.Encode() diff --git a/vendor/gopkg.in/olivere/elastic.v5/plugins.go b/vendor/gopkg.in/olivere/elastic.v6/plugins.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/plugins.go rename to vendor/gopkg.in/olivere/elastic.v6/plugins.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/query.go b/vendor/gopkg.in/olivere/elastic.v6/query.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/query.go rename to vendor/gopkg.in/olivere/elastic.v6/query.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/reindex.go b/vendor/gopkg.in/olivere/elastic.v6/reindex.go similarity index 77% rename from vendor/gopkg.in/olivere/elastic.v5/reindex.go rename to vendor/gopkg.in/olivere/elastic.v6/reindex.go index 71e0807ee2..1cdf2f2fa0 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/reindex.go +++ b/vendor/gopkg.in/olivere/elastic.v6/reindex.go @@ -6,12 +6,14 @@ package elastic import ( "context" + "errors" "fmt" + "net/http" "net/url" ) // ReindexService is a method to copy documents from one index to another. -// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.0/docs-reindex.html. +// It is documented at https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-reindex.html. type ReindexService struct { client *Client pretty bool @@ -20,13 +22,14 @@ type ReindexService struct { waitForActiveShards string waitForCompletion *bool requestsPerSecond *int - slices *int + slices interface{} body interface{} source *ReindexSource destination *ReindexDestination conflicts string size *int script *Script + headers http.Header } // NewReindexService creates a new ReindexService. @@ -53,13 +56,20 @@ func (s *ReindexService) RequestsPerSecond(requestsPerSecond int) *ReindexServic } // Slices specifies the number of slices this task should be divided into. Defaults to 1. -func (s *ReindexService) Slices(slices int) *ReindexService { - s.slices = &slices +// It used to be a number, but can be set to "auto" as of 6.7. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-reindex.html#docs-reindex-slice +// for details. +func (s *ReindexService) Slices(slices interface{}) *ReindexService { + s.slices = slices return s } // Refresh indicates whether Elasticsearch should refresh the effected indexes // immediately. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html +// for details. func (s *ReindexService) Refresh(refresh string) *ReindexService { s.refresh = refresh return s @@ -79,6 +89,15 @@ func (s *ReindexService) WaitForCompletion(waitForCompletion bool) *ReindexServi return s } +// Header sets headers on the request +func (s *ReindexService) Header(name string, value string) *ReindexService { + if s.headers == nil { + s.headers = http.Header{} + } + s.headers.Add(name, value) + return s +} + // Pretty indicates that the JSON response be indented and human readable. func (s *ReindexService) Pretty(pretty bool) *ReindexService { s.pretty = pretty @@ -175,7 +194,7 @@ func (s *ReindexService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.refresh != "" { params.Set("refresh", s.refresh) @@ -187,7 +206,7 @@ func (s *ReindexService) buildURL() (string, url.Values, error) { params.Set("requests_per_second", fmt.Sprintf("%v", *s.requestsPerSecond)) } if s.slices != nil { - params.Set("slices", fmt.Sprintf("%v", *s.slices)) + params.Set("slices", fmt.Sprintf("%v", s.slices)) } if s.waitForActiveShards != "" { params.Set("wait_for_active_shards", s.waitForActiveShards) @@ -207,7 +226,7 @@ func (s *ReindexService) Validate() error { if s.source == nil { invalid = append(invalid, "Source") } else { - if len(s.source.indices) == 0 { + if len(s.source.request.indices) == 0 { invalid = append(invalid, "Source.Index") } } @@ -277,7 +296,13 @@ func (s *ReindexService) Do(ctx context.Context) (*BulkIndexByScrollResponse, er } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + Headers: s.headers, + }) if err != nil { return nil, err } @@ -287,6 +312,7 @@ func (s *ReindexService) Do(ctx context.Context) (*BulkIndexByScrollResponse, er if err := s.client.decoder.Decode(res.Body, ret); err != nil { return nil, err } + ret.Header = res.Header return ret, nil } @@ -319,7 +345,13 @@ func (s *ReindexService) DoAsync(ctx context.Context) (*StartTaskResult, error) } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + Headers: s.headers, + }) if err != nil { return nil, err } @@ -329,6 +361,7 @@ func (s *ReindexService) DoAsync(ctx context.Context) (*StartTaskResult, error) if err := s.client.decoder.Decode(res.Body, ret); err != nil { return nil, err } + ret.Header = res.Header return ret, nil } @@ -336,144 +369,157 @@ func (s *ReindexService) DoAsync(ctx context.Context) (*StartTaskResult, error) // ReindexSource specifies the source of a Reindex process. type ReindexSource struct { - searchType string - indices []string - types []string - routing *string - preference *string - requestCache *bool - scroll string - query Query - sorts []SortInfo - sorters []Sorter - searchSource *SearchSource - remoteInfo *ReindexRemoteInfo + searchType string // default in ES is "query_then_fetch" + request *SearchRequest + /* + indices []string + types []string + routing *string + preference *string + requestCache *bool + scroll string + query Query + sorts []SortInfo + sorters []Sorter + searchSource *SearchSource + */ + remoteInfo *ReindexRemoteInfo } // NewReindexSource creates a new ReindexSource. func NewReindexSource() *ReindexSource { - return &ReindexSource{} + return &ReindexSource{ + request: NewSearchRequest(), + } +} + +// Request specifies the search request used for source. +func (r *ReindexSource) Request(request *SearchRequest) *ReindexSource { + if request == nil { + r.request = NewSearchRequest() + } else { + r.request = request + } + return r } // SearchType is the search operation type. Possible values are // "query_then_fetch" and "dfs_query_then_fetch". func (r *ReindexSource) SearchType(searchType string) *ReindexSource { - r.searchType = searchType + r.request = r.request.SearchType(searchType) return r } func (r *ReindexSource) SearchTypeDfsQueryThenFetch() *ReindexSource { - return r.SearchType("dfs_query_then_fetch") + r.request = r.request.SearchType("dfs_query_then_fetch") + return r } func (r *ReindexSource) SearchTypeQueryThenFetch() *ReindexSource { - return r.SearchType("query_then_fetch") + r.request = r.request.SearchType("query_then_fetch") + return r } func (r *ReindexSource) Index(indices ...string) *ReindexSource { - r.indices = append(r.indices, indices...) + r.request = r.request.Index(indices...) return r } func (r *ReindexSource) Type(types ...string) *ReindexSource { - r.types = append(r.types, types...) + r.request = r.request.Type(types...) return r } func (r *ReindexSource) Preference(preference string) *ReindexSource { - r.preference = &preference + r.request = r.request.Preference(preference) return r } func (r *ReindexSource) RequestCache(requestCache bool) *ReindexSource { - r.requestCache = &requestCache + r.request = r.request.RequestCache(requestCache) return r } func (r *ReindexSource) Scroll(scroll string) *ReindexSource { - r.scroll = scroll + r.request = r.request.Scroll(scroll) return r } func (r *ReindexSource) Query(query Query) *ReindexSource { - r.query = query + r.request = r.request.Query(query) return r } // Sort adds a sort order. -func (s *ReindexSource) Sort(field string, ascending bool) *ReindexSource { - s.sorts = append(s.sorts, SortInfo{Field: field, Ascending: ascending}) - return s +func (r *ReindexSource) Sort(field string, ascending bool) *ReindexSource { + r.request = r.request.Sort(field, ascending) + return r } // SortWithInfo adds a sort order. -func (s *ReindexSource) SortWithInfo(info SortInfo) *ReindexSource { - s.sorts = append(s.sorts, info) - return s +func (r *ReindexSource) SortWithInfo(info SortInfo) *ReindexSource { + r.request = r.request.SortWithInfo(info) + return r } // SortBy adds a sort order. -func (s *ReindexSource) SortBy(sorter ...Sorter) *ReindexSource { - s.sorters = append(s.sorters, sorter...) - return s +func (r *ReindexSource) SortBy(sorter ...Sorter) *ReindexSource { + r.request = r.request.SortBy(sorter...) + return r +} + +// FetchSource indicates whether the response should contain the stored +// _source for every hit. +func (r *ReindexSource) FetchSource(fetchSource bool) *ReindexSource { + r.request = r.request.FetchSource(fetchSource) + return r +} + +// FetchSourceIncludeExclude specifies that _source should be returned +// with each hit, where "include" and "exclude" serve as a simple wildcard +// matcher that gets applied to its fields +// (e.g. include := []string{"obj1.*","obj2.*"}, exclude := []string{"description.*"}). +func (r *ReindexSource) FetchSourceIncludeExclude(include, exclude []string) *ReindexSource { + r.request = r.request.FetchSourceIncludeExclude(include, exclude) + return r +} + +// FetchSourceContext indicates how the _source should be fetched. +func (r *ReindexSource) FetchSourceContext(fsc *FetchSourceContext) *ReindexSource { + r.request = r.request.FetchSourceContext(fsc) + return r } // RemoteInfo sets up reindexing from a remote cluster. -func (s *ReindexSource) RemoteInfo(ri *ReindexRemoteInfo) *ReindexSource { - s.remoteInfo = ri - return s +func (r *ReindexSource) RemoteInfo(ri *ReindexRemoteInfo) *ReindexSource { + r.remoteInfo = ri + return r } // Source returns a serializable JSON request for the request. func (r *ReindexSource) Source() (interface{}, error) { - source := make(map[string]interface{}) - - if r.query != nil { - src, err := r.query.Source() - if err != nil { - return nil, err - } - source["query"] = src - } else if r.searchSource != nil { - src, err := r.searchSource.Source() - if err != nil { - return nil, err - } - source["source"] = src + src, err := r.request.sourceAsMap() + if err != nil { + return nil, err + } + source, ok := src.(map[string]interface{}) + if !ok { + return nil, errors.New("unable to use SearchRequest as map[string]interface{}") } - if r.searchType != "" { - source["search_type"] = r.searchType + switch len(r.request.indices) { + case 1: + source["index"] = r.request.indices[0] + default: + source["index"] = r.request.indices } - - switch len(r.indices) { + switch len(r.request.types) { case 0: case 1: - source["index"] = r.indices[0] + source["type"] = r.request.types[0] default: - source["index"] = r.indices + source["type"] = r.request.types } - - switch len(r.types) { - case 0: - case 1: - source["type"] = r.types[0] - default: - source["type"] = r.types - } - - if r.preference != nil && *r.preference != "" { - source["preference"] = *r.preference - } - - if r.requestCache != nil { - source["request_cache"] = fmt.Sprintf("%v", *r.requestCache) - } - - if r.scroll != "" { - source["scroll"] = r.scroll - } - if r.remoteInfo != nil { src, err := r.remoteInfo.Source() if err != nil { @@ -481,29 +527,6 @@ func (r *ReindexSource) Source() (interface{}, error) { } source["remote"] = src } - - if len(r.sorters) > 0 { - var sortarr []interface{} - for _, sorter := range r.sorters { - src, err := sorter.Source() - if err != nil { - return nil, err - } - sortarr = append(sortarr, src) - } - source["sort"] = sortarr - } else if len(r.sorts) > 0 { - var sortarr []interface{} - for _, sort := range r.sorts { - src, err := sort.Source() - if err != nil { - return nil, err - } - sortarr = append(sortarr, src) - } - source["sort"] = sortarr - } - return source, nil } @@ -578,7 +601,7 @@ func (ri *ReindexRemoteInfo) 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/5.2/docs-reindex.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-reindex.html // fsourcer details. type ReindexDestination struct { index string @@ -588,6 +611,7 @@ type ReindexDestination struct { opType string version int64 // default is MATCH_ANY versionType string // default is "internal" + pipeline string } // NewReindexDestination returns a new ReindexDestination. @@ -637,7 +661,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/5.2/docs-index_.html#operation-type +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-index_.html#operation-type // for details. func (r *ReindexDestination) OpType(opType string) *ReindexDestination { r.opType = opType @@ -657,6 +681,12 @@ func (r *ReindexDestination) VersionType(versionType string) *ReindexDestination return r } +// Pipeline specifies the pipeline to use for reindexing. +func (r *ReindexDestination) Pipeline(pipeline string) *ReindexDestination { + r.pipeline = pipeline + return r +} + // Source returns a serializable JSON request for the request. func (r *ReindexDestination) Source() (interface{}, error) { source := make(map[string]interface{}) @@ -681,5 +711,8 @@ func (r *ReindexDestination) Source() (interface{}, error) { if r.versionType != "" { source["version_type"] = r.versionType } + if r.pipeline != "" { + source["pipeline"] = r.pipeline + } return source, nil } diff --git a/vendor/gopkg.in/olivere/elastic.v5/request.go b/vendor/gopkg.in/olivere/elastic.v6/request.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/request.go rename to vendor/gopkg.in/olivere/elastic.v6/request.go index da5a7216e5..288c837aba 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/request.go +++ b/vendor/gopkg.in/olivere/elastic.v6/request.go @@ -35,21 +35,20 @@ func (r *Request) SetBasicAuth(username, password string) { ((*http.Request)(r)).SetBasicAuth(username, password) } -// SetBody encodes the body in the request. Optionally, it performs GZIP compression. +// SetBody encodes the body in the request. You may pass a flag to +// compress the request via gzip. func (r *Request) SetBody(body interface{}, gzipCompress bool) error { switch b := body.(type) { case string: if gzipCompress { return r.setBodyGzip(b) - } else { - return r.setBodyString(b) } + return r.setBodyString(b) default: if gzipCompress { return r.setBodyGzip(body) - } else { - return r.setBodyJson(body) } + return r.setBodyJson(body) } } diff --git a/vendor/gopkg.in/olivere/elastic.v5/rescore.go b/vendor/gopkg.in/olivere/elastic.v6/rescore.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/rescore.go rename to vendor/gopkg.in/olivere/elastic.v6/rescore.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/rescorer.go b/vendor/gopkg.in/olivere/elastic.v6/rescorer.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/rescorer.go rename to vendor/gopkg.in/olivere/elastic.v6/rescorer.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/response.go b/vendor/gopkg.in/olivere/elastic.v6/response.go similarity index 62% rename from vendor/gopkg.in/olivere/elastic.v5/response.go rename to vendor/gopkg.in/olivere/elastic.v6/response.go index 4fcdc32d62..eae6a533cd 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/response.go +++ b/vendor/gopkg.in/olivere/elastic.v6/response.go @@ -6,10 +6,17 @@ package elastic import ( "encoding/json" + "errors" + "io" "io/ioutil" "net/http" ) +var ( + // ErrResponseSize is raised if a response body exceeds the given max body size. + ErrResponseSize = errors.New("elastic: response size too large") +) + // Response represents a response from Elasticsearch. type Response struct { // StatusCode is the HTTP status code, e.g. 200. @@ -22,16 +29,26 @@ type Response struct { } // newResponse creates a new response from the HTTP response. -func (c *Client) newResponse(res *http.Response) (*Response, error) { +func (c *Client) newResponse(res *http.Response, maxBodySize int64) (*Response, error) { r := &Response{ StatusCode: res.StatusCode, Header: res.Header, } if res.Body != nil { - slurp, err := ioutil.ReadAll(res.Body) + body := io.Reader(res.Body) + if maxBodySize > 0 { + if res.ContentLength > maxBodySize { + return nil, ErrResponseSize + } + body = io.LimitReader(body, maxBodySize+1) + } + slurp, err := ioutil.ReadAll(body) if err != nil { return nil, err } + if maxBodySize > 0 && int64(len(slurp)) > maxBodySize { + return nil, ErrResponseSize + } // HEAD requests return a body but no content if len(slurp) > 0 { r.Body = json.RawMessage(slurp) diff --git a/vendor/gopkg.in/olivere/elastic.v5/retrier.go b/vendor/gopkg.in/olivere/elastic.v6/retrier.go similarity index 82% rename from vendor/gopkg.in/olivere/elastic.v5/retrier.go rename to vendor/gopkg.in/olivere/elastic.v6/retrier.go index 46d3adfcb5..e05ca66c4f 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/retrier.go +++ b/vendor/gopkg.in/olivere/elastic.v6/retrier.go @@ -10,9 +10,16 @@ import ( "time" ) -// RetrierFunc specifies the signature of a Retry function. +// RetrierFunc specifies the signature of a Retry function, and is an adapter +// to allow the use of ordinary Retry functions. If f is a function with the +// appropriate signature, RetrierFunc(f) is a Retrier that calls f. type RetrierFunc func(context.Context, int, *http.Request, *http.Response, error) (time.Duration, bool, error) +// Retry calls f. +func (f RetrierFunc) Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error) { + return f(ctx, retry, req, resp, err) +} + // 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 diff --git a/vendor/gopkg.in/olivere/elastic.v5/retry.go b/vendor/gopkg.in/olivere/elastic.v6/retry.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/retry.go rename to vendor/gopkg.in/olivere/elastic.v6/retry.go diff --git a/vendor/gopkg.in/olivere/elastic.v6/run-es.sh b/vendor/gopkg.in/olivere/elastic.v6/run-es.sh new file mode 100644 index 0000000000..8b60fbc95d --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/run-es.sh @@ -0,0 +1,3 @@ +#!/bin/sh +VERSION=${VERSION:=6.4.0} +docker run --rm -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch-oss:$VERSION elasticsearch -Enetwork.host=_local_,_site_ -Enetwork.publish_host=_local_ diff --git a/vendor/gopkg.in/olivere/elastic.v5/script.go b/vendor/gopkg.in/olivere/elastic.v6/script.go similarity index 61% rename from vendor/gopkg.in/olivere/elastic.v5/script.go rename to vendor/gopkg.in/olivere/elastic.v6/script.go index eb27f27f0d..4b9e5ee09e 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/script.go +++ b/vendor/gopkg.in/olivere/elastic.v6/script.go @@ -4,12 +4,17 @@ package elastic -import "errors" +import ( + "encoding/json" + "errors" + "fmt" + "strings" +) -// Script holds all the paramaters necessary to compile or find in cache +// Script holds all the parameters necessary to compile or find in cache // and then execute a script. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-scripting.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting.html // for details of scripting. type Script struct { script string @@ -18,30 +23,26 @@ type Script struct { params map[string]interface{} } -// NewScript creates and initializes a new Script. +// NewScript creates and initializes a new Script. By default, it is of +// type "inline". Use NewScriptStored for a stored script (where type is "id"). func NewScript(script string) *Script { return &Script{ script: script, - typ: "", // default type is "inline" + typ: "inline", params: make(map[string]interface{}), } } -// NewScriptInline creates and initializes a new Script of type "inline". +// NewScriptInline creates and initializes a new inline script, i.e. code. func NewScriptInline(script string) *Script { return NewScript(script).Type("inline") } -// NewScriptId creates and initializes a new Script of type "id". -func NewScriptId(script string) *Script { +// NewScriptStored creates and initializes a new stored script. +func NewScriptStored(script string) *Script { return NewScript(script).Type("id") } -// NewScriptFile creates and initializes a new Script of type "file". -func NewScriptFile(script string) *Script { - return NewScript(script).Type("file") -} - // Script is either the cache key of the script to be compiled/executed // or the actual script source code for inline scripts. For indexed // scripts this is the id used in the request. For file scripts this is @@ -51,16 +52,15 @@ func (s *Script) Script(script string) *Script { return s } -// Type sets the type of script: "inline", "id", or "file". +// Type sets the type of script: "inline" or "id". func (s *Script) Type(typ string) *Script { s.typ = typ return s } -// 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/5.2/modules-scripting.html +// Lang sets the language of the script. The default scripting language +// is Painless ("painless"). +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting.html // for details. func (s *Script) Lang(lang string) *Script { s.lang = lang @@ -84,29 +84,42 @@ func (s *Script) Params(params map[string]interface{}) *Script { // Source returns the JSON serializable data for this Script. func (s *Script) Source() (interface{}, error) { - source := make(map[string]interface{}) - - // In 5.5 and earlier, the type can "inline", "id", or "file". - // In 5.6+, the type can be "source", "id", or "file". - // So we use "inline" here to keep compatibility with 5.5 and earlier. - // Notice that this will trigger a deprecation warning in 5.6. - if s.typ == "" || s.typ == "inline" { - source["inline"] = s.script - } else { - // "id" or "file" - source[s.typ] = s.script + if s.typ == "" && s.lang == "" && len(s.params) == 0 { + return s.script, nil + } + source := make(map[string]interface{}) + // Beginning with 6.0, the type can only be "source" or "id" + if s.typ == "" || s.typ == "inline" { + src, err := s.rawScriptSource(s.script) + if err != nil { + return nil, err + } + source["source"] = src + } else { + source["id"] = s.script } - if s.lang != "" { source["lang"] = s.lang } if len(s.params) > 0 { source["params"] = s.params } - return source, nil } +// rawScriptSource returns an embeddable script. If it uses a short +// script form, e.g. "ctx._source.likes++" (without the quotes), it +// is quoted. Otherwise it returns the raw script that will be directly +// embedded into the JSON data. +func (s *Script) rawScriptSource(script string) (interface{}, error) { + v := strings.TrimSpace(script) + if !strings.HasPrefix(v, "{") && !strings.HasPrefix(v, `"`) { + v = fmt.Sprintf("%q", v) + } + raw := json.RawMessage(v) + return &raw, nil +} + // -- Script Field -- // ScriptField is a single script field. diff --git a/vendor/gopkg.in/olivere/elastic.v6/script_delete.go b/vendor/gopkg.in/olivere/elastic.v6/script_delete.go new file mode 100644 index 0000000000..ef782b6047 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/script_delete.go @@ -0,0 +1,134 @@ +// 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 ( + "context" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// DeleteScriptService removes a stored script in Elasticsearch. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting.html +// for details. +type DeleteScriptService struct { + client *Client + pretty bool + id string + timeout string + masterTimeout string +} + +// NewDeleteScriptService creates a new DeleteScriptService. +func NewDeleteScriptService(client *Client) *DeleteScriptService { + return &DeleteScriptService{ + client: client, + } +} + +// Id is the script ID. +func (s *DeleteScriptService) Id(id string) *DeleteScriptService { + s.id = id + return s +} + +// Timeout is an explicit operation timeout. +func (s *DeleteScriptService) Timeout(timeout string) *DeleteScriptService { + s.timeout = timeout + return s +} + +// MasterTimeout is the timeout for connecting to master. +func (s *DeleteScriptService) MasterTimeout(masterTimeout string) *DeleteScriptService { + s.masterTimeout = masterTimeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *DeleteScriptService) Pretty(pretty bool) *DeleteScriptService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *DeleteScriptService) buildURL() (string, string, url.Values, error) { + var ( + err error + method = "DELETE" + path string + ) + + path, err = uritemplates.Expand("/_scripts/{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", "true") + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + if s.masterTimeout != "" { + params.Set("master_timestamp", s.masterTimeout) + } + return method, path, params, nil +} + +// Validate checks if the operation is valid. +func (s *DeleteScriptService) 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 *DeleteScriptService) Do(ctx context.Context) (*DeleteScriptResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + method, path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: method, + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(DeleteScriptResponse) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// DeleteScriptResponse is the result of deleting a stored script +// in Elasticsearch. +type DeleteScriptResponse struct { + AcknowledgedResponse +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/script_get.go b/vendor/gopkg.in/olivere/elastic.v6/script_get.go new file mode 100644 index 0000000000..e01ea89a19 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/script_get.go @@ -0,0 +1,117 @@ +// 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// GetScriptService reads a stored script in Elasticsearch. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting.html +// for details. +type GetScriptService struct { + client *Client + pretty bool + id string +} + +// NewGetScriptService creates a new GetScriptService. +func NewGetScriptService(client *Client) *GetScriptService { + return &GetScriptService{ + client: client, + } +} + +// Id is the script ID. +func (s *GetScriptService) Id(id string) *GetScriptService { + s.id = id + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *GetScriptService) Pretty(pretty bool) *GetScriptService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *GetScriptService) buildURL() (string, string, url.Values, error) { + var ( + err error + method = "GET" + path string + ) + + path, err = uritemplates.Expand("/_scripts/{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", "true") + } + return method, path, params, nil +} + +// Validate checks if the operation is valid. +func (s *GetScriptService) 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 *GetScriptService) Do(ctx context.Context) (*GetScriptResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + method, path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Get HTTP response + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: method, + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(GetScriptResponse) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// GetScriptResponse is the result of getting a stored script +// from Elasticsearch. +type GetScriptResponse struct { + Id string `json:"_id"` + Found bool `json:"found"` + Script json.RawMessage `json:"script"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/script_put.go b/vendor/gopkg.in/olivere/elastic.v6/script_put.go new file mode 100644 index 0000000000..b0d71d102f --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/script_put.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 ( + "context" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// PutScriptService adds or updates a stored script in Elasticsearch. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting.html +// for details. +type PutScriptService struct { + client *Client + pretty bool + id string + context string + timeout string + masterTimeout string + bodyJson interface{} + bodyString string +} + +// NewPutScriptService creates a new PutScriptService. +func NewPutScriptService(client *Client) *PutScriptService { + return &PutScriptService{ + client: client, + } +} + +// Id is the script ID. +func (s *PutScriptService) Id(id string) *PutScriptService { + s.id = id + return s +} + +// Context specifies the script context (optional). +func (s *PutScriptService) Context(context string) *PutScriptService { + s.context = context + return s +} + +// Timeout is an explicit operation timeout. +func (s *PutScriptService) Timeout(timeout string) *PutScriptService { + s.timeout = timeout + return s +} + +// MasterTimeout is the timeout for connecting to master. +func (s *PutScriptService) MasterTimeout(masterTimeout string) *PutScriptService { + s.masterTimeout = masterTimeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *PutScriptService) Pretty(pretty bool) *PutScriptService { + s.pretty = pretty + return s +} + +// BodyJson is the document as a serializable JSON interface. +func (s *PutScriptService) BodyJson(body interface{}) *PutScriptService { + s.bodyJson = body + return s +} + +// BodyString is the document encoded as a string. +func (s *PutScriptService) BodyString(body string) *PutScriptService { + s.bodyString = body + return s +} + +// buildURL builds the URL for the operation. +func (s *PutScriptService) buildURL() (string, string, url.Values, error) { + var ( + err error + method = "PUT" + path string + ) + + if s.context != "" { + path, err = uritemplates.Expand("/_scripts/{id}/{context}", map[string]string{ + "id": s.id, + "context": s.context, + }) + } else { + path, err = uritemplates.Expand("/_scripts/{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", "true") + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + if s.masterTimeout != "" { + params.Set("master_timestamp", s.masterTimeout) + } + return method, path, params, nil +} + +// Validate checks if the operation is valid. +func (s *PutScriptService) 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 *PutScriptService) Do(ctx context.Context) (*PutScriptResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Get URL for request + method, 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, PerformRequestOptions{ + Method: method, + Path: path, + Params: params, + Body: body, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(PutScriptResponse) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// PutScriptResponse is the result of saving a stored script +// in Elasticsearch. +type PutScriptResponse struct { + AcknowledgedResponse +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/scroll.go b/vendor/gopkg.in/olivere/elastic.v6/scroll.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v5/scroll.go rename to vendor/gopkg.in/olivere/elastic.v6/scroll.go index cf83246b26..233d87d9b2 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/scroll.go +++ b/vendor/gopkg.in/olivere/elastic.v6/scroll.go @@ -8,11 +8,12 @@ import ( "context" "fmt" "io" + "net/http" "net/url" "strings" "sync" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) const ( @@ -36,6 +37,8 @@ type ScrollService struct { ignoreUnavailable *bool allowNoIndices *bool expandWildcards string + headers http.Header + maxResponseSize int64 filterPath []string mu sync.RWMutex @@ -52,6 +55,15 @@ func NewScrollService(client *Client) *ScrollService { return builder } +// Header sets headers on the request +func (s *ScrollService) Header(name string, value string) *ScrollService { + if s.headers == nil { + s.headers = http.Header{} + } + s.headers.Add(name, value) + return s +} + // Retrier allows to set specific retry logic for this ScrollService. // If not specified, it will use the client's default retrier. func (s *ScrollService) Retrier(retrier Retrier) *ScrollService { @@ -85,7 +97,7 @@ func (s *ScrollService) Scroll(keepAlive string) *ScrollService { } // KeepAlive sets the maximum time after which the cursor will expire. -// It is "2m" by default. +// It is "5m" by default. func (s *ScrollService) KeepAlive(keepAlive string) *ScrollService { s.keepAlive = keepAlive return s @@ -101,7 +113,7 @@ func (s *ScrollService) Size(size int) *ScrollService { // 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 SearchService. +// other properties of the ScanService. func (s *ScrollService) Body(body interface{}) *ScrollService { s.body = body return s @@ -126,7 +138,7 @@ func (s *ScrollService) Query(query Query) *ScrollService { // 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 +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-post-filter.html // for details. func (s *ScrollService) PostFilter(postFilter Query) *ScrollService { s.ss = s.ss.PostFilter(postFilter) @@ -135,7 +147,7 @@ func (s *ScrollService) PostFilter(postFilter Query) *ScrollService { // 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 +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-scroll.html#sliced-scroll // for details. func (s *ScrollService) Slice(sliceQuery Query) *ScrollService { s.ss = s.ss.Slice(sliceQuery) @@ -156,7 +168,7 @@ func (s *ScrollService) FetchSourceContext(fetchSourceContext *FetchSourceContex } // 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. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-version.html. func (s *ScrollService) Version(version bool) *ScrollService { s.ss = s.ss.Version(version) return s @@ -228,9 +240,16 @@ func (s *ScrollService) ExpandWildcards(expandWildcards string) *ScrollService { return s } +// MaxResponseSize sets an upper limit on the response body size that we accept, +// to guard against OOM situations. +func (s *ScrollService) MaxResponseSize(maxResponseSize int64) *ScrollService { + s.maxResponseSize = maxResponseSize + 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.6/common-options.html#common-options-response-filtering. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/common-options.html#common-options-response-filtering. func (s *ScrollService) FilterPath(filterPath ...string) *ScrollService { s.filterPath = append(s.filterPath, filterPath...) return s @@ -275,7 +294,7 @@ func (s *ScrollService) Clear(ctx context.Context) error { ScrollId: []string{scrollId}, } - _, err := s.client.PerformRequestWithOptions(ctx, PerformRequestOptions{ + _, err := s.client.PerformRequest(ctx, PerformRequestOptions{ Method: "DELETE", Path: path, Params: params, @@ -306,12 +325,14 @@ func (s *ScrollService) first(ctx context.Context) (*SearchResult, error) { } // Get HTTP response - res, err := s.client.PerformRequestWithOptions(ctx, PerformRequestOptions{ - Method: "POST", - Path: path, - Params: params, - Body: body, - Retrier: s.retrier, + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + Retrier: s.retrier, + Headers: s.headers, + MaxResponseSize: s.maxResponseSize, }) if err != nil { return nil, err @@ -359,7 +380,7 @@ func (s *ScrollService) buildFirstURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.size != nil && *s.size > 0 { params.Set("size", fmt.Sprintf("%d", *s.size)) @@ -431,12 +452,14 @@ func (s *ScrollService) next(ctx context.Context) (*SearchResult, error) { } // Get HTTP response - res, err := s.client.PerformRequestWithOptions(ctx, PerformRequestOptions{ - Method: "POST", - Path: path, - Params: params, - Body: body, - Retrier: s.retrier, + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + Retrier: s.retrier, + Headers: s.headers, + MaxResponseSize: s.maxResponseSize, }) if err != nil { return nil, err @@ -463,7 +486,12 @@ func (s *ScrollService) buildNextURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") + } + if len(s.filterPath) > 0 { + // Always add "hits._scroll_id", otherwise we cannot scroll + s.filterPath = append(s.filterPath, "_scroll_id") + params.Set("filter_path", strings.Join(s.filterPath, ",")) } return path, params, nil diff --git a/vendor/gopkg.in/olivere/elastic.v5/search.go b/vendor/gopkg.in/olivere/elastic.v6/search.go similarity index 68% rename from vendor/gopkg.in/olivere/elastic.v5/search.go rename to vendor/gopkg.in/olivere/elastic.v6/search.go index f971a53cf9..22dda6596a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search.go @@ -12,25 +12,28 @@ import ( "reflect" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // Search for documents in Elasticsearch. type SearchService struct { - client *Client - 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 + client *Client + 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 + maxResponseSize int64 + restTotalHitsAsInt *bool + seqNoPrimaryTerm *bool } // NewSearchService creates a new service for searching in Elasticsearch. @@ -60,7 +63,7 @@ func (s *SearchService) Source(source interface{}) *SearchService { // FilterPath allows reducing the response, a mechanism known as // response filtering and described here: -// https://www.elastic.co/guide/en/elasticsearch/reference/5.6/common-options.html#common-options-response-filtering. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/common-options.html#common-options-response-filtering. func (s *SearchService) FilterPath(filterPath ...string) *SearchService { s.filterPath = append(s.filterPath, filterPath...) return s @@ -119,7 +122,7 @@ func (s *SearchService) TerminateAfter(terminateAfter int) *SearchService { // SearchType sets the search operation type. Valid values are: // "dfs_query_then_fetch" and "query_then_fetch". -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-search-type.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-search-type.html // for details. func (s *SearchService) SearchType(searchType string) *SearchService { s.searchType = searchType @@ -246,12 +249,40 @@ func (s *SearchService) SortWithInfo(info SortInfo) *SearchService { return s } -// SortBy adds a sort order. +// SortBy adds a sort order. func (s *SearchService) SortBy(sorter ...Sorter) *SearchService { s.searchSource = s.searchSource.SortBy(sorter...) return s } +// DocvalueField adds a single field to load from the field data cache +// and return as part of the search. +func (s *SearchService) DocvalueField(docvalueField string) *SearchService { + s.searchSource = s.searchSource.DocvalueField(docvalueField) + return s +} + +// DocvalueFieldWithFormat adds a single field to load from the field data cache +// and return as part of the search. +func (s *SearchService) DocvalueFieldWithFormat(docvalueField DocvalueField) *SearchService { + s.searchSource = s.searchSource.DocvalueFieldWithFormat(docvalueField) + return s +} + +// DocvalueFields adds one or more fields to load from the field data cache +// and return as part of the search. +func (s *SearchService) DocvalueFields(docvalueFields ...string) *SearchService { + s.searchSource = s.searchSource.DocvalueFields(docvalueFields...) + return s +} + +// DocvalueFieldsWithFormat adds one or more fields to load from the field data cache +// and return as part of the search. +func (s *SearchService) DocvalueFieldsWithFormat(docvalueFields ...DocvalueField) *SearchService { + s.searchSource = s.searchSource.DocvalueFieldsWithFormat(docvalueFields...) + return s +} + // NoStoredFields indicates that no stored fields should be loaded, resulting in only // id and type to be returned per field. func (s *SearchService) NoStoredFields() *SearchService { @@ -284,7 +315,7 @@ func (s *SearchService) TrackScores(trackScores bool) *SearchService { // 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.6/search-request-search-after.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-search-after.html func (s *SearchService) SearchAfter(sortValues ...interface{}) *SearchService { s.searchSource = s.searchSource.SearchAfter(sortValues...) return s @@ -312,6 +343,32 @@ func (s *SearchService) ExpandWildcards(expandWildcards string) *SearchService { return s } +// MaxResponseSize sets an upper limit on the response body size that we accept, +// to guard against OOM situations. +func (s *SearchService) MaxResponseSize(maxResponseSize int64) *SearchService { + s.maxResponseSize = maxResponseSize + return s +} + +// RestTotalHitsAsInt is a flag that is temporarily available for ES 7.x +// servers to return total hits as an int64 instead of a response structure. +// +// Warning: Using it indicates that you are using elastic.v6 with ES 7.x, +// which is an unsupported scenario. Use at your own risk. +// This option will also be removed with ES 8.x. +// See https://www.elastic.co/guide/en/elasticsearch/reference/7.0/breaking-changes-7.0.html#hits-total-now-object-search-response. +func (s *SearchService) RestTotalHitsAsInt(v bool) *SearchService { + s.restTotalHitsAsInt = &v + return s +} + +// SeqNoPrimaryTerm specifies whether to return sequence number and +// primary term of the last modification of each hit. +func (s *SearchService) SeqNoPrimaryTerm(v bool) *SearchService { + s.seqNoPrimaryTerm = &v + return s +} + // buildURL builds the URL for the operation. func (s *SearchService) buildURL() (string, url.Values, error) { var err error @@ -340,7 +397,7 @@ func (s *SearchService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", fmt.Sprintf("%v", s.pretty)) + params.Set("pretty", fmt.Sprint(s.pretty)) } if s.searchType != "" { params.Set("search_type", s.searchType) @@ -352,20 +409,26 @@ func (s *SearchService) buildURL() (string, url.Values, error) { params.Set("preference", s.preference) } if s.requestCache != nil { - params.Set("request_cache", fmt.Sprintf("%v", *s.requestCache)) + params.Set("request_cache", fmt.Sprint(*s.requestCache)) } if s.allowNoIndices != nil { - params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices)) + params.Set("allow_no_indices", fmt.Sprint(*s.allowNoIndices)) } if s.expandWildcards != "" { params.Set("expand_wildcards", s.expandWildcards) } if s.ignoreUnavailable != nil { - params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) + params.Set("ignore_unavailable", fmt.Sprint(*s.ignoreUnavailable)) } if len(s.filterPath) > 0 { params.Set("filter_path", strings.Join(s.filterPath, ",")) } + if s.restTotalHitsAsInt != nil { + params.Set("rest_total_hits_as_int", fmt.Sprint(*s.restTotalHitsAsInt)) + } + if s.seqNoPrimaryTerm != nil { + params.Set("seq_no_primary_term", fmt.Sprint(*s.seqNoPrimaryTerm)) + } return path, params, nil } @@ -398,7 +461,13 @@ func (s *SearchService) Do(ctx context.Context) (*SearchResult, error) { } body = src } - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + MaxResponseSize: s.maxResponseSize, + }) if err != nil { return nil, err } @@ -413,15 +482,15 @@ func (s *SearchService) Do(ctx context.Context) (*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 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 + TookInMillis int64 `json:"took,omitempty"` // search time in milliseconds + ScrollId string `json:"_scroll_id,omitempty"` // only used with Scroll and Scan operations + Hits *SearchHits `json:"hits,omitempty"` // the actual search hits + Suggest SearchSuggest `json:"suggest,omitempty"` // results from suggesters + Aggregations Aggregations `json:"aggregations,omitempty"` // results from aggregations + TimedOut bool `json:"timed_out,omitempty"` // 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 @@ -435,7 +504,8 @@ func (r *SearchResult) TotalHits() int64 { // Each is a utility function to iterate over all hits. It saves you from // checking for nil values. Notice that Each will ignore errors in -// serializing JSON. +// serializing JSON and hits with empty/nil _source will get an empty +// value func (r *SearchResult) Each(typ reflect.Type) []interface{} { if r.Hits == nil || r.Hits.Hits == nil || len(r.Hits.Hits) == 0 { return nil @@ -456,9 +526,9 @@ func (r *SearchResult) Each(typ reflect.Type) []interface{} { // SearchHits specifies the list of search hits. type SearchHits struct { - TotalHits int64 `json:"total"` // total number of hits found - MaxScore *float64 `json:"max_score"` // maximum score of all hits - Hits []*SearchHit `json:"hits"` // the actual hits returned + TotalHits int64 `json:"total"` // total number of hits found + MaxScore *float64 `json:"max_score,omitempty"` // maximum score of all hits + Hits []*SearchHit `json:"hits,omitempty"` // the actual hits returned } // NestedHit is a nested innerhit @@ -470,22 +540,24 @@ type NestedHit struct { // SearchHit is a single hit. type SearchHit struct { - Score *float64 `json:"_score"` // computed score - Index string `json:"_index"` // index name - 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) - 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 (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 - Nested *NestedHit `json:"_nested"` // for nested inner hits + Score *float64 `json:"_score,omitempty"` // computed score + Index string `json:"_index,omitempty"` // index name + Type string `json:"_type,omitempty"` // type meta field + Id string `json:"_id,omitempty"` // external or internal + Uid string `json:"_uid,omitempty"` // uid meta field (see MapperService.java for all meta fields) + Routing string `json:"_routing,omitempty"` // routing meta field + Parent string `json:"_parent,omitempty"` // parent meta field + Version *int64 `json:"_version,omitempty"` // version number, when Version is set to true in SearchService + SeqNo *int64 `json:"_seq_no"` + PrimaryTerm *int64 `json:"_primary_term"` + Sort []interface{} `json:"sort,omitempty"` // sort information + Highlight SearchHitHighlight `json:"highlight,omitempty"` // highlighter information + Source *json.RawMessage `json:"_source,omitempty"` // stored document source + Fields map[string]interface{} `json:"fields,omitempty"` // returned (stored) fields + Explanation *SearchExplanation `json:"_explanation,omitempty"` // explains how the score was computed + MatchedQueries []string `json:"matched_queries,omitempty"` // matched queries + InnerHits map[string]*SearchHitInnerHits `json:"inner_hits,omitempty"` // inner hits with ES >= 1.5.0 + Nested *NestedHit `json:"_nested,omitempty"` // for nested inner hits // Shard // HighlightFields @@ -493,12 +565,13 @@ type SearchHit struct { // MatchedFilters } +// SearchHitInnerHits is used for inner hits. type SearchHitInnerHits struct { - Hits *SearchHits `json:"hits"` + Hits *SearchHits `json:"hits,omitempty"` } // SearchExplanation explains how the score for a hit was computed. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-explain.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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:" @@ -508,11 +581,11 @@ type SearchExplanation struct { // Suggest // SearchSuggest is a map of suggestions. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters.html. type SearchSuggest map[string][]SearchSuggestion // SearchSuggestion is a single search suggestion. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters.html. type SearchSuggestion struct { Text string `json:"text"` Offset int `json:"offset"` @@ -521,17 +594,18 @@ type SearchSuggestion struct { } // SearchSuggestionOption is an option of a SearchSuggestion. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters.html. type SearchSuggestionOption struct { - Text string `json:"text"` - Index string `json:"_index"` - Type string `json:"_type"` - Id string `json:"_id"` - Score float64 `json:"score"` - Highlighted string `json:"highlighted"` - CollateMatch bool `json:"collate_match"` - Freq int `json:"freq"` // from TermSuggestion.Option in Java API - Source *json.RawMessage `json:"_source"` + Text string `json:"text"` + Index string `json:"_index"` + Type string `json:"_type"` + Id string `json:"_id"` + Score float64 `json:"score"` // term and phrase suggesters uses "score" as of 6.2.4 + ScoreUnderscore float64 `json:"_score"` // completion and context suggesters uses "_score" as of 6.2.4 + Highlighted string `json:"highlighted"` + CollateMatch bool `json:"collate_match"` + Freq int `json:"freq"` // from TermSuggestion.Option in Java API + Source *json.RawMessage `json:"_source"` } // SearchProfile is a list of shard profiling data collected during @@ -584,6 +658,6 @@ type ProfileResult struct { // Highlighting // SearchHitHighlight is the highlight information of a search hit. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-highlighting.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-highlighting.html // for a general discussion of highlighting. type SearchHitHighlight map[string][]string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs.go similarity index 84% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs.go index cc4921aeb8..f9f9905482 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs.go @@ -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: -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-min-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-max-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-sum-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-avg-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-avg-aggregation.html func (a Aggregations) Avg(name string) (*AggregationValueMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationValueMetric) @@ -83,8 +83,23 @@ func (a Aggregations) Avg(name string) (*AggregationValueMetric, bool) { return nil, false } +// WeightedAvg computes the weighted average of numeric values that are extracted from the aggregated documents. +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-weight-avg-aggregation.html +func (a Aggregations) WeightedAvg(name string) (*AggregationValueMetric, bool) { + if raw, found := a[name]; found { + agg := new(AggregationValueMetric) + if raw == nil { + return agg, true + } + if err := json.Unmarshal(*raw, agg); err == nil { + return agg, true + } + } + return nil, false +} + // ValueCount returns value-count aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-valuecount-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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 +114,7 @@ func (a Aggregations) ValueCount(name string) (*AggregationValueMetric, bool) { } // Cardinality returns cardinality aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-cardinality-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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 +129,7 @@ func (a Aggregations) Cardinality(name string) (*AggregationValueMetric, bool) { } // Stats returns stats aggregation results. -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-stats-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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 +144,7 @@ func (a Aggregations) Stats(name string) (*AggregationStatsMetric, bool) { } // ExtendedStats returns extended stats aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-extendedstats-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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 +159,7 @@ func (a Aggregations) ExtendedStats(name string) (*AggregationExtendedStatsMetri } // MatrixStats returns matrix stats aggregation results. -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-matrix-stats-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-matrix-stats-aggregation.html func (a Aggregations) MatrixStats(name string) (*AggregationMatrixStats, bool) { if raw, found := a[name]; found { agg := new(AggregationMatrixStats) @@ -159,7 +174,7 @@ func (a Aggregations) MatrixStats(name string) (*AggregationMatrixStats, bool) { } // Percentiles returns percentiles results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-percentile-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-percentile-aggregation.html func (a Aggregations) Percentiles(name string) (*AggregationPercentilesMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationPercentilesMetric) @@ -174,7 +189,7 @@ func (a Aggregations) Percentiles(name string) (*AggregationPercentilesMetric, b } // PercentileRanks returns percentile ranks results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-percentile-rank-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-percentile-rank-aggregation.html func (a Aggregations) PercentileRanks(name string) (*AggregationPercentilesMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationPercentilesMetric) @@ -189,7 +204,7 @@ func (a Aggregations) PercentileRanks(name string) (*AggregationPercentilesMetri } // TopHits returns top-hits aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-top-hits-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-top-hits-aggregation.html func (a Aggregations) TopHits(name string) (*AggregationTopHitsMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationTopHitsMetric) @@ -204,7 +219,7 @@ func (a Aggregations) TopHits(name string) (*AggregationTopHitsMetric, bool) { } // Global returns global results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-global-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-global-aggregation.html func (a Aggregations) Global(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -219,7 +234,7 @@ func (a Aggregations) Global(name string) (*AggregationSingleBucket, bool) { } // Filter returns filter results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-filter-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-filter-aggregation.html func (a Aggregations) Filter(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -234,7 +249,7 @@ func (a Aggregations) Filter(name string) (*AggregationSingleBucket, bool) { } // Filters returns filters results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-filters-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-filters-aggregation.html func (a Aggregations) Filters(name string) (*AggregationBucketFilters, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketFilters) @@ -249,7 +264,7 @@ func (a Aggregations) Filters(name string) (*AggregationBucketFilters, bool) { } // AdjacencyMatrix returning a form of adjacency matrix. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-adjacency-matrix-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-adjacency-matrix-aggregation.html func (a Aggregations) AdjacencyMatrix(name string) (*AggregationBucketAdjacencyMatrix, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketAdjacencyMatrix) @@ -264,7 +279,7 @@ func (a Aggregations) AdjacencyMatrix(name string) (*AggregationBucketAdjacencyM } // Missing returns missing results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-missing-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-missing-aggregation.html func (a Aggregations) Missing(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -279,7 +294,7 @@ func (a Aggregations) Missing(name string) (*AggregationSingleBucket, bool) { } // Nested returns nested results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-nested-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-nested-aggregation.html func (a Aggregations) Nested(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -294,7 +309,7 @@ func (a Aggregations) Nested(name string) (*AggregationSingleBucket, bool) { } // ReverseNested returns reverse-nested results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-reverse-nested-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-reverse-nested-aggregation.html func (a Aggregations) ReverseNested(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -309,7 +324,7 @@ func (a Aggregations) ReverseNested(name string) (*AggregationSingleBucket, bool } // Children returns children results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-children-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-children-aggregation.html func (a Aggregations) Children(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -324,7 +339,7 @@ func (a Aggregations) Children(name string) (*AggregationSingleBucket, bool) { } // Terms returns terms aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-terms-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-terms-aggregation.html func (a Aggregations) Terms(name string) (*AggregationBucketKeyItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketKeyItems) @@ -339,7 +354,7 @@ func (a Aggregations) Terms(name string) (*AggregationBucketKeyItems, bool) { } // SignificantTerms returns significant terms aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-significantterms-aggregation.html func (a Aggregations) SignificantTerms(name string) (*AggregationBucketSignificantTerms, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketSignificantTerms) @@ -354,7 +369,7 @@ func (a Aggregations) SignificantTerms(name string) (*AggregationBucketSignifica } // Sampler returns sampler aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-sampler-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-sampler-aggregation.html func (a Aggregations) Sampler(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -369,7 +384,7 @@ func (a Aggregations) Sampler(name string) (*AggregationSingleBucket, bool) { } // DiversifiedSampler returns diversified_sampler aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-diversified-sampler-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-diversified-sampler-aggregation.html func (a Aggregations) DiversifiedSampler(name string) (*AggregationSingleBucket, bool) { if raw, found := a[name]; found { agg := new(AggregationSingleBucket) @@ -384,7 +399,7 @@ func (a Aggregations) DiversifiedSampler(name string) (*AggregationSingleBucket, } // Range returns range aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-range-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-range-aggregation.html func (a Aggregations) Range(name string) (*AggregationBucketRangeItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketRangeItems) @@ -399,7 +414,7 @@ func (a Aggregations) Range(name string) (*AggregationBucketRangeItems, bool) { } // KeyedRange returns keyed range aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-range-aggregation.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-range-aggregation.html. func (a Aggregations) KeyedRange(name string) (*AggregationBucketKeyedRangeItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketKeyedRangeItems) @@ -414,7 +429,7 @@ func (a Aggregations) KeyedRange(name string) (*AggregationBucketKeyedRangeItems } // DateRange returns date range aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-daterange-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-daterange-aggregation.html func (a Aggregations) DateRange(name string) (*AggregationBucketRangeItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketRangeItems) @@ -429,7 +444,7 @@ func (a Aggregations) DateRange(name string) (*AggregationBucketRangeItems, bool } // IPRange returns IP range aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-iprange-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-iprange-aggregation.html func (a Aggregations) IPRange(name string) (*AggregationBucketRangeItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketRangeItems) @@ -444,7 +459,7 @@ func (a Aggregations) IPRange(name string) (*AggregationBucketRangeItems, bool) } // Histogram returns histogram aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-histogram-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-histogram-aggregation.html func (a Aggregations) Histogram(name string) (*AggregationBucketHistogramItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketHistogramItems) @@ -459,8 +474,7 @@ func (a Aggregations) Histogram(name string) (*AggregationBucketHistogramItems, } // DateHistogram returns date histogram aggregation results. -// -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-datehistogram-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-datehistogram-aggregation.html func (a Aggregations) DateHistogram(name string) (*AggregationBucketHistogramItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketHistogramItems) @@ -476,7 +490,7 @@ func (a Aggregations) DateHistogram(name string) (*AggregationBucketHistogramIte // KeyedDateHistogram returns date histogram aggregation results for keyed responses. // -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-datehistogram-aggregation.html#_keyed_response_3 +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-datehistogram-aggregation.html#_keyed_response_3 func (a Aggregations) KeyedDateHistogram(name string) (*AggregationBucketKeyedHistogramItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketKeyedHistogramItems) @@ -491,7 +505,7 @@ func (a Aggregations) KeyedDateHistogram(name string) (*AggregationBucketKeyedHi } // GeoBounds returns geo-bounds aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-geobounds-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-geobounds-aggregation.html func (a Aggregations) GeoBounds(name string) (*AggregationGeoBoundsMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationGeoBoundsMetric) @@ -506,7 +520,7 @@ func (a Aggregations) GeoBounds(name string) (*AggregationGeoBoundsMetric, bool) } // GeoHash returns geo-hash aggregation results. -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-geohashgrid-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-geohashgrid-aggregation.html func (a Aggregations) GeoHash(name string) (*AggregationBucketKeyItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketKeyItems) @@ -521,7 +535,7 @@ func (a Aggregations) GeoHash(name string) (*AggregationBucketKeyItems, bool) { } // GeoCentroid returns geo-centroid aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-geocentroid-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-geocentroid-aggregation.html func (a Aggregations) GeoCentroid(name string) (*AggregationGeoCentroidMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationGeoCentroidMetric) @@ -536,7 +550,7 @@ func (a Aggregations) GeoCentroid(name string) (*AggregationGeoCentroidMetric, b } // GeoDistance returns geo distance aggregation results. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-geodistance-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-geodistance-aggregation.html func (a Aggregations) GeoDistance(name string) (*AggregationBucketRangeItems, bool) { if raw, found := a[name]; found { agg := new(AggregationBucketRangeItems) @@ -551,7 +565,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/5.2/search-aggregations-pipeline-avg-bucket-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-avg-bucket-aggregation.html func (a Aggregations) AvgBucket(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -566,7 +580,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/5.2/search-aggregations-pipeline-sum-bucket-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-sum-bucket-aggregation.html func (a Aggregations) SumBucket(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -581,7 +595,7 @@ func (a Aggregations) SumBucket(name string) (*AggregationPipelineSimpleValue, b } // 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 +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-stats-bucket-aggregation.html func (a Aggregations) StatsBucket(name string) (*AggregationPipelineStatsMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineStatsMetric) @@ -596,7 +610,7 @@ func (a Aggregations) StatsBucket(name string) (*AggregationPipelineStatsMetric, } // PercentilesBucket returns stats bucket pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-percentiles-bucket-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-percentiles-bucket-aggregation.html func (a Aggregations) PercentilesBucket(name string) (*AggregationPipelinePercentilesMetric, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelinePercentilesMetric) @@ -611,7 +625,7 @@ func (a Aggregations) PercentilesBucket(name string) (*AggregationPipelinePercen } // MaxBucket returns maximum bucket pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-max-bucket-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-max-bucket-aggregation.html func (a Aggregations) MaxBucket(name string) (*AggregationPipelineBucketMetricValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineBucketMetricValue) @@ -626,7 +640,7 @@ func (a Aggregations) MaxBucket(name string) (*AggregationPipelineBucketMetricVa } // MinBucket returns minimum bucket pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-min-bucket-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-min-bucket-aggregation.html func (a Aggregations) MinBucket(name string) (*AggregationPipelineBucketMetricValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineBucketMetricValue) @@ -641,7 +655,9 @@ func (a Aggregations) MinBucket(name string) (*AggregationPipelineBucketMetricVa } // MovAvg returns moving average pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movavg-aggregation.html +// +// Deprecated: The MovAvgAggregation has been deprecated in 6.4.0. Use the more generate MovFnAggregation instead. func (a Aggregations) MovAvg(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -655,8 +671,23 @@ func (a Aggregations) MovAvg(name string) (*AggregationPipelineSimpleValue, bool return nil, false } +// MovFn returns moving function pipeline aggregation results. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movfn-aggregation.html +func (a Aggregations) MovFn(name string) (*AggregationPipelineSimpleValue, bool) { + if raw, found := a[name]; found { + agg := new(AggregationPipelineSimpleValue) + if raw == nil { + return agg, true + } + if err := json.Unmarshal(*raw, agg); err == nil { + return agg, true + } + } + return nil, false +} + // Derivative returns derivative pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-derivative-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-derivative-aggregation.html func (a Aggregations) Derivative(name string) (*AggregationPipelineDerivative, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineDerivative) @@ -671,7 +702,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/5.2/search-aggregations-pipeline-cumulative-sum-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-cumulative-sum-aggregation.html func (a Aggregations) CumulativeSum(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -686,7 +717,7 @@ func (a Aggregations) CumulativeSum(name string) (*AggregationPipelineSimpleValu } // BucketScript returns bucket script pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-bucket-script-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-bucket-script-aggregation.html func (a Aggregations) BucketScript(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -701,7 +732,7 @@ func (a Aggregations) BucketScript(name string) (*AggregationPipelineSimpleValue } // SerialDiff returns serial differencing pipeline aggregation results. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-serialdiff-aggregation.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-serialdiff-aggregation.html func (a Aggregations) SerialDiff(name string) (*AggregationPipelineSimpleValue, bool) { if raw, found := a[name]; found { agg := new(AggregationPipelineSimpleValue) @@ -715,6 +746,39 @@ func (a Aggregations) SerialDiff(name string) (*AggregationPipelineSimpleValue, return nil, false } +// Composite returns composite bucket aggregation results. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-composite-aggregation.html +// for details. +func (a Aggregations) Composite(name string) (*AggregationBucketCompositeItems, bool) { + if raw, found := a[name]; found { + agg := new(AggregationBucketCompositeItems) + if raw == nil { + return agg, true + } + if err := json.Unmarshal(*raw, agg); err == nil { + return agg, true + } + } + return nil, false +} + +// ScriptedMetric returns scripted metric aggregation results. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-scripted-metric-aggregation.html +// for details. +func (a Aggregations) ScriptedMetric(name string) (*AggregationScriptedMetric, bool) { + if raw, found := a[name]; found { + agg := new(AggregationScriptedMetric) + if raw == nil { + return agg, true + } + if err := json.Unmarshal(*raw, agg); err == nil { + return agg, true + } + } + return nil, false +} + // -- Single value metric -- // AggregationValueMetric is a single-value metric, returned e.g. by a @@ -967,9 +1031,7 @@ func (a *AggregationGeoBoundsMetric) UnmarshalJSON(data []byte) error { return nil } -// -- Geo Centroid -- - -// AggregationGeocentroidMetric is a metric as returned by a GeoCentroid aggregation. +// AggregationGeoCentroidMetric is a metric as returned by a GeoCentroid aggregation. type AggregationGeoCentroidMetric struct { Aggregations @@ -1597,3 +1659,87 @@ func (a *AggregationPipelinePercentilesMetric) UnmarshalJSON(data []byte) error a.Aggregations = aggs return nil } + +// -- Composite key items -- + +// AggregationBucketCompositeItems implements the response structure +// for a bucket aggregation of type composite. +type AggregationBucketCompositeItems struct { + Aggregations + + Buckets []*AggregationBucketCompositeItem //`json:"buckets"` + Meta map[string]interface{} // `json:"meta,omitempty"` + AfterKey map[string]interface{} // `json:"after_key,omitempty"` +} + +// UnmarshalJSON decodes JSON data and initializes an AggregationBucketCompositeItems structure. +func (a *AggregationBucketCompositeItems) UnmarshalJSON(data []byte) error { + var aggs map[string]*json.RawMessage + if err := json.Unmarshal(data, &aggs); err != nil { + return err + } + if v, ok := aggs["buckets"]; ok && v != nil { + json.Unmarshal(*v, &a.Buckets) + } + if v, ok := aggs["meta"]; ok && v != nil { + json.Unmarshal(*v, &a.Meta) + } + if v, ok := aggs["after_key"]; ok && v != nil { + json.Unmarshal(*v, &a.AfterKey) + } + a.Aggregations = aggs + return nil +} + +// AggregationBucketCompositeItem is a single bucket of an AggregationBucketCompositeItems structure. +type AggregationBucketCompositeItem struct { + Aggregations + + Key map[string]interface{} //`json:"key"` + DocCount int64 //`json:"doc_count"` +} + +// UnmarshalJSON decodes JSON data and initializes an AggregationBucketCompositeItem structure. +func (a *AggregationBucketCompositeItem) UnmarshalJSON(data []byte) error { + var aggs map[string]*json.RawMessage + dec := json.NewDecoder(bytes.NewReader(data)) + dec.UseNumber() + if err := dec.Decode(&aggs); err != nil { + return err + } + if v, ok := aggs["key"]; ok && v != nil { + json.Unmarshal(*v, &a.Key) + } + if v, ok := aggs["doc_count"]; ok && v != nil { + json.Unmarshal(*v, &a.DocCount) + } + a.Aggregations = aggs + return nil +} + +// AggregationScriptedMetric is the value return by a scripted metric aggregation. +// Value maybe one of map[string]interface{}/[]interface{}/string/bool/json.Number +type AggregationScriptedMetric struct { + Aggregations + + Value interface{} //`json:"value"` + Meta map[string]interface{} //`json:"meta,omitempty"` +} + +// UnmarshalJSON decodes JSON data and initializes an AggregationScriptedMetric structure. +func (a *AggregationScriptedMetric) UnmarshalJSON(data []byte) error { + var aggs map[string]*json.RawMessage + if err := json.Unmarshal(data, &aggs); err != nil { + return err + } + if v, ok := aggs["value"]; ok && v != nil { + decoder := json.NewDecoder(bytes.NewReader(*v)) + decoder.UseNumber() + decoder.Decode(&a.Value) + } + 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.v5/search_aggs_bucket_adjacency_matrix.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_adjacency_matrix.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_adjacency_matrix.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_adjacency_matrix.go index fa6e814641..5850b7075d 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_adjacency_matrix.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_adjacency_matrix.go @@ -10,7 +10,7 @@ package elastic // response represents a non-empty cell in the matrix of intersecting filters. // // For details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-adjacency-matrix-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-adjacency-matrix-aggregation.html type AdjacencyMatrixAggregation struct { filters map[string]Query subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_children.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_children.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_children.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_children.go index 14d0d1ca9c..d2fa67e993 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_children.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_children.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-children-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-children-aggregation.html type ChildrenAggregation struct { typ string subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_composite.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_composite.go new file mode 100644 index 0000000000..70d66cf8bd --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_composite.go @@ -0,0 +1,554 @@ +// 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 + +// CompositeAggregation is a multi-bucket values source based aggregation +// that can be used to calculate unique composite values from source documents. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-composite-aggregation.html +// for details. +type CompositeAggregation struct { + after map[string]interface{} + size *int + sources []CompositeAggregationValuesSource + subAggregations map[string]Aggregation + meta map[string]interface{} +} + +// NewCompositeAggregation creates a new CompositeAggregation. +func NewCompositeAggregation() *CompositeAggregation { + return &CompositeAggregation{ + sources: make([]CompositeAggregationValuesSource, 0), + subAggregations: make(map[string]Aggregation), + } +} + +// Size represents the number of composite buckets to return. +// Defaults to 10 as of Elasticsearch 6.1. +func (a *CompositeAggregation) Size(size int) *CompositeAggregation { + a.size = &size + return a +} + +// AggregateAfter sets the values that indicate which composite bucket this +// request should "aggregate after". +func (a *CompositeAggregation) AggregateAfter(after map[string]interface{}) *CompositeAggregation { + a.after = after + return a +} + +// Sources specifies the list of CompositeAggregationValuesSource instances to +// use in the aggregation. +func (a *CompositeAggregation) Sources(sources ...CompositeAggregationValuesSource) *CompositeAggregation { + a.sources = append(a.sources, sources...) + return a +} + +// SubAggregations of this aggregation. +func (a *CompositeAggregation) SubAggregation(name string, subAggregation Aggregation) *CompositeAggregation { + a.subAggregations[name] = subAggregation + return a +} + +// Meta sets the meta data to be included in the aggregation response. +func (a *CompositeAggregation) Meta(metaData map[string]interface{}) *CompositeAggregation { + a.meta = metaData + return a +} + +// Source returns the serializable JSON for this aggregation. +func (a *CompositeAggregation) Source() (interface{}, error) { + // Example: + // { + // "aggs" : { + // "my_composite_agg" : { + // "composite" : { + // "sources": [ + // {"my_term": { "terms": { "field": "product" }}}, + // {"my_histo": { "histogram": { "field": "price", "interval": 5 }}}, + // {"my_date": { "date_histogram": { "field": "timestamp", "interval": "1d" }}}, + // ], + // "size" : 10, + // "after" : ["a", 2, "c"] + // } + // } + // } + // } + // + // This method returns only the { "histogram" : { ... } } part. + + source := make(map[string]interface{}) + opts := make(map[string]interface{}) + source["composite"] = opts + + sources := make([]interface{}, len(a.sources)) + for i, s := range a.sources { + src, err := s.Source() + if err != nil { + return nil, err + } + sources[i] = src + } + opts["sources"] = sources + + if a.size != nil { + opts["size"] = *a.size + } + + if a.after != nil { + opts["after"] = a.after + } + + // AggregationBuilder (SubAggregations) + if len(a.subAggregations) > 0 { + aggsMap := make(map[string]interface{}) + source["aggregations"] = aggsMap + for name, aggregate := range a.subAggregations { + src, err := aggregate.Source() + if err != nil { + return nil, err + } + aggsMap[name] = src + } + } + + // Add Meta data if available + if len(a.meta) > 0 { + source["meta"] = a.meta + } + + return source, nil +} + +// -- Generic interface for CompositeAggregationValues -- + +// CompositeAggregationValuesSource specifies the interface that +// all implementations for CompositeAggregation's Sources method +// need to implement. +// +// The different implementations are described in +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-composite-aggregation.html#_values_source_2. +type CompositeAggregationValuesSource interface { + Source() (interface{}, error) +} + +// -- CompositeAggregationTermsValuesSource -- + +// CompositeAggregationTermsValuesSource is a source for the CompositeAggregation that handles terms +// it works very similar to a terms aggregation with slightly different syntax +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-composite-aggregation.html#_terms +// for details. +type CompositeAggregationTermsValuesSource struct { + name string + field string + script *Script + valueType string + missing interface{} + missingBucket *bool + order string +} + +// NewCompositeAggregationTermsValuesSource creates and initializes +// a new CompositeAggregationTermsValuesSource. +func NewCompositeAggregationTermsValuesSource(name string) *CompositeAggregationTermsValuesSource { + return &CompositeAggregationTermsValuesSource{ + name: name, + } +} + +// Field to use for this source. +func (a *CompositeAggregationTermsValuesSource) Field(field string) *CompositeAggregationTermsValuesSource { + a.field = field + return a +} + +// Script to use for this source. +func (a *CompositeAggregationTermsValuesSource) Script(script *Script) *CompositeAggregationTermsValuesSource { + a.script = script + return a +} + +// ValueType specifies the type of values produced by this source, +// e.g. "string" or "date". +func (a *CompositeAggregationTermsValuesSource) ValueType(valueType string) *CompositeAggregationTermsValuesSource { + a.valueType = valueType + return a +} + +// Order specifies the order in the values produced by this source. +// It can be either "asc" or "desc". +func (a *CompositeAggregationTermsValuesSource) Order(order string) *CompositeAggregationTermsValuesSource { + a.order = order + return a +} + +// Asc ensures the order of the values produced is ascending. +func (a *CompositeAggregationTermsValuesSource) Asc() *CompositeAggregationTermsValuesSource { + a.order = "asc" + return a +} + +// Desc ensures the order of the values produced is descending. +func (a *CompositeAggregationTermsValuesSource) Desc() *CompositeAggregationTermsValuesSource { + a.order = "desc" + return a +} + +// Missing specifies the value to use when the source finds a missing +// value in a document. +// +// Deprecated: Use MissingBucket instead. +func (a *CompositeAggregationTermsValuesSource) Missing(missing interface{}) *CompositeAggregationTermsValuesSource { + a.missing = missing + return a +} + +// MissingBucket, if true, will create an explicit null bucket which represents +// documents with missing values. +func (a *CompositeAggregationTermsValuesSource) MissingBucket(missingBucket bool) *CompositeAggregationTermsValuesSource { + a.missingBucket = &missingBucket + return a +} + +// Source returns the serializable JSON for this values source. +func (a *CompositeAggregationTermsValuesSource) Source() (interface{}, error) { + source := make(map[string]interface{}) + name := make(map[string]interface{}) + source[a.name] = name + values := make(map[string]interface{}) + name["terms"] = values + + // field + if a.field != "" { + values["field"] = a.field + } + + // script + if a.script != nil { + src, err := a.script.Source() + if err != nil { + return nil, err + } + values["script"] = src + } + + // missing + if a.missing != nil { + values["missing"] = a.missing + } + + // missing_bucket + if a.missingBucket != nil { + values["missing_bucket"] = *a.missingBucket + } + + // value_type + if a.valueType != "" { + values["value_type"] = a.valueType + } + + // order + if a.order != "" { + values["order"] = a.order + } + + return source, nil + +} + +// -- CompositeAggregationHistogramValuesSource -- + +// CompositeAggregationHistogramValuesSource is a source for the CompositeAggregation that handles histograms +// it works very similar to a terms histogram with slightly different syntax +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-composite-aggregation.html#_histogram +// for details. +type CompositeAggregationHistogramValuesSource struct { + name string + field string + script *Script + valueType string + missing interface{} + missingBucket *bool + order string + interval float64 +} + +// NewCompositeAggregationHistogramValuesSource creates and initializes +// a new CompositeAggregationHistogramValuesSource. +func NewCompositeAggregationHistogramValuesSource(name string, interval float64) *CompositeAggregationHistogramValuesSource { + return &CompositeAggregationHistogramValuesSource{ + name: name, + interval: interval, + } +} + +// Field to use for this source. +func (a *CompositeAggregationHistogramValuesSource) Field(field string) *CompositeAggregationHistogramValuesSource { + a.field = field + return a +} + +// Script to use for this source. +func (a *CompositeAggregationHistogramValuesSource) Script(script *Script) *CompositeAggregationHistogramValuesSource { + a.script = script + return a +} + +// ValueType specifies the type of values produced by this source, +// e.g. "string" or "date". +func (a *CompositeAggregationHistogramValuesSource) ValueType(valueType string) *CompositeAggregationHistogramValuesSource { + a.valueType = valueType + return a +} + +// Missing specifies the value to use when the source finds a missing +// value in a document. +// +// Deprecated: Use MissingBucket instead. +func (a *CompositeAggregationHistogramValuesSource) Missing(missing interface{}) *CompositeAggregationHistogramValuesSource { + a.missing = missing + return a +} + +// MissingBucket, if true, will create an explicit null bucket which represents +// documents with missing values. +func (a *CompositeAggregationHistogramValuesSource) MissingBucket(missingBucket bool) *CompositeAggregationHistogramValuesSource { + a.missingBucket = &missingBucket + return a +} + +// Order specifies the order in the values produced by this source. +// It can be either "asc" or "desc". +func (a *CompositeAggregationHistogramValuesSource) Order(order string) *CompositeAggregationHistogramValuesSource { + a.order = order + return a +} + +// Asc ensures the order of the values produced is ascending. +func (a *CompositeAggregationHistogramValuesSource) Asc() *CompositeAggregationHistogramValuesSource { + a.order = "asc" + return a +} + +// Desc ensures the order of the values produced is descending. +func (a *CompositeAggregationHistogramValuesSource) Desc() *CompositeAggregationHistogramValuesSource { + a.order = "desc" + return a +} + +// Interval specifies the interval to use. +func (a *CompositeAggregationHistogramValuesSource) Interval(interval float64) *CompositeAggregationHistogramValuesSource { + a.interval = interval + return a +} + +// Source returns the serializable JSON for this values source. +func (a *CompositeAggregationHistogramValuesSource) Source() (interface{}, error) { + source := make(map[string]interface{}) + name := make(map[string]interface{}) + source[a.name] = name + values := make(map[string]interface{}) + name["histogram"] = values + + // field + if a.field != "" { + values["field"] = a.field + } + + // script + if a.script != nil { + src, err := a.script.Source() + if err != nil { + return nil, err + } + values["script"] = src + } + + // missing + if a.missing != nil { + values["missing"] = a.missing + } + + // missing_bucket + if a.missingBucket != nil { + values["missing_bucket"] = *a.missingBucket + } + + // value_type + if a.valueType != "" { + values["value_type"] = a.valueType + } + + // order + if a.order != "" { + values["order"] = a.order + } + + // Histogram-related properties + values["interval"] = a.interval + + return source, nil + +} + +// -- CompositeAggregationDateHistogramValuesSource -- + +// CompositeAggregationDateHistogramValuesSource is a source for the CompositeAggregation that handles date histograms +// it works very similar to a date histogram aggregation with slightly different syntax +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-composite-aggregation.html#_date_histogram +// for details. +type CompositeAggregationDateHistogramValuesSource struct { + name string + field string + script *Script + valueType string + missing interface{} + missingBucket *bool + order string + interval interface{} + format string + timeZone string +} + +// NewCompositeAggregationDateHistogramValuesSource creates and initializes +// a new CompositeAggregationDateHistogramValuesSource. +func NewCompositeAggregationDateHistogramValuesSource(name string, interval interface{}) *CompositeAggregationDateHistogramValuesSource { + return &CompositeAggregationDateHistogramValuesSource{ + name: name, + interval: interval, + } +} + +// Field to use for this source. +func (a *CompositeAggregationDateHistogramValuesSource) Field(field string) *CompositeAggregationDateHistogramValuesSource { + a.field = field + return a +} + +// Script to use for this source. +func (a *CompositeAggregationDateHistogramValuesSource) Script(script *Script) *CompositeAggregationDateHistogramValuesSource { + a.script = script + return a +} + +// ValueType specifies the type of values produced by this source, +// e.g. "string" or "date". +func (a *CompositeAggregationDateHistogramValuesSource) ValueType(valueType string) *CompositeAggregationDateHistogramValuesSource { + a.valueType = valueType + return a +} + +// Missing specifies the value to use when the source finds a missing +// value in a document. +// +// Deprecated: Use MissingBucket instead. +func (a *CompositeAggregationDateHistogramValuesSource) Missing(missing interface{}) *CompositeAggregationDateHistogramValuesSource { + a.missing = missing + return a +} + +// MissingBucket, if true, will create an explicit null bucket which represents +// documents with missing values. +func (a *CompositeAggregationDateHistogramValuesSource) MissingBucket(missingBucket bool) *CompositeAggregationDateHistogramValuesSource { + a.missingBucket = &missingBucket + return a +} + +// Order specifies the order in the values produced by this source. +// It can be either "asc" or "desc". +func (a *CompositeAggregationDateHistogramValuesSource) Order(order string) *CompositeAggregationDateHistogramValuesSource { + a.order = order + return a +} + +// Asc ensures the order of the values produced is ascending. +func (a *CompositeAggregationDateHistogramValuesSource) Asc() *CompositeAggregationDateHistogramValuesSource { + a.order = "asc" + return a +} + +// Desc ensures the order of the values produced is descending. +func (a *CompositeAggregationDateHistogramValuesSource) Desc() *CompositeAggregationDateHistogramValuesSource { + a.order = "desc" + return a +} + +// Interval to use for the date histogram, e.g. "1d" or a numeric value like "60". +func (a *CompositeAggregationDateHistogramValuesSource) Interval(interval interface{}) *CompositeAggregationDateHistogramValuesSource { + a.interval = interval + return a +} + +// Format to use for the date histogram, e.g. "strict_date_optional_time" +func (a *CompositeAggregationDateHistogramValuesSource) Format(format string) *CompositeAggregationDateHistogramValuesSource { + a.format = format + return a +} + +// TimeZone to use for the dates. +func (a *CompositeAggregationDateHistogramValuesSource) TimeZone(timeZone string) *CompositeAggregationDateHistogramValuesSource { + a.timeZone = timeZone + return a +} + +// Source returns the serializable JSON for this values source. +func (a *CompositeAggregationDateHistogramValuesSource) Source() (interface{}, error) { + source := make(map[string]interface{}) + name := make(map[string]interface{}) + source[a.name] = name + values := make(map[string]interface{}) + name["date_histogram"] = values + + // field + if a.field != "" { + values["field"] = a.field + } + + // script + if a.script != nil { + src, err := a.script.Source() + if err != nil { + return nil, err + } + values["script"] = src + } + + // missing + if a.missing != nil { + values["missing"] = a.missing + } + + // missing_bucket + if a.missingBucket != nil { + values["missing_bucket"] = *a.missingBucket + } + + // value_type + if a.valueType != "" { + values["value_type"] = a.valueType + } + + // order + if a.order != "" { + values["order"] = a.order + } + + if a.format != "" { + values["format"] = a.format + } + + // DateHistogram-related properties + values["interval"] = a.interval + + // timeZone + if a.timeZone != "" { + values["time_zone"] = a.timeZone + } + + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_count_thresholds.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_count_thresholds.go new file mode 100644 index 0000000000..53efdaf5fd --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_count_thresholds.go @@ -0,0 +1,13 @@ +// 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 + +// BucketCountThresholds is used in e.g. terms and significant text aggregations. +type BucketCountThresholds struct { + MinDocCount *int64 + ShardMinDocCount *int64 + RequiredSize *int + ShardSize *int +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_histogram.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_date_histogram.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_histogram.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_date_histogram.go index aaebe0a926..20b887cfe2 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_histogram.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_date_histogram.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-datehistogram-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-datehistogram-aggregation.html type DateHistogramAggregation struct { field string script *Script @@ -198,7 +198,8 @@ func (a *DateHistogramAggregation) ExtendedBoundsMax(max interface{}) *DateHisto } // Keyed specifies whether to return the results with a keyed response (or not). -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-datehistogram-aggregation.html#_keyed_response_3. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-datehistogram-aggregation.html#_keyed_response_3. func (a *DateHistogramAggregation) Keyed(keyed bool) *DateHistogramAggregation { a.keyed = &keyed return a diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_range.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_date_range.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_range.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_date_range.go index a4c10aa880..71e05fcf65 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_date_range.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_date_range.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-daterange-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-daterange-aggregation.html type DateRangeAggregation struct { field string script *Script @@ -23,6 +23,7 @@ type DateRangeAggregation struct { meta map[string]interface{} keyed *bool unmapped *bool + timeZone string format string entries []DateRangeAggregationEntry } @@ -71,6 +72,11 @@ func (a *DateRangeAggregation) Unmapped(unmapped bool) *DateRangeAggregation { return a } +func (a *DateRangeAggregation) TimeZone(timeZone string) *DateRangeAggregation { + a.timeZone = timeZone + return a +} + func (a *DateRangeAggregation) Format(format string) *DateRangeAggregation { a.format = format return a @@ -178,6 +184,9 @@ func (a *DateRangeAggregation) Source() (interface{}, error) { if a.unmapped != nil { opts["unmapped"] = *a.unmapped } + if a.timeZone != "" { + opts["time_zone"] = a.timeZone + } if a.format != "" { opts["format"] = a.format } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_diversified_sampler.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_diversified_sampler.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_diversified_sampler.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_diversified_sampler.go index a70b83a2de..1dba719e30 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_diversified_sampler.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_diversified_sampler.go @@ -8,7 +8,7 @@ package elastic // sub aggregations’ processing to a sample of the top-scoring documents. The diversified_sampler aggregation adds // the ability to limit the number of matches that share a common value such as an "author". // -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-diversified-sampler-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-diversified-sampler-aggregation.html type DiversifiedSamplerAggregation struct { subAggregations map[string]Aggregation meta map[string]interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filter.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_filter.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filter.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_filter.go index 2085f0d366..ea92905fe8 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filter.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_filter.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-filter-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-filter-aggregation.html type FilterAggregation struct { filter Query subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filters.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_filters.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filters.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_filters.go index 80999eed96..b5b022d1ba 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_filters.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_filters.go @@ -15,7 +15,7 @@ import "errors" // use both named and unnamed filters. // // For details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-filters-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-filters-aggregation.html type FiltersAggregation struct { unnamedFilters []Query namedFilters map[string]Query diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geo_distance.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_geo_distance.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geo_distance.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_geo_distance.go index 2ae7b63dc0..a808f533d3 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geo_distance.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_geo_distance.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-geodistance-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-geodistance-aggregation.html type GeoDistanceAggregation struct { field string unit string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_geohash_grid.go similarity index 80% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_geohash_grid.go index 07f61b3314..fa43b897f0 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_geohash_grid.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_geohash_grid.go @@ -2,7 +2,7 @@ package elastic type GeoHashGridAggregation struct { field string - precision int + precision interface{} size int shardSize int subAggregations map[string]Aggregation @@ -12,7 +12,6 @@ type GeoHashGridAggregation struct { func NewGeoHashGridAggregation() *GeoHashGridAggregation { return &GeoHashGridAggregation{ subAggregations: make(map[string]Aggregation), - precision: -1, size: -1, shardSize: -1, } @@ -23,7 +22,10 @@ func (a *GeoHashGridAggregation) Field(field string) *GeoHashGridAggregation { return a } -func (a *GeoHashGridAggregation) Precision(precision int) *GeoHashGridAggregation { +// Precision accepts the level as int value between 1 and 12 or Distance Units like "2km", "5mi" as described at +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/common-options.html#distance-units and +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-geohashgrid-aggregation.html +func (a *GeoHashGridAggregation) Precision(precision interface{}) *GeoHashGridAggregation { a.precision = precision return a } @@ -69,7 +71,7 @@ func (a *GeoHashGridAggregation) Source() (interface{}, error) { opts["field"] = a.field } - if a.precision != -1 { + if a.precision != nil { opts["precision"] = a.precision } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_global.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_global.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_global.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_global.go index fbd14a45fa..fbe7a58859 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_global.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_global.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-global-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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.v5/search_aggs_bucket_histogram.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_histogram.go similarity index 99% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_histogram.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_histogram.go index 30528c164d..68ea566b5a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_histogram.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_histogram.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-histogram-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-histogram-aggregation.html type HistogramAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_ip_range.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_ip_range.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_ip_range.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_ip_range.go index c32f334f30..5d17740c11 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_ip_range.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_ip_range.go @@ -7,7 +7,7 @@ package elastic // IPRangeAggregation is a range aggregation that is dedicated for // IP addresses. // -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-iprange-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-iprange-aggregation.html type IPRangeAggregation struct { field string subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_missing.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_missing.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_missing.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_missing.go index 3ca3fd6930..af7218647a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_missing.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_missing.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-missing-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-missing-aggregation.html type MissingAggregation struct { field string subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_nested.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_nested.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_nested.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_nested.go index 62e592eb88..775d23cf71 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_nested.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_nested.go @@ -6,7 +6,7 @@ package elastic // NestedAggregation is a special single bucket aggregation that enables // aggregating nested documents. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-nested-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-nested-aggregation.html type NestedAggregation struct { path string subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_range.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_range.go similarity index 99% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_range.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_range.go index 1c5204a0bc..1cc3daece7 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_range.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_range.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-range-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-range-aggregation.html type RangeAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_reverse_nested.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_reverse_nested.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_reverse_nested.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_reverse_nested.go index f307f256f8..9dc6227c0b 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_reverse_nested.go +++ b/vendor/gopkg.in/olivere/elastic.v6/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/5.2/search-aggregations-bucket-reverse-nested-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-reverse-nested-aggregation.html type ReverseNestedAggregation struct { path string subAggregations map[string]Aggregation diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_sampler.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_sampler.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_sampler.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_sampler.go index c1a1ab4f76..d70a43fd59 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_sampler.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_sampler.go @@ -9,7 +9,7 @@ package elastic // 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/5.2/search-aggregations-bucket-sampler-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-sampler-aggregation.html type SamplerAggregation struct { subAggregations map[string]Aggregation meta map[string]interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_significant_terms.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_significant_terms.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_significant_terms.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_significant_terms.go index e03801f1e0..0e2bb29510 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_significant_terms.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_significant_terms.go @@ -4,9 +4,9 @@ package elastic -// SignificantSignificantTermsAggregation is an aggregation that returns interesting +// SignificantTermsAggregation is an aggregation that returns interesting // or unusual occurrences of terms in a set. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/search-aggregations-bucket-significantterms-aggregation.html#_chi_square +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/search-aggregations-bucket-significantterms-aggregation.html#_google_normalized_distance +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/search-aggregations-bucket-significantterms-aggregation.html#_jlh_score. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/search-aggregations-bucket-significantterms-aggregation.html#_mutual_information +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/search-aggregations-bucket-significantterms-aggregation.html#_percentage. +// in https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/search-aggregations-bucket-significantterms-aggregation.html#_scripted +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/search-aggregations-bucket-significantterms-aggregation.html#_scripted +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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.v6/search_aggs_bucket_significant_text.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_significant_text.go new file mode 100644 index 0000000000..d8bec3f082 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_significant_text.go @@ -0,0 +1,245 @@ +// 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 + +// SignificantTextAggregation returns interesting or unusual occurrences +// of free-text terms in a set. +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-significanttext-aggregation.html +type SignificantTextAggregation struct { + field string + subAggregations map[string]Aggregation + meta map[string]interface{} + + sourceFieldNames []string + filterDuplicateText *bool + includeExclude *TermsAggregationIncludeExclude + filter Query + bucketCountThresholds *BucketCountThresholds + significanceHeuristic SignificanceHeuristic +} + +func NewSignificantTextAggregation() *SignificantTextAggregation { + return &SignificantTextAggregation{ + subAggregations: make(map[string]Aggregation, 0), + } +} + +func (a *SignificantTextAggregation) Field(field string) *SignificantTextAggregation { + a.field = field + return a +} + +func (a *SignificantTextAggregation) SubAggregation(name string, subAggregation Aggregation) *SignificantTextAggregation { + a.subAggregations[name] = subAggregation + return a +} + +// Meta sets the meta data to be included in the aggregation response. +func (a *SignificantTextAggregation) Meta(metaData map[string]interface{}) *SignificantTextAggregation { + a.meta = metaData + return a +} + +func (a *SignificantTextAggregation) SourceFieldNames(names ...string) *SignificantTextAggregation { + a.sourceFieldNames = names + return a +} + +func (a *SignificantTextAggregation) FilterDuplicateText(filter bool) *SignificantTextAggregation { + a.filterDuplicateText = &filter + return a +} + +func (a *SignificantTextAggregation) MinDocCount(minDocCount int64) *SignificantTextAggregation { + if a.bucketCountThresholds == nil { + a.bucketCountThresholds = &BucketCountThresholds{} + } + a.bucketCountThresholds.MinDocCount = &minDocCount + return a +} + +func (a *SignificantTextAggregation) ShardMinDocCount(shardMinDocCount int64) *SignificantTextAggregation { + if a.bucketCountThresholds == nil { + a.bucketCountThresholds = &BucketCountThresholds{} + } + a.bucketCountThresholds.ShardMinDocCount = &shardMinDocCount + return a +} + +func (a *SignificantTextAggregation) Size(size int) *SignificantTextAggregation { + if a.bucketCountThresholds == nil { + a.bucketCountThresholds = &BucketCountThresholds{} + } + a.bucketCountThresholds.RequiredSize = &size + return a +} + +func (a *SignificantTextAggregation) ShardSize(shardSize int) *SignificantTextAggregation { + if a.bucketCountThresholds == nil { + a.bucketCountThresholds = &BucketCountThresholds{} + } + a.bucketCountThresholds.ShardSize = &shardSize + return a +} + +func (a *SignificantTextAggregation) BackgroundFilter(filter Query) *SignificantTextAggregation { + a.filter = filter + return a +} + +func (a *SignificantTextAggregation) SignificanceHeuristic(heuristic SignificanceHeuristic) *SignificantTextAggregation { + a.significanceHeuristic = heuristic + return a +} + +func (a *SignificantTextAggregation) Include(regexp string) *SignificantTextAggregation { + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.Include = regexp + return a +} + +func (a *SignificantTextAggregation) IncludeValues(values ...interface{}) *SignificantTextAggregation { + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.IncludeValues = append(a.includeExclude.IncludeValues, values...) + return a +} + +func (a *SignificantTextAggregation) Exclude(regexp string) *SignificantTextAggregation { + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.Exclude = regexp + return a +} + +func (a *SignificantTextAggregation) ExcludeValues(values ...interface{}) *SignificantTextAggregation { + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.ExcludeValues = append(a.includeExclude.ExcludeValues, values...) + return a +} + +func (a *SignificantTextAggregation) Partition(p int) *SignificantTextAggregation { + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.Partition = p + return a +} + +func (a *SignificantTextAggregation) NumPartitions(n int) *SignificantTextAggregation { + if a.includeExclude == nil { + a.includeExclude = &TermsAggregationIncludeExclude{} + } + a.includeExclude.NumPartitions = n + return a +} + +func (a *SignificantTextAggregation) Source() (interface{}, error) { + // Example: + // { + // "query" : { + // "match" : {"content" : "Bird flu"} + // }, + // "aggregations" : { + // "my_sample" : { + // "sampler": { + // "shard_size" : 100 + // }, + // "aggregations": { + // "keywords" : { + // "significant_text" : { "field" : "content" } + // } + // } + // } + // } + // } + // + // This method returns only the + // { "significant_text" : { "field" : "content" } + // part. + + source := make(map[string]interface{}) + opts := make(map[string]interface{}) + source["significant_text"] = opts + + if a.field != "" { + opts["field"] = a.field + } + if a.bucketCountThresholds != nil { + if a.bucketCountThresholds.RequiredSize != nil { + opts["size"] = (*a.bucketCountThresholds).RequiredSize + } + if a.bucketCountThresholds.ShardSize != nil { + opts["shard_size"] = (*a.bucketCountThresholds).ShardSize + } + if a.bucketCountThresholds.MinDocCount != nil { + opts["min_doc_count"] = (*a.bucketCountThresholds).MinDocCount + } + if a.bucketCountThresholds.ShardMinDocCount != nil { + opts["shard_min_doc_count"] = (*a.bucketCountThresholds).ShardMinDocCount + } + } + if a.filter != nil { + src, err := a.filter.Source() + if err != nil { + return nil, err + } + opts["background_filter"] = src + } + if a.significanceHeuristic != nil { + name := a.significanceHeuristic.Name() + src, err := a.significanceHeuristic.Source() + if err != nil { + return nil, err + } + opts[name] = src + } + // Include/Exclude + if ie := a.includeExclude; ie != nil { + // Include + if ie.Include != "" { + opts["include"] = ie.Include + } else if len(ie.IncludeValues) > 0 { + opts["include"] = ie.IncludeValues + } else if ie.NumPartitions > 0 { + inc := make(map[string]interface{}) + inc["partition"] = ie.Partition + inc["num_partitions"] = ie.NumPartitions + opts["include"] = inc + } + // Exclude + if ie.Exclude != "" { + opts["exclude"] = ie.Exclude + } else if len(ie.ExcludeValues) > 0 { + opts["exclude"] = ie.ExcludeValues + } + } + + // AggregationBuilder (SubAggregations) + if len(a.subAggregations) > 0 { + aggsMap := make(map[string]interface{}) + source["aggregations"] = aggsMap + for name, aggregate := range a.subAggregations { + src, err := aggregate.Source() + if err != nil { + return nil, err + } + aggsMap[name] = src + } + } + + // Add Meta data if available + if len(a.meta) > 0 { + source["meta"] = a.meta + } + + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_terms.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_terms.go index 6bcc322d07..29252e7a24 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_bucket_terms.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_bucket_terms.go @@ -6,7 +6,8 @@ package elastic // TermsAggregation is a multi-bucket value source based aggregation // where buckets are dynamically built - one per unique value. -// See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html +// +// See: https://www.elasticsearch.org/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-terms-aggregation.html type TermsAggregation struct { field string script *Script @@ -158,20 +159,37 @@ func (a *TermsAggregation) OrderByCountDesc() *TermsAggregation { return a.OrderByCount(false) } +// Deprecated: Use OrderByKey instead. func (a *TermsAggregation) OrderByTerm(asc bool) *TermsAggregation { // "order" : { "_term" : "asc" } a.order = append(a.order, TermsOrder{Field: "_term", Ascending: asc}) return a } +// Deprecated: Use OrderByKeyAsc instead. func (a *TermsAggregation) OrderByTermAsc() *TermsAggregation { return a.OrderByTerm(true) } +// Deprecated: Use OrderByKeyDesc instead. func (a *TermsAggregation) OrderByTermDesc() *TermsAggregation { return a.OrderByTerm(false) } +func (a *TermsAggregation) OrderByKey(asc bool) *TermsAggregation { + // "order" : { "_term" : "asc" } + a.order = append(a.order, TermsOrder{Field: "_key", Ascending: asc}) + return a +} + +func (a *TermsAggregation) OrderByKeyAsc() *TermsAggregation { + return a.OrderByKey(true) +} + +func (a *TermsAggregation) OrderByKeyDesc() *TermsAggregation { + return a.OrderByKey(false) +} + // OrderByAggregation creates a bucket ordering strategy which sorts buckets // based on a single-valued calc get. func (a *TermsAggregation) OrderByAggregation(aggName string, asc bool) *TermsAggregation { diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_matrix_stats.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_matrix_stats.go similarity index 86% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_matrix_stats.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_matrix_stats.go index 875da07181..462c0b19fb 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_matrix_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_matrix_stats.go @@ -4,8 +4,14 @@ package elastic -// MatrixMatrixStatsAggregation ... -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-aggregations-metrics-stats-aggregation.html +// MatrixMatrixStatsAggregation is a multi-value metrics aggregation +// that 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. +// +// The stats that are returned consist of: min, max, sum, count and avg. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-stats-aggregation.html // for details. type MatrixStatsAggregation struct { fields []string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_avg.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_avg.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_avg.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_avg.go index ff337a8cd2..40e1e99e2e 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_avg.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_avg.go @@ -9,11 +9,13 @@ 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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-avg-aggregation.html +// +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-avg-aggregation.html type AvgAggregation struct { field string script *Script format string + missing interface{} subAggregations map[string]Aggregation meta map[string]interface{} } @@ -39,6 +41,11 @@ func (a *AvgAggregation) Format(format string) *AvgAggregation { return a } +func (a *AvgAggregation) Missing(missing interface{}) *AvgAggregation { + a.missing = missing + return a +} + func (a *AvgAggregation) SubAggregation(name string, subAggregation Aggregation) *AvgAggregation { a.subAggregations[name] = subAggregation return a @@ -79,6 +86,10 @@ func (a *AvgAggregation) Source() (interface{}, error) { opts["format"] = a.format } + if a.missing != nil { + opts["missing"] = a.missing + } + // AggregationBuilder (SubAggregations) if len(a.subAggregations) > 0 { aggsMap := make(map[string]interface{}) diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_cardinality.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_cardinality.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_cardinality.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_cardinality.go index 8f6f447c47..d971be083b 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_cardinality.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_cardinality.go @@ -8,11 +8,12 @@ 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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-cardinality-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-cardinality-aggregation.html type CardinalityAggregation struct { field string script *Script format string + missing interface{} subAggregations map[string]Aggregation meta map[string]interface{} precisionThreshold *int64 @@ -40,6 +41,10 @@ func (a *CardinalityAggregation) Format(format string) *CardinalityAggregation { return a } +func (a *CardinalityAggregation) Missing(missing interface{}) *CardinalityAggregation { + a.missing = missing + return a +} func (a *CardinalityAggregation) SubAggregation(name string, subAggregation Aggregation) *CardinalityAggregation { a.subAggregations[name] = subAggregation return a @@ -87,7 +92,9 @@ func (a *CardinalityAggregation) Source() (interface{}, error) { } opts["script"] = src } - + if a.missing != nil { + opts["missing"] = a.missing + } if a.format != "" { opts["format"] = a.format } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_extended_stats.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_extended_stats.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_extended_stats.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_extended_stats.go index 95b312686d..1a471af715 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_extended_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_extended_stats.go @@ -8,11 +8,12 @@ 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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-extendedstats-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-extendedstats-aggregation.html type ExtendedStatsAggregation struct { field string script *Script format string + missing interface{} subAggregations map[string]Aggregation meta map[string]interface{} } @@ -38,6 +39,11 @@ func (a *ExtendedStatsAggregation) Format(format string) *ExtendedStatsAggregati return a } +func (a *ExtendedStatsAggregation) Missing(missing interface{}) *ExtendedStatsAggregation { + a.missing = missing + return a +} + func (a *ExtendedStatsAggregation) SubAggregation(name string, subAggregation Aggregation) *ExtendedStatsAggregation { a.subAggregations[name] = subAggregation return a @@ -76,6 +82,9 @@ func (a *ExtendedStatsAggregation) Source() (interface{}, error) { if a.format != "" { opts["format"] = a.format } + if a.missing != nil { + opts["missing"] = a.missing + } // AggregationBuilder (SubAggregations) if len(a.subAggregations) > 0 { diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_geo_bounds.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_geo_bounds.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_geo_bounds.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_geo_bounds.go index c263a76b40..de98f4a870 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_geo_bounds.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_geo_bounds.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-geobounds-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-geobounds-aggregation.html type GeoBoundsAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_geo_centroid.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_geo_centroid.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_geo_centroid.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_geo_centroid.go index a3470794a8..d809894c6a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_geo_centroid.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_geo_centroid.go @@ -6,7 +6,7 @@ package elastic // GeoCentroidAggregation is a metric aggregation that computes the weighted centroid // from all coordinate values for a Geo-point datatype field. -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-geocentroid-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-geocentroid-aggregation.html type GeoCentroidAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_max.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_max.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_max.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_max.go index b62130676a..d18af81e6d 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_max.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_max.go @@ -9,11 +9,12 @@ 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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-max-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-max-aggregation.html type MaxAggregation struct { field string script *Script format string + missing interface{} subAggregations map[string]Aggregation meta map[string]interface{} } @@ -39,6 +40,11 @@ func (a *MaxAggregation) Format(format string) *MaxAggregation { return a } +func (a *MaxAggregation) Missing(missing interface{}) *MaxAggregation { + a.missing = missing + return a +} + func (a *MaxAggregation) SubAggregation(name string, subAggregation Aggregation) *MaxAggregation { a.subAggregations[name] = subAggregation return a @@ -76,6 +82,9 @@ func (a *MaxAggregation) Source() (interface{}, error) { if a.format != "" { opts["format"] = a.format } + if a.missing != nil { + opts["missing"] = a.missing + } // AggregationBuilder (SubAggregations) if len(a.subAggregations) > 0 { diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_min.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_min.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_min.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_min.go index c1ca6922b4..b1363c9567 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_min.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_min.go @@ -9,11 +9,12 @@ 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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-min-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-min-aggregation.html type MinAggregation struct { field string script *Script format string + missing interface{} subAggregations map[string]Aggregation meta map[string]interface{} } @@ -39,6 +40,11 @@ func (a *MinAggregation) Format(format string) *MinAggregation { return a } +func (a *MinAggregation) Missing(missing interface{}) *MinAggregation { + a.missing = missing + return a +} + func (a *MinAggregation) SubAggregation(name string, subAggregation Aggregation) *MinAggregation { a.subAggregations[name] = subAggregation return a @@ -77,6 +83,9 @@ func (a *MinAggregation) Source() (interface{}, error) { if a.format != "" { opts["format"] = a.format } + if a.missing != nil { + opts["missing"] = a.missing + } // AggregationBuilder (SubAggregations) if len(a.subAggregations) > 0 { diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentile_ranks.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_percentile_ranks.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentile_ranks.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_percentile_ranks.go index 3e0595e880..010db199a9 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentile_ranks.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_percentile_ranks.go @@ -5,11 +5,12 @@ package elastic // PercentileRanksAggregation -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-percentile-rank-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-percentile-rank-aggregation.html type PercentileRanksAggregation struct { field string script *Script format string + missing interface{} subAggregations map[string]Aggregation meta map[string]interface{} values []float64 @@ -39,6 +40,11 @@ func (a *PercentileRanksAggregation) Format(format string) *PercentileRanksAggre return a } +func (a *PercentileRanksAggregation) Missing(missing interface{}) *PercentileRanksAggregation { + a.missing = missing + return a +} + func (a *PercentileRanksAggregation) SubAggregation(name string, subAggregation Aggregation) *PercentileRanksAggregation { a.subAggregations[name] = subAggregation return a @@ -99,6 +105,9 @@ func (a *PercentileRanksAggregation) Source() (interface{}, error) { if a.format != "" { opts["format"] = a.format } + if a.missing != nil { + opts["missing"] = a.missing + } if len(a.values) > 0 { opts["values"] = a.values } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentiles.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_percentiles.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentiles.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_percentiles.go index 9829f80afd..c67d659afd 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_percentiles.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_percentiles.go @@ -4,12 +4,18 @@ package elastic -// PercentilesAggregation -// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-percentile-aggregation.html +// PercentilesAggregation is a multi-value metrics aggregation +// that calculates one or more percentiles 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: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-percentile-aggregation.html type PercentilesAggregation struct { field string script *Script format string + missing interface{} subAggregations map[string]Aggregation meta map[string]interface{} percentiles []float64 @@ -42,6 +48,11 @@ func (a *PercentilesAggregation) Format(format string) *PercentilesAggregation { return a } +func (a *PercentilesAggregation) Missing(missing interface{}) *PercentilesAggregation { + a.missing = missing + return a +} + func (a *PercentilesAggregation) SubAggregation(name string, subAggregation Aggregation) *PercentilesAggregation { a.subAggregations[name] = subAggregation return a @@ -112,6 +123,9 @@ func (a *PercentilesAggregation) Source() (interface{}, error) { if a.format != "" { opts["format"] = a.format } + if a.missing != nil { + opts["missing"] = a.missing + } if len(a.percentiles) > 0 { opts["percents"] = a.percentiles } diff --git a/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_scripted_metric.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_scripted_metric.go new file mode 100644 index 0000000000..cd6e293807 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_scripted_metric.go @@ -0,0 +1,112 @@ +// 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 + +// ScriptedMetricAggregation is a a metric aggregation that executes using scripts to provide a metric output. +// +// See: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html +type ScriptedMetricAggregation struct { + initScript *Script + mapScript *Script + combineScript *Script + reduceScript *Script + + params map[string]interface{} + meta map[string]interface{} +} + +func NewScriptedMetricAggregation() *ScriptedMetricAggregation { + a := &ScriptedMetricAggregation{} + return a +} + +func (a *ScriptedMetricAggregation) InitScript(script *Script) *ScriptedMetricAggregation { + a.initScript = script + return a +} + +func (a *ScriptedMetricAggregation) MapScript(script *Script) *ScriptedMetricAggregation { + a.mapScript = script + return a +} + +func (a *ScriptedMetricAggregation) CombineScript(script *Script) *ScriptedMetricAggregation { + a.combineScript = script + return a +} + +func (a *ScriptedMetricAggregation) ReduceScript(script *Script) *ScriptedMetricAggregation { + a.reduceScript = script + return a +} + +func (a *ScriptedMetricAggregation) Params(params map[string]interface{}) *ScriptedMetricAggregation { + a.params = params + return a +} + +// Meta sets the meta data to be included in the aggregation response. +func (a *ScriptedMetricAggregation) Meta(metaData map[string]interface{}) *ScriptedMetricAggregation { + a.meta = metaData + return a +} + +func (a *ScriptedMetricAggregation) Source() (interface{}, error) { + // Example: + // { + // "aggs" : { + // "magic_script" : { "scripted_metric" : { + // "init_script" : "state.transactions = []", + // "map_script" : "state.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)", + // "combine_script" : "double profit = 0; for (t in state.transactions) { profit += t } return profit", + // "reduce_script" : "double profit = 0; for (a in states) { profit += a } return profit" + // } } + // } + // } + // This method returns only the { "scripted_metric" : { ... } } part. + + source := make(map[string]interface{}) + opts := make(map[string]interface{}) + source["scripted_metric"] = opts + + if a.initScript != nil { + src, err := a.initScript.Source() + if err != nil { + return nil, err + } + opts["init_script"] = src + } + if a.mapScript != nil { + src, err := a.mapScript.Source() + if err != nil { + return nil, err + } + opts["map_script"] = src + } + if a.combineScript != nil { + src, err := a.combineScript.Source() + if err != nil { + return nil, err + } + opts["combine_script"] = src + } + if a.reduceScript != nil { + src, err := a.reduceScript.Source() + if err != nil { + return nil, err + } + opts["reduce_script"] = src + } + + if a.params != nil && len(a.params) > 0 { + opts["params"] = a.params + } + + // Add Meta data if available + if len(a.meta) > 0 { + source["meta"] = a.meta + } + + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_stats.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_stats.go similarity index 90% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_stats.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_stats.go index 400b79b008..0bcad339e9 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_stats.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_stats.go @@ -8,11 +8,12 @@ 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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-stats-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-stats-aggregation.html type StatsAggregation struct { field string script *Script format string + missing interface{} subAggregations map[string]Aggregation meta map[string]interface{} } @@ -38,6 +39,11 @@ func (a *StatsAggregation) Format(format string) *StatsAggregation { return a } +func (a *StatsAggregation) Missing(missing interface{}) *StatsAggregation { + a.missing = missing + return a +} + func (a *StatsAggregation) SubAggregation(name string, subAggregation Aggregation) *StatsAggregation { a.subAggregations[name] = subAggregation return a @@ -76,6 +82,9 @@ func (a *StatsAggregation) Source() (interface{}, error) { if a.format != "" { opts["format"] = a.format } + if a.missing != nil { + opts["missing"] = a.missing + } // AggregationBuilder (SubAggregations) if len(a.subAggregations) > 0 { diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_sum.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_sum.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_sum.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_sum.go index f959a3e54b..adda12b876 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_sum.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_sum.go @@ -8,11 +8,12 @@ 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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-sum-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-sum-aggregation.html type SumAggregation struct { field string script *Script format string + missing interface{} subAggregations map[string]Aggregation meta map[string]interface{} } @@ -38,6 +39,11 @@ func (a *SumAggregation) Format(format string) *SumAggregation { return a } +func (a *SumAggregation) Missing(missing interface{}) *SumAggregation { + a.missing = missing + return a +} + func (a *SumAggregation) SubAggregation(name string, subAggregation Aggregation) *SumAggregation { a.subAggregations[name] = subAggregation return a @@ -76,6 +82,9 @@ func (a *SumAggregation) Source() (interface{}, error) { if a.format != "" { opts["format"] = a.format } + if a.missing != nil { + opts["missing"] = a.missing + } // AggregationBuilder (SubAggregations) if len(a.subAggregations) > 0 { diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_top_hits.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_top_hits.go similarity index 86% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_top_hits.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_top_hits.go index 43dd36cdb1..db6d63e44a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_top_hits.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_top_hits.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-top-hits-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-top-hits-aggregation.html type TopHitsAggregation struct { searchSource *SearchSource } @@ -24,6 +24,14 @@ func NewTopHitsAggregation() *TopHitsAggregation { } } +func (a *TopHitsAggregation) SearchSource(searchSource *SearchSource) *TopHitsAggregation { + a.searchSource = searchSource + if a.searchSource == nil { + a.searchSource = NewSearchSource() + } + return a +} + func (a *TopHitsAggregation) From(from int) *TopHitsAggregation { a.searchSource = a.searchSource.From(from) return a @@ -69,11 +77,21 @@ func (a *TopHitsAggregation) DocvalueFields(docvalueFields ...string) *TopHitsAg return a } +func (a *TopHitsAggregation) DocvalueFieldsWithFormat(docvalueFields ...DocvalueField) *TopHitsAggregation { + a.searchSource = a.searchSource.DocvalueFieldsWithFormat(docvalueFields...) + return a +} + func (a *TopHitsAggregation) DocvalueField(docvalueField string) *TopHitsAggregation { a.searchSource = a.searchSource.DocvalueField(docvalueField) return a } +func (a *TopHitsAggregation) DocvalueFieldWithFormat(docvalueField DocvalueField) *TopHitsAggregation { + a.searchSource = a.searchSource.DocvalueFieldWithFormat(docvalueField) + return a +} + func (a *TopHitsAggregation) ScriptFields(scriptFields ...*ScriptField) *TopHitsAggregation { a.searchSource = a.searchSource.ScriptFields(scriptFields...) return a diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_value_count.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_value_count.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_value_count.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_value_count.go index 4e7281d62d..699a1ea9a5 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_metrics_value_count.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_value_count.go @@ -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: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-valuecount-aggregation.html +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-valuecount-aggregation.html type ValueCountAggregation struct { field string script *Script diff --git a/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_weighted_avg.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_weighted_avg.go new file mode 100644 index 0000000000..586472a8ac --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_metrics_weighted_avg.go @@ -0,0 +1,156 @@ +// 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 + +// WeightedAvgAggregation is a single-value metrics aggregation that +// computes the weighted average of numeric values that are extracted +// from the aggregated documents. These values can be extracted either +// from specific numeric fields in the documents. +// +// See: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-weight-avg-aggregation.html +type WeightedAvgAggregation struct { + fields map[string]*MultiValuesSourceFieldConfig + valueType string + format string + value *MultiValuesSourceFieldConfig + weight *MultiValuesSourceFieldConfig + subAggregations map[string]Aggregation + meta map[string]interface{} +} + +func NewWeightedAvgAggregation() *WeightedAvgAggregation { + return &WeightedAvgAggregation{ + fields: make(map[string]*MultiValuesSourceFieldConfig), + subAggregations: make(map[string]Aggregation), + } +} + +func (a *WeightedAvgAggregation) Field(field string, config *MultiValuesSourceFieldConfig) *WeightedAvgAggregation { + a.fields[field] = config + return a +} + +func (a *WeightedAvgAggregation) ValueType(valueType string) *WeightedAvgAggregation { + a.valueType = valueType + return a +} + +func (a *WeightedAvgAggregation) Format(format string) *WeightedAvgAggregation { + a.format = format + return a +} + +func (a *WeightedAvgAggregation) Value(value *MultiValuesSourceFieldConfig) *WeightedAvgAggregation { + a.value = value + return a +} + +func (a *WeightedAvgAggregation) Weight(weight *MultiValuesSourceFieldConfig) *WeightedAvgAggregation { + a.weight = weight + return a +} + +func (a *WeightedAvgAggregation) SubAggregation(name string, subAggregation Aggregation) *WeightedAvgAggregation { + a.subAggregations[name] = subAggregation + return a +} + +// Meta sets the meta data to be included in the aggregation response. +func (a *WeightedAvgAggregation) Meta(metaData map[string]interface{}) *WeightedAvgAggregation { + a.meta = metaData + return a +} + +func (a *WeightedAvgAggregation) Source() (interface{}, error) { + source := make(map[string]interface{}) + opts := make(map[string]interface{}) + source["weighted_avg"] = opts + + if len(a.fields) > 0 { + f := make(map[string]interface{}) + for name, config := range a.fields { + cfg, err := config.Source() + if err != nil { + return nil, err + } + f[name] = cfg + } + opts["fields"] = f + } + + if v := a.format; v != "" { + opts["format"] = v + } + + if v := a.valueType; v != "" { + opts["value_type"] = v + } + + if v := a.value; v != nil { + cfg, err := v.Source() + if err != nil { + return nil, err + } + opts["value"] = cfg + } + + if v := a.weight; v != nil { + cfg, err := v.Source() + if err != nil { + return nil, err + } + opts["weight"] = cfg + } + + // AggregationBuilder (SubAggregations) + if len(a.subAggregations) > 0 { + aggsMap := make(map[string]interface{}) + source["aggregations"] = aggsMap + for name, aggregate := range a.subAggregations { + src, err := aggregate.Source() + if err != nil { + return nil, err + } + aggsMap[name] = src + } + } + + // Add Meta data if available + if len(a.meta) > 0 { + source["meta"] = a.meta + } + + return source, nil +} + +// MultiValuesSourceFieldConfig represents a field configuration +// used e.g. in WeightedAvgAggregation. +type MultiValuesSourceFieldConfig struct { + FieldName string + Missing interface{} + Script *Script + TimeZone string +} + +func (f *MultiValuesSourceFieldConfig) Source() (interface{}, error) { + source := make(map[string]interface{}) + if v := f.Missing; v != nil { + source["missing"] = v + } + if v := f.Script; v != nil { + src, err := v.Source() + if err != nil { + return nil, err + } + source["script"] = src + } + if v := f.FieldName; v != "" { + source["field"] = v + } + if v := f.TimeZone; v != "" { + source["time_zone"] = v + } + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_avg_bucket.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_avg_bucket.go similarity index 75% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_avg_bucket.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_avg_bucket.go index 7eea9310d5..3e63beca6b 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_avg_bucket.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_avg_bucket.go @@ -10,24 +10,23 @@ package elastic // be a multi-bucket aggregation. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-avg-bucket-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-avg-bucket-aggregation.html type AvgBucketAggregation struct { format string gapPolicy string - subAggregations map[string]Aggregation - meta map[string]interface{} - bucketsPaths []string + meta map[string]interface{} + bucketsPaths []string } // NewAvgBucketAggregation creates and initializes a new AvgBucketAggregation. func NewAvgBucketAggregation() *AvgBucketAggregation { return &AvgBucketAggregation{ - subAggregations: make(map[string]Aggregation), - bucketsPaths: make([]string, 0), + bucketsPaths: make([]string, 0), } } +// Format to use on the output of this aggregation. func (a *AvgBucketAggregation) Format(format string) *AvgBucketAggregation { a.format = format return a @@ -52,12 +51,6 @@ func (a *AvgBucketAggregation) GapSkip() *AvgBucketAggregation { return a } -// SubAggregation adds a sub-aggregation to this aggregation. -func (a *AvgBucketAggregation) SubAggregation(name string, subAggregation Aggregation) *AvgBucketAggregation { - a.subAggregations[name] = subAggregation - return a -} - // Meta sets the meta data to be included in the aggregation response. func (a *AvgBucketAggregation) Meta(metaData map[string]interface{}) *AvgBucketAggregation { a.meta = metaData @@ -70,6 +63,7 @@ func (a *AvgBucketAggregation) BucketsPath(bucketsPaths ...string) *AvgBucketAgg return a } +// Source returns the a JSON-serializable interface. func (a *AvgBucketAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -91,19 +85,6 @@ func (a *AvgBucketAggregation) Source() (interface{}, error) { params["buckets_path"] = a.bucketsPaths } - // AggregationBuilder (SubAggregations) - if len(a.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range a.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(a.meta) > 0 { source["meta"] = a.meta diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_script.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_bucket_script.go similarity index 82% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_script.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_bucket_script.go index 13cad638f2..9c12d6418a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_script.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_bucket_script.go @@ -10,13 +10,12 @@ package elastic // numeric and the script must return a numeric value. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-bucket-script-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-bucket-script-aggregation.html type BucketScriptAggregation struct { format string gapPolicy string script *Script - subAggregations map[string]Aggregation meta map[string]interface{} bucketsPathsMap map[string]string } @@ -24,11 +23,11 @@ type BucketScriptAggregation struct { // NewBucketScriptAggregation creates and initializes a new BucketScriptAggregation. func NewBucketScriptAggregation() *BucketScriptAggregation { return &BucketScriptAggregation{ - subAggregations: make(map[string]Aggregation), bucketsPathsMap: make(map[string]string), } } +// Format to use on the output of this aggregation. func (a *BucketScriptAggregation) Format(format string) *BucketScriptAggregation { a.format = format return a @@ -59,12 +58,6 @@ func (a *BucketScriptAggregation) Script(script *Script) *BucketScriptAggregatio return a } -// SubAggregation adds a sub-aggregation to this aggregation. -func (a *BucketScriptAggregation) SubAggregation(name string, subAggregation Aggregation) *BucketScriptAggregation { - a.subAggregations[name] = subAggregation - return a -} - // Meta sets the meta data to be included in the aggregation response. func (a *BucketScriptAggregation) Meta(metaData map[string]interface{}) *BucketScriptAggregation { a.meta = metaData @@ -86,6 +79,7 @@ func (a *BucketScriptAggregation) AddBucketsPath(name, path string) *BucketScrip return a } +// Source returns the a JSON-serializable interface. func (a *BucketScriptAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -110,19 +104,6 @@ func (a *BucketScriptAggregation) Source() (interface{}, error) { params["buckets_path"] = a.bucketsPathsMap } - // AggregationBuilder (SubAggregations) - if len(a.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range a.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(a.meta) > 0 { source["meta"] = a.meta diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_selector.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_bucket_selector.go similarity index 82% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_selector.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_bucket_selector.go index f3c9385190..d0e3fc76f0 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_bucket_selector.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_bucket_selector.go @@ -12,13 +12,12 @@ 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/5.2/search-aggregations-pipeline-bucket-selector-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-bucket-selector-aggregation.html type BucketSelectorAggregation struct { format string gapPolicy string script *Script - subAggregations map[string]Aggregation meta map[string]interface{} bucketsPathsMap map[string]string } @@ -26,11 +25,11 @@ type BucketSelectorAggregation struct { // NewBucketSelectorAggregation creates and initializes a new BucketSelectorAggregation. func NewBucketSelectorAggregation() *BucketSelectorAggregation { return &BucketSelectorAggregation{ - subAggregations: make(map[string]Aggregation), bucketsPathsMap: make(map[string]string), } } +// Format to use on the output of this aggregation. func (a *BucketSelectorAggregation) Format(format string) *BucketSelectorAggregation { a.format = format return a @@ -61,12 +60,6 @@ func (a *BucketSelectorAggregation) Script(script *Script) *BucketSelectorAggreg return a } -// SubAggregation adds a sub-aggregation to this aggregation. -func (a *BucketSelectorAggregation) SubAggregation(name string, subAggregation Aggregation) *BucketSelectorAggregation { - a.subAggregations[name] = subAggregation - return a -} - // Meta sets the meta data to be included in the aggregation response. func (a *BucketSelectorAggregation) Meta(metaData map[string]interface{}) *BucketSelectorAggregation { a.meta = metaData @@ -88,6 +81,7 @@ func (a *BucketSelectorAggregation) AddBucketsPath(name, path string) *BucketSel return a } +// Source returns the a JSON-serializable interface. func (a *BucketSelectorAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -112,19 +106,6 @@ func (a *BucketSelectorAggregation) Source() (interface{}, error) { params["buckets_path"] = a.bucketsPathsMap } - // AggregationBuilder (SubAggregations) - if len(a.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range a.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(a.meta) > 0 { source["meta"] = a.meta diff --git a/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_bucket_sort.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_bucket_sort.go new file mode 100644 index 0000000000..21ff519c4c --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_bucket_sort.go @@ -0,0 +1,119 @@ +// 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 + +// BucketSortAggregation parent pipeline aggregation which sorts the buckets +// of its parent multi-bucket aggregation. Zero or more sort fields may be +// specified together with the corresponding sort order. Each bucket may be +// sorted based on its _key, _count or its sub-aggregations. In addition, +// parameters from and size may be set in order to truncate the result buckets. +// +// For more details, see +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-bucket-sort-aggregation.html +type BucketSortAggregation struct { + sorters []Sorter + from int + size int + gapPolicy string + + meta map[string]interface{} +} + +// NewBucketSortAggregation creates and initializes a new BucketSortAggregation. +func NewBucketSortAggregation() *BucketSortAggregation { + return &BucketSortAggregation{ + size: -1, + } +} + +// Sort adds a sort order to the list of sorters. +func (a *BucketSortAggregation) Sort(field string, ascending bool) *BucketSortAggregation { + a.sorters = append(a.sorters, SortInfo{Field: field, Ascending: ascending}) + return a +} + +// SortWithInfo adds a SortInfo to the list of sorters. +func (a *BucketSortAggregation) SortWithInfo(info SortInfo) *BucketSortAggregation { + a.sorters = append(a.sorters, info) + return a +} + +// From adds the "from" parameter to the aggregation. +func (a *BucketSortAggregation) From(from int) *BucketSortAggregation { + a.from = from + return a +} + +// Size adds the "size" parameter to the aggregation. +func (a *BucketSortAggregation) Size(size int) *BucketSortAggregation { + a.size = size + return a +} + +// GapPolicy defines what should be done when a gap in the series is discovered. +// Valid values include "insert_zeros" or "skip". Default is "skip". +func (a *BucketSortAggregation) GapPolicy(gapPolicy string) *BucketSortAggregation { + a.gapPolicy = gapPolicy + return a +} + +// GapInsertZeros inserts zeros for gaps in the series. +func (a *BucketSortAggregation) GapInsertZeros() *BucketSortAggregation { + a.gapPolicy = "insert_zeros" + return a +} + +// GapSkip skips gaps in the series. +func (a *BucketSortAggregation) GapSkip() *BucketSortAggregation { + a.gapPolicy = "skip" + return a +} + +// Meta sets the meta data in the aggregation. +// Although metadata is supported for this aggregation by Elasticsearch, it's important to +// note that there's no use to it because this aggregation does not include new data in the +// response. It merely reorders parent buckets. +func (a *BucketSortAggregation) Meta(meta map[string]interface{}) *BucketSortAggregation { + a.meta = meta + return a +} + +// Source returns the a JSON-serializable interface. +func (a *BucketSortAggregation) Source() (interface{}, error) { + source := make(map[string]interface{}) + params := make(map[string]interface{}) + source["bucket_sort"] = params + + if a.from != 0 { + params["from"] = a.from + } + if a.size != -1 { + params["size"] = a.size + } + + if a.gapPolicy != "" { + params["gap_policy"] = a.gapPolicy + } + + // Parses sorters to JSON-serializable interface. + if len(a.sorters) > 0 { + sorters := make([]interface{}, len(a.sorters)) + params["sort"] = sorters + for idx, sorter := range a.sorters { + src, err := sorter.Source() + if err != nil { + return nil, err + } + sorters[idx] = src + } + } + + // Add metadata if available. + if len(a.meta) > 0 { + source["meta"] = a.meta + } + + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_cumulative_sum.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_cumulative_sum.go similarity index 70% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_cumulative_sum.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_cumulative_sum.go index 95546f1cb0..b2b9d2be6e 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_cumulative_sum.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_cumulative_sum.go @@ -10,34 +10,27 @@ 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/5.2/search-aggregations-pipeline-cumulative-sum-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-cumulative-sum-aggregation.html type CumulativeSumAggregation struct { format string - subAggregations map[string]Aggregation - meta map[string]interface{} - bucketsPaths []string + meta map[string]interface{} + bucketsPaths []string } // NewCumulativeSumAggregation creates and initializes a new CumulativeSumAggregation. func NewCumulativeSumAggregation() *CumulativeSumAggregation { return &CumulativeSumAggregation{ - subAggregations: make(map[string]Aggregation), - bucketsPaths: make([]string, 0), + bucketsPaths: make([]string, 0), } } +// Format to use on the output of this aggregation. func (a *CumulativeSumAggregation) Format(format string) *CumulativeSumAggregation { a.format = format return a } -// SubAggregation adds a sub-aggregation to this aggregation. -func (a *CumulativeSumAggregation) SubAggregation(name string, subAggregation Aggregation) *CumulativeSumAggregation { - a.subAggregations[name] = subAggregation - return a -} - // Meta sets the meta data to be included in the aggregation response. func (a *CumulativeSumAggregation) Meta(metaData map[string]interface{}) *CumulativeSumAggregation { a.meta = metaData @@ -50,6 +43,7 @@ func (a *CumulativeSumAggregation) BucketsPath(bucketsPaths ...string) *Cumulati return a } +// Source returns the a JSON-serializable interface. func (a *CumulativeSumAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -68,19 +62,6 @@ func (a *CumulativeSumAggregation) Source() (interface{}, error) { params["buckets_path"] = a.bucketsPaths } - // AggregationBuilder (SubAggregations) - if len(a.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range a.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(a.meta) > 0 { source["meta"] = a.meta diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_derivative.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_derivative.go similarity index 78% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_derivative.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_derivative.go index 2c3c7e03ab..820242acc5 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_derivative.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_derivative.go @@ -10,25 +10,24 @@ 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/5.2/search-aggregations-pipeline-derivative-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-derivative-aggregation.html type DerivativeAggregation struct { format string gapPolicy string unit string - subAggregations map[string]Aggregation - meta map[string]interface{} - bucketsPaths []string + meta map[string]interface{} + bucketsPaths []string } // NewDerivativeAggregation creates and initializes a new DerivativeAggregation. func NewDerivativeAggregation() *DerivativeAggregation { return &DerivativeAggregation{ - subAggregations: make(map[string]Aggregation), - bucketsPaths: make([]string, 0), + bucketsPaths: make([]string, 0), } } +// Format to use on the output of this aggregation. func (a *DerivativeAggregation) Format(format string) *DerivativeAggregation { a.format = format return a @@ -60,12 +59,6 @@ func (a *DerivativeAggregation) Unit(unit string) *DerivativeAggregation { return a } -// SubAggregation adds a sub-aggregation to this aggregation. -func (a *DerivativeAggregation) SubAggregation(name string, subAggregation Aggregation) *DerivativeAggregation { - a.subAggregations[name] = subAggregation - return a -} - // Meta sets the meta data to be included in the aggregation response. func (a *DerivativeAggregation) Meta(metaData map[string]interface{}) *DerivativeAggregation { a.meta = metaData @@ -78,6 +71,7 @@ func (a *DerivativeAggregation) BucketsPath(bucketsPaths ...string) *DerivativeA return a } +// Source returns the a JSON-serializable interface. func (a *DerivativeAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -102,19 +96,6 @@ func (a *DerivativeAggregation) Source() (interface{}, error) { params["buckets_path"] = a.bucketsPaths } - // AggregationBuilder (SubAggregations) - if len(a.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range a.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(a.meta) > 0 { source["meta"] = a.meta diff --git a/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_extended_stats_bucket.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_extended_stats_bucket.go new file mode 100644 index 0000000000..a22f19686a --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_extended_stats_bucket.go @@ -0,0 +1,107 @@ +// 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 + +// ExtendedStatsBucketAggregation 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. +// +// This aggregation provides a few more statistics (sum of squares, standard deviation, etc) +// compared to the stats_bucket aggregation. +// For more details, see +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-extended-stats-bucket-aggregation.html +type ExtendedStatsBucketAggregation struct { + format string + gapPolicy string + sigma *float32 + meta map[string]interface{} + bucketsPaths []string +} + +// NewExtendedStatsBucketAggregation creates and initializes a new ExtendedStatsBucketAggregation. +func NewExtendedStatsBucketAggregation() *ExtendedStatsBucketAggregation { + return &ExtendedStatsBucketAggregation{ + bucketsPaths: make([]string, 0), + } +} + +// Format to use on the output of this aggregation. +func (s *ExtendedStatsBucketAggregation) Format(format string) *ExtendedStatsBucketAggregation { + 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 *ExtendedStatsBucketAggregation) GapPolicy(gapPolicy string) *ExtendedStatsBucketAggregation { + s.gapPolicy = gapPolicy + return s +} + +// GapInsertZeros inserts zeros for gaps in the series. +func (s *ExtendedStatsBucketAggregation) GapInsertZeros() *ExtendedStatsBucketAggregation { + s.gapPolicy = "insert_zeros" + return s +} + +// GapSkip skips gaps in the series. +func (s *ExtendedStatsBucketAggregation) GapSkip() *ExtendedStatsBucketAggregation { + s.gapPolicy = "skip" + return s +} + +// Meta sets the meta data to be included in the aggregation response. +func (s *ExtendedStatsBucketAggregation) Meta(metaData map[string]interface{}) *ExtendedStatsBucketAggregation { + s.meta = metaData + return s +} + +// BucketsPath sets the paths to the buckets to use for this pipeline aggregator. +func (s *ExtendedStatsBucketAggregation) BucketsPath(bucketsPaths ...string) *ExtendedStatsBucketAggregation { + s.bucketsPaths = append(s.bucketsPaths, bucketsPaths...) + return s +} + +// Sigma sets number of standard deviations above/below the mean to display +func (s *ExtendedStatsBucketAggregation) Sigma(sigma float32) *ExtendedStatsBucketAggregation { + s.sigma = &sigma + return s +} + +// Source returns the a JSON-serializable interface. +func (s *ExtendedStatsBucketAggregation) Source() (interface{}, error) { + source := make(map[string]interface{}) + params := make(map[string]interface{}) + source["extended_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 + } + + // Add sigma is not zero or less + if s.sigma != nil && *s.sigma >= 0 { + params["sigma"] = *s.sigma + } + + // 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.v5/search_aggs_pipeline_max_bucket.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_max_bucket.go similarity index 76% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_max_bucket.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_max_bucket.go index 5a10b0e455..a89ceaf7de 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_max_bucket.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_max_bucket.go @@ -11,24 +11,23 @@ package elastic // be a multi-bucket aggregation. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-max-bucket-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-max-bucket-aggregation.html type MaxBucketAggregation struct { format string gapPolicy string - subAggregations map[string]Aggregation - meta map[string]interface{} - bucketsPaths []string + meta map[string]interface{} + bucketsPaths []string } // NewMaxBucketAggregation creates and initializes a new MaxBucketAggregation. func NewMaxBucketAggregation() *MaxBucketAggregation { return &MaxBucketAggregation{ - subAggregations: make(map[string]Aggregation), - bucketsPaths: make([]string, 0), + bucketsPaths: make([]string, 0), } } +// Format to use on the output of this aggregation. func (a *MaxBucketAggregation) Format(format string) *MaxBucketAggregation { a.format = format return a @@ -53,12 +52,6 @@ func (a *MaxBucketAggregation) GapSkip() *MaxBucketAggregation { return a } -// SubAggregation adds a sub-aggregation to this aggregation. -func (a *MaxBucketAggregation) SubAggregation(name string, subAggregation Aggregation) *MaxBucketAggregation { - a.subAggregations[name] = subAggregation - return a -} - // Meta sets the meta data to be included in the aggregation response. func (a *MaxBucketAggregation) Meta(metaData map[string]interface{}) *MaxBucketAggregation { a.meta = metaData @@ -71,6 +64,7 @@ func (a *MaxBucketAggregation) BucketsPath(bucketsPaths ...string) *MaxBucketAgg return a } +// Source returns the a JSON-serializable interface. func (a *MaxBucketAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -92,19 +86,6 @@ func (a *MaxBucketAggregation) Source() (interface{}, error) { params["buckets_path"] = a.bucketsPaths } - // AggregationBuilder (SubAggregations) - if len(a.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range a.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(a.meta) > 0 { source["meta"] = a.meta diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_min_bucket.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_min_bucket.go similarity index 76% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_min_bucket.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_min_bucket.go index 96982250ca..3496e992e6 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_min_bucket.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_min_bucket.go @@ -11,24 +11,23 @@ package elastic // be a multi-bucket aggregation. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-min-bucket-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-min-bucket-aggregation.html type MinBucketAggregation struct { format string gapPolicy string - subAggregations map[string]Aggregation - meta map[string]interface{} - bucketsPaths []string + meta map[string]interface{} + bucketsPaths []string } // NewMinBucketAggregation creates and initializes a new MinBucketAggregation. func NewMinBucketAggregation() *MinBucketAggregation { return &MinBucketAggregation{ - subAggregations: make(map[string]Aggregation), - bucketsPaths: make([]string, 0), + bucketsPaths: make([]string, 0), } } +// Format to use on the output of this aggregation. func (a *MinBucketAggregation) Format(format string) *MinBucketAggregation { a.format = format return a @@ -53,12 +52,6 @@ func (a *MinBucketAggregation) GapSkip() *MinBucketAggregation { return a } -// SubAggregation adds a sub-aggregation to this aggregation. -func (a *MinBucketAggregation) SubAggregation(name string, subAggregation Aggregation) *MinBucketAggregation { - a.subAggregations[name] = subAggregation - return a -} - // Meta sets the meta data to be included in the aggregation response. func (a *MinBucketAggregation) Meta(metaData map[string]interface{}) *MinBucketAggregation { a.meta = metaData @@ -71,6 +64,7 @@ func (a *MinBucketAggregation) BucketsPath(bucketsPaths ...string) *MinBucketAgg return a } +// Source returns the a JSON-serializable interface. func (a *MinBucketAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -92,19 +86,6 @@ func (a *MinBucketAggregation) Source() (interface{}, error) { params["buckets_path"] = a.bucketsPaths } - // AggregationBuilder (SubAggregations) - if len(a.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range a.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(a.meta) > 0 { source["meta"] = a.meta diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_mov_avg.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_mov_avg.go similarity index 88% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_mov_avg.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_mov_avg.go index cf94342f70..35ec29f9f3 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_mov_avg.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_mov_avg.go @@ -8,7 +8,9 @@ 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/5.2/search-aggregations-pipeline-movavg-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movavg-aggregation.html +// +// Deprecated: The MovAvgAggregation has been deprecated in 6.4.0. Use the more generate MovFnAggregation instead. type MovAvgAggregation struct { format string gapPolicy string @@ -17,19 +19,20 @@ type MovAvgAggregation struct { predict *int minimize *bool - subAggregations map[string]Aggregation - meta map[string]interface{} - bucketsPaths []string + meta map[string]interface{} + bucketsPaths []string } // NewMovAvgAggregation creates and initializes a new MovAvgAggregation. +// +// Deprecated: The MovAvgAggregation has been deprecated in 6.4.0. Use the more generate MovFnAggregation instead. func NewMovAvgAggregation() *MovAvgAggregation { return &MovAvgAggregation{ - subAggregations: make(map[string]Aggregation), - bucketsPaths: make([]string, 0), + bucketsPaths: make([]string, 0), } } +// Format to use on the output of this aggregation. func (a *MovAvgAggregation) Format(format string) *MovAvgAggregation { a.format = format return a @@ -85,12 +88,6 @@ func (a *MovAvgAggregation) Minimize(minimize bool) *MovAvgAggregation { return a } -// SubAggregation adds a sub-aggregation to this aggregation. -func (a *MovAvgAggregation) SubAggregation(name string, subAggregation Aggregation) *MovAvgAggregation { - a.subAggregations[name] = subAggregation - return a -} - // Meta sets the meta data to be included in the aggregation response. func (a *MovAvgAggregation) Meta(metaData map[string]interface{}) *MovAvgAggregation { a.meta = metaData @@ -103,6 +100,7 @@ func (a *MovAvgAggregation) BucketsPath(bucketsPaths ...string) *MovAvgAggregati return a } +// Source returns the a JSON-serializable interface. func (a *MovAvgAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -140,19 +138,6 @@ func (a *MovAvgAggregation) Source() (interface{}, error) { params["buckets_path"] = a.bucketsPaths } - // AggregationBuilder (SubAggregations) - if len(a.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range a.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(a.meta) > 0 { source["meta"] = a.meta @@ -162,7 +147,7 @@ func (a *MovAvgAggregation) Source() (interface{}, error) { } // -- Models for moving averages -- -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html#_models +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movavg-aggregation.html#_models // MovAvgModel specifies the model to use with the MovAvgAggregation. type MovAvgModel interface { @@ -175,7 +160,7 @@ type MovAvgModel interface { // EWMAMovAvgModel calculates an exponentially weighted moving average. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html#_ewma_exponentially_weighted +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movavg-aggregation.html#_ewma_exponentially_weighted type EWMAMovAvgModel struct { alpha *float64 } @@ -213,7 +198,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/5.2/search-aggregations-pipeline-movavg-aggregation.html#_holt_linear +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movavg-aggregation.html#_holt_linear type HoltLinearMovAvgModel struct { alpha *float64 beta *float64 @@ -262,7 +247,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/5.2/search-aggregations-pipeline-movavg-aggregation.html#_holt_winters +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movavg-aggregation.html#_holt_winters type HoltWintersMovAvgModel struct { alpha *float64 beta *float64 @@ -349,7 +334,7 @@ func (m *HoltWintersMovAvgModel) Settings() map[string]interface{} { // by position in collection. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html#_linear +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movavg-aggregation.html#_linear type LinearMovAvgModel struct { } @@ -373,7 +358,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/5.2/search-aggregations-pipeline-movavg-aggregation.html#_simple +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movavg-aggregation.html#_simple type SimpleMovAvgModel struct { } diff --git a/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_mov_fn.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_mov_fn.go new file mode 100644 index 0000000000..542a1e9ccd --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_mov_fn.go @@ -0,0 +1,132 @@ +// 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 + +// MovFnAggregation, given an ordered series of data, will slice a window across +// the data and allow the user to specify a custom script that is executed for +// each window of data. +// +// You must pass a script to process the values. There are a number of predefined +// script functions you can use as described here: +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movfn-aggregation.html#_pre_built_functions. +// +// Example: +// agg := elastic.NewMovFnAggregation( +// "the_sum", // bucket path +// elastic.NewScript("MovingFunctions.stdDev(values, MovingFunctions.unweightedAvg(values))"), +// 10, // window size +// ) +// +// For more details, see +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movfn-aggregation.html. +type MovFnAggregation struct { + script *Script + format string + gapPolicy string + window int + + meta map[string]interface{} + bucketsPaths []string +} + +// NewMovFnAggregation creates and initializes a new MovFnAggregation. +// +// Deprecated: The MovFnAggregation has been deprecated in 6.4.0. Use the more generate MovFnAggregation instead. +func NewMovFnAggregation(bucketsPath string, script *Script, window int) *MovFnAggregation { + return &MovFnAggregation{ + bucketsPaths: []string{bucketsPath}, + script: script, + window: window, + } +} + +// Script is the script to run. +func (a *MovFnAggregation) Script(script *Script) *MovFnAggregation { + a.script = script + return a +} + +// Format to use on the output of this aggregation. +func (a *MovFnAggregation) Format(format string) *MovFnAggregation { + a.format = format + return a +} + +// 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 (a *MovFnAggregation) GapPolicy(gapPolicy string) *MovFnAggregation { + a.gapPolicy = gapPolicy + return a +} + +// GapInsertZeros inserts zeros for gaps in the series. +func (a *MovFnAggregation) GapInsertZeros() *MovFnAggregation { + a.gapPolicy = "insert_zeros" + return a +} + +// GapSkip skips gaps in the series. +func (a *MovFnAggregation) GapSkip() *MovFnAggregation { + a.gapPolicy = "skip" + return a +} + +// Window sets the window size for this aggregation. +func (a *MovFnAggregation) Window(window int) *MovFnAggregation { + a.window = window + return a +} + +// Meta sets the meta data to be included in the aggregation response. +func (a *MovFnAggregation) Meta(metaData map[string]interface{}) *MovFnAggregation { + a.meta = metaData + return a +} + +// BucketsPath sets the paths to the buckets to use for this pipeline aggregator. +func (a *MovFnAggregation) BucketsPath(bucketsPaths ...string) *MovFnAggregation { + a.bucketsPaths = append(a.bucketsPaths, bucketsPaths...) + return a +} + +// Source returns the a JSON-serializable interface. +func (a *MovFnAggregation) Source() (interface{}, error) { + source := make(map[string]interface{}) + params := make(map[string]interface{}) + source["moving_fn"] = params + + // Add buckets paths + switch len(a.bucketsPaths) { + case 0: + case 1: + params["buckets_path"] = a.bucketsPaths[0] + default: + params["buckets_path"] = a.bucketsPaths + } + + // Script + if a.script != nil { + src, err := a.script.Source() + if err != nil { + return nil, err + } + params["script"] = src + } + + if a.format != "" { + params["format"] = a.format + } + if a.gapPolicy != "" { + params["gap_policy"] = a.gapPolicy + } + params["window"] = a.window + + // Add Meta data if available + if len(a.meta) > 0 { + source["meta"] = a.meta + } + + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_percentiles_bucket.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_percentiles_bucket.go similarity index 77% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_percentiles_bucket.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_percentiles_bucket.go index 4caca74329..b381fc1fea 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_percentiles_bucket.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_percentiles_bucket.go @@ -10,22 +10,19 @@ package elastic // be a multi-bucket aggregation. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-percentiles-bucket-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-percentiles-bucket-aggregation.html type PercentilesBucketAggregation struct { format string gapPolicy string percents []float64 bucketsPaths []string - subAggregations map[string]Aggregation - meta map[string]interface{} + meta map[string]interface{} } // NewPercentilesBucketAggregation creates and initializes a new PercentilesBucketAggregation. func NewPercentilesBucketAggregation() *PercentilesBucketAggregation { - return &PercentilesBucketAggregation{ - subAggregations: make(map[string]Aggregation), - } + return &PercentilesBucketAggregation{} } // Format to apply the output value of this aggregation. @@ -59,12 +56,6 @@ func (p *PercentilesBucketAggregation) GapSkip() *PercentilesBucketAggregation { return p } -// SubAggregation adds a sub-aggregation to this aggregation. -func (p *PercentilesBucketAggregation) SubAggregation(name string, subAggregation Aggregation) *PercentilesBucketAggregation { - p.subAggregations[name] = subAggregation - return p -} - // Meta sets the meta data to be included in the aggregation response. func (p *PercentilesBucketAggregation) Meta(metaData map[string]interface{}) *PercentilesBucketAggregation { p.meta = metaData @@ -77,6 +68,7 @@ func (p *PercentilesBucketAggregation) BucketsPath(bucketsPaths ...string) *Perc return p } +// Source returns the a JSON-serializable interface. func (p *PercentilesBucketAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -103,19 +95,6 @@ func (p *PercentilesBucketAggregation) Source() (interface{}, error) { params["percents"] = p.percents } - // AggregationBuilder (SubAggregations) - if len(p.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range p.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(p.meta) > 0 { source["meta"] = p.meta diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_serial_diff.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_serial_diff.go similarity index 77% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_serial_diff.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_serial_diff.go index 84ae430048..db35a49988 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_serial_diff.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_serial_diff.go @@ -9,25 +9,24 @@ package elastic // subtracted from itself at different time lags or periods. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-serialdiff-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-serialdiff-aggregation.html type SerialDiffAggregation struct { format string gapPolicy string lag *int - subAggregations map[string]Aggregation - meta map[string]interface{} - bucketsPaths []string + meta map[string]interface{} + bucketsPaths []string } // NewSerialDiffAggregation creates and initializes a new SerialDiffAggregation. func NewSerialDiffAggregation() *SerialDiffAggregation { return &SerialDiffAggregation{ - subAggregations: make(map[string]Aggregation), - bucketsPaths: make([]string, 0), + bucketsPaths: make([]string, 0), } } +// Format to use on the output of this aggregation. func (a *SerialDiffAggregation) Format(format string) *SerialDiffAggregation { a.format = format return a @@ -60,12 +59,6 @@ func (a *SerialDiffAggregation) Lag(lag int) *SerialDiffAggregation { return a } -// SubAggregation adds a sub-aggregation to this aggregation. -func (a *SerialDiffAggregation) SubAggregation(name string, subAggregation Aggregation) *SerialDiffAggregation { - a.subAggregations[name] = subAggregation - return a -} - // Meta sets the meta data to be included in the aggregation response. func (a *SerialDiffAggregation) Meta(metaData map[string]interface{}) *SerialDiffAggregation { a.meta = metaData @@ -78,6 +71,7 @@ func (a *SerialDiffAggregation) BucketsPath(bucketsPaths ...string) *SerialDiffA return a } +// Source returns the a JSON-serializable interface. func (a *SerialDiffAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -102,19 +96,6 @@ func (a *SerialDiffAggregation) Source() (interface{}, error) { params["buckets_path"] = a.bucketsPaths } - // AggregationBuilder (SubAggregations) - if len(a.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range a.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(a.meta) > 0 { source["meta"] = a.meta diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_stats_bucket.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_stats_bucket.go similarity index 76% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_stats_bucket.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_stats_bucket.go index fb0a94afc3..398b633ae2 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_stats_bucket.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_stats_bucket.go @@ -10,24 +10,23 @@ package elastic // 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 +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-stats-bucket-aggregation.html type StatsBucketAggregation struct { format string gapPolicy string - subAggregations map[string]Aggregation - meta map[string]interface{} - bucketsPaths []string + 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), + bucketsPaths: make([]string, 0), } } +// Format to use on the output of this aggregation. func (s *StatsBucketAggregation) Format(format string) *StatsBucketAggregation { s.format = format return s @@ -52,12 +51,6 @@ func (s *StatsBucketAggregation) GapSkip() *StatsBucketAggregation { 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 @@ -70,6 +63,7 @@ func (s *StatsBucketAggregation) BucketsPath(bucketsPaths ...string) *StatsBucke return s } +// Source returns the a JSON-serializable interface. func (s *StatsBucketAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -91,19 +85,6 @@ func (s *StatsBucketAggregation) Source() (interface{}, error) { 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 diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_sum_bucket.go b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_sum_bucket.go similarity index 75% rename from vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_sum_bucket.go rename to vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_sum_bucket.go index 1f78efa565..8cbc53c8ce 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs_pipeline_sum_bucket.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_aggs_pipeline_sum_bucket.go @@ -10,24 +10,23 @@ package elastic // be a multi-bucket aggregation. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-sum-bucket-aggregation.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-sum-bucket-aggregation.html type SumBucketAggregation struct { format string gapPolicy string - subAggregations map[string]Aggregation - meta map[string]interface{} - bucketsPaths []string + meta map[string]interface{} + bucketsPaths []string } // NewSumBucketAggregation creates and initializes a new SumBucketAggregation. func NewSumBucketAggregation() *SumBucketAggregation { return &SumBucketAggregation{ - subAggregations: make(map[string]Aggregation), - bucketsPaths: make([]string, 0), + bucketsPaths: make([]string, 0), } } +// Format to use on the output of this aggregation. func (a *SumBucketAggregation) Format(format string) *SumBucketAggregation { a.format = format return a @@ -52,12 +51,6 @@ func (a *SumBucketAggregation) GapSkip() *SumBucketAggregation { return a } -// SubAggregation adds a sub-aggregation to this aggregation. -func (a *SumBucketAggregation) SubAggregation(name string, subAggregation Aggregation) *SumBucketAggregation { - a.subAggregations[name] = subAggregation - return a -} - // Meta sets the meta data to be included in the aggregation response. func (a *SumBucketAggregation) Meta(metaData map[string]interface{}) *SumBucketAggregation { a.meta = metaData @@ -70,6 +63,7 @@ func (a *SumBucketAggregation) BucketsPath(bucketsPaths ...string) *SumBucketAgg return a } +// Source returns the a JSON-serializable interface. func (a *SumBucketAggregation) Source() (interface{}, error) { source := make(map[string]interface{}) params := make(map[string]interface{}) @@ -91,19 +85,6 @@ func (a *SumBucketAggregation) Source() (interface{}, error) { params["buckets_path"] = a.bucketsPaths } - // AggregationBuilder (SubAggregations) - if len(a.subAggregations) > 0 { - aggsMap := make(map[string]interface{}) - source["aggregations"] = aggsMap - for name, aggregate := range a.subAggregations { - src, err := aggregate.Source() - if err != nil { - return nil, err - } - aggsMap[name] = src - } - } - // Add Meta data if available if len(a.meta) > 0 { source["meta"] = a.meta diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_collapse_builder.go b/vendor/gopkg.in/olivere/elastic.v6/search_collapse_builder.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/search_collapse_builder.go rename to vendor/gopkg.in/olivere/elastic.v6/search_collapse_builder.go index 48ed17acb0..7275037cf8 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_collapse_builder.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_collapse_builder.go @@ -5,7 +5,7 @@ package elastic // CollapseBuilder enables field collapsing on a search request. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-request-collapse.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-collapse.html // for details. type CollapseBuilder struct { field string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_bool.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_bool.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_bool.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_bool.go index 8ae223834e..8015c3343f 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_bool.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_bool.go @@ -9,7 +9,7 @@ import "fmt" // A bool query matches documents matching boolean // combinations of other queries. // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-bool-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-bool-query.html type BoolQuery struct { Query mustClauses []Query @@ -17,7 +17,6 @@ type BoolQuery struct { filterClauses []Query shouldClauses []Query boost *float64 - disableCoord *bool minimumShouldMatch string adjustPureNegative *bool queryName string @@ -58,11 +57,6 @@ func (q *BoolQuery) Boost(boost float64) *BoolQuery { return q } -func (q *BoolQuery) DisableCoord(disableCoord bool) *BoolQuery { - q.disableCoord = &disableCoord - return q -} - func (q *BoolQuery) MinimumShouldMatch(minimumShouldMatch string) *BoolQuery { q.minimumShouldMatch = minimumShouldMatch return q @@ -106,7 +100,7 @@ func (q *BoolQuery) Source() (interface{}, error) { // "term" : { "tag" : "elasticsearch" } // } // ], - // "minimum_number_should_match" : 1, + // "minimum_should_match" : 1, // "boost" : 1.0 // } // } @@ -195,9 +189,6 @@ func (q *BoolQuery) Source() (interface{}, error) { if q.boost != nil { boolClause["boost"] = *q.boost } - if q.disableCoord != nil { - boolClause["disable_coord"] = *q.disableCoord - } if q.minimumShouldMatch != "" { boolClause["minimum_should_match"] = q.minimumShouldMatch } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_boosting.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_boosting.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_boosting.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_boosting.go index 3a31237c99..fe0ee24a97 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_boosting.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_boosting.go @@ -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: -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-boosting-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-boosting-query.html type BoostingQuery struct { Query positiveClause Query diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_common_terms.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_common_terms.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_common_terms.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_common_terms.go index a1a37b37c4..073e283f25 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_common_terms.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_common_terms.go @@ -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/5.2/query-dsl-common-terms-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-common-terms-query.html type CommonTermsQuery struct { Query name string @@ -22,7 +22,6 @@ type CommonTermsQuery struct { lowFreqMinimumShouldMatch string analyzer string boost *float64 - disableCoord *bool queryName string } @@ -76,11 +75,6 @@ func (q *CommonTermsQuery) Boost(boost float64) *CommonTermsQuery { return q } -func (q *CommonTermsQuery) DisableCoord(disableCoord bool) *CommonTermsQuery { - q.disableCoord = &disableCoord - return q -} - func (q *CommonTermsQuery) QueryName(queryName string) *CommonTermsQuery { q.queryName = queryName return q @@ -132,9 +126,6 @@ func (q *CommonTermsQuery) Source() (interface{}, error) { if q.analyzer != "" { query["analyzer"] = q.analyzer } - if q.disableCoord != nil { - query["disable_coord"] = *q.disableCoord - } if q.boost != nil { query["boost"] = *q.boost } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_constant_score.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_constant_score.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_constant_score.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_constant_score.go index 3ba879958f..d503f6c808 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_constant_score.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_constant_score.go @@ -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/5.2/query-dsl-constant-score-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-constant-score-query.html type ConstantScoreQuery struct { filter Query boost *float64 diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_dis_max.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_dis_max.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_dis_max.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_dis_max.go index af9a40d375..0bc96f6e6e 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_dis_max.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_dis_max.go @@ -10,7 +10,7 @@ package elastic // increment for any additional matching subqueries. // // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-dis-max-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-dis-max-query.html type DisMaxQuery struct { queries []Query boost *float64 diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_exists.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_exists.go similarity index 89% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_exists.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_exists.go index 6c2ebd369c..06389acf84 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_exists.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_exists.go @@ -8,13 +8,13 @@ package elastic // has a value in them. // // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-exists-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-exists-query.html type ExistsQuery struct { name string queryName string } -// NewExistsQuery creates and initializes a new dis max query. +// NewExistsQuery creates and initializes a new exists query. func NewExistsQuery(name string) *ExistsQuery { return &ExistsQuery{ name: name, diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_fsq.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_fsq.go index 82821b0b6c..7ea66c68f9 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_fsq.go @@ -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/5.2/query-dsl-function-score-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html type FunctionScoreQuery struct { query Query filter Query diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq_score_funcs.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_fsq_score_funcs.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq_score_funcs.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_fsq_score_funcs.go index 622b645bbc..44c45fce5d 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_fsq_score_funcs.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_fsq_score_funcs.go @@ -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/5.2/query-dsl-function-score-query.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/query-dsl-function-score-query.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/query-dsl-function-score-query.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/query-dsl-function-score-query.html#_script_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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 https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_field_value_factor. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/query-dsl-function-score-query.html#_weight +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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/5.2/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#_using_function_score // for details. func (fn *WeightFactorFunction) Weight(weight float64) *WeightFactorFunction { fn.weight = weight @@ -517,9 +517,10 @@ func (fn *WeightFactorFunction) Source() (interface{}, error) { // -- Random -- // RandomFunction builds a random score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_random +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#_random // for details. type RandomFunction struct { + field string seed interface{} weight *float64 } @@ -535,15 +536,26 @@ func (fn *RandomFunction) Name() string { return "random_score" } -// Seed is documented in 1.6 as a numeric value. However, in the source code -// of the Java client, it also accepts strings. So we accept both here, too. +// Field is the field to be used for random number generation. +// This parameter is compulsory when a Seed is set and ignored +// otherwise. Note that documents that have the same value for a +// field will get the same score. +func (fn *RandomFunction) Field(field string) *RandomFunction { + fn.field = field + return fn +} + +// Seed sets the seed based on which the random number will be generated. +// Using the same seed is guaranteed to generate the same random number for a specific doc. +// Seed must be an integer, e.g. int or int64. It is specified as an interface{} +// here for compatibility with older versions (which also accepted strings). func (fn *RandomFunction) Seed(seed interface{}) *RandomFunction { fn.seed = seed return fn } // Weight adjusts the score of the score function. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#_using_function_score +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#_using_function_score // for details. func (fn *RandomFunction) Weight(weight float64) *RandomFunction { fn.weight = &weight @@ -559,6 +571,9 @@ func (fn *RandomFunction) GetWeight() *float64 { // Source returns the serializable JSON data of this score function. func (fn *RandomFunction) Source() (interface{}, error) { source := make(map[string]interface{}) + if fn.field != "" { + source["field"] = fn.field + } if fn.seed != nil { source["seed"] = fn.seed } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_fuzzy.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_fuzzy.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_fuzzy.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_fuzzy.go index b98f9c7f0c..dbb7357dea 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_fuzzy.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_fuzzy.go @@ -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/5.2/query-dsl-fuzzy-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-fuzzy-query.html type FuzzyQuery struct { name string value interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_bounding_box.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_geo_bounding_box.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_bounding_box.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_geo_bounding_box.go index e53340e644..9caa5ffa67 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_bounding_box.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_geo_bounding_box.go @@ -10,7 +10,7 @@ import "errors" // a bounding box. // // For more details, see: -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-geo-bounding-box-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-geo-bounding-box-query.html type GeoBoundingBoxQuery struct { name string top *float64 diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_distance.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_geo_distance.go similarity index 89% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_distance.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_geo_distance.go index a10bd5e3c3..d96817cd5a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_distance.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_geo_distance.go @@ -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/5.2/query-dsl-geo-distance-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-geo-distance-query.html type GeoDistanceQuery struct { name string distance string @@ -16,7 +16,6 @@ type GeoDistanceQuery struct { lon float64 geohash string distanceType string - optimizeBbox string queryName string } @@ -62,11 +61,6 @@ func (q *GeoDistanceQuery) DistanceType(distanceType string) *GeoDistanceQuery { return q } -func (q *GeoDistanceQuery) OptimizeBbox(optimizeBbox string) *GeoDistanceQuery { - q.optimizeBbox = optimizeBbox - return q -} - func (q *GeoDistanceQuery) QueryName(queryName string) *GeoDistanceQuery { q.queryName = queryName return q @@ -103,9 +97,6 @@ func (q *GeoDistanceQuery) Source() (interface{}, error) { if q.distanceType != "" { params["distance_type"] = q.distanceType } - if q.optimizeBbox != "" { - params["optimize_bbox"] = q.optimizeBbox - } if q.queryName != "" { params["_name"] = q.queryName } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_geo_polygon.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_geo_polygon.go index 1faaf24e02..e1e98da0f1 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_geo_polygon.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_geo_polygon.go @@ -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/5.2/query-dsl-geo-polygon-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-geo-polygon-query.html type GeoPolygonQuery struct { name string points []*GeoPoint diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_has_child.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_has_child.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_has_child.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_has_child.go index 27cea7ad61..873949927a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_has_child.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_has_child.go @@ -8,7 +8,7 @@ package elastic // in parent documents that have child docs matching the query. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-has-child-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-has-child-query.html type HasChildQuery struct { query Query childType string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_has_parent.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_has_parent.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_has_parent.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_has_parent.go index aa46b34c91..044c20cd5b 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_has_parent.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_has_parent.go @@ -11,14 +11,14 @@ package elastic // same manner as has_child query. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-has-parent-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-has-parent-query.html type HasParentQuery struct { - query Query - parentType string - boost *float64 - score *bool - queryName string - innerHit *InnerHit + query Query + parentType string + boost *float64 + score *bool + queryName string + innerHit *InnerHit ignoreUnmapped *bool } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_ids.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_ids.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_ids.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_ids.go index 42cc656721..01150f80e4 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_ids.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_ids.go @@ -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/5.2/query-dsl-ids-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-ids-query.html type IdsQuery struct { types []string values []string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_match.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_match.go index 1f2f16f69d..1026f426da 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_match.go @@ -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/5.2/query-dsl-match-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-query.html type MatchQuery struct { name string text interface{} @@ -176,7 +176,7 @@ func (q *MatchQuery) Source() (interface{}, error) { query["zero_terms_query"] = q.zeroTermsQuery } if q.cutoffFrequency != nil { - query["cutoff_frequency"] = q.cutoffFrequency + query["cutoff_frequency"] = *q.cutoffFrequency } if q.boost != nil { query["boost"] = *q.boost diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match_all.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_match_all.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_match_all.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_match_all.go index 5551eea302..73b3cb5e8e 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match_all.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_match_all.go @@ -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/5.2/query-dsl-match-all-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-all-query.html type MatchAllQuery struct { boost *float64 queryName string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match_none.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_match_none.go similarity index 93% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_match_none.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_match_none.go index 06d036e710..d52c03bf33 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match_none.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_match_none.go @@ -8,7 +8,7 @@ package elastic // MatchAllQuery. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-match-all-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-all-query.html type MatchNoneQuery struct { queryName string } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match_phrase.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_match_phrase.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_match_phrase.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_match_phrase.go index fdded2e766..43a6215df4 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match_phrase.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_match_phrase.go @@ -8,7 +8,7 @@ package elastic // the analyzed text. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-match-query-phrase.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-query-phrase.html type MatchPhraseQuery struct { name string value interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match_phrase_prefix.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_match_phrase_prefix.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_match_phrase_prefix.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_match_phrase_prefix.go index 1eeba8af52..3590a7ae50 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match_phrase_prefix.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_match_phrase_prefix.go @@ -8,7 +8,7 @@ package elastic // prefix matches on the last term in the text. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-match-query-phrase-prefix.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-query-phrase-prefix.html type MatchPhrasePrefixQuery struct { name string value interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_more_like_this.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_more_like_this.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_more_like_this.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_more_like_this.go index 40c2d575dd..7affdcdfa3 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_more_like_this.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_more_like_this.go @@ -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/5.2/query-dsl-mlt-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-mlt-query.html type MoreLikeThisQuery struct { fields []string docs []*MoreLikeThisQueryItem @@ -25,8 +25,8 @@ type MoreLikeThisQuery struct { stopWords []string minDocFreq *int maxDocFreq *int - minWordLen *int - maxWordLen *int + minWordLength *int + maxWordLength *int boostTerms *float64 boost *float64 analyzer string @@ -147,15 +147,15 @@ func (q *MoreLikeThisQuery) MaxDocFreq(maxDocFreq int) *MoreLikeThisQuery { // MinWordLength sets the minimum word length below which words will be // ignored. It defaults to 0. -func (q *MoreLikeThisQuery) MinWordLen(minWordLen int) *MoreLikeThisQuery { - q.minWordLen = &minWordLen +func (q *MoreLikeThisQuery) MinWordLength(minWordLength int) *MoreLikeThisQuery { + q.minWordLength = &minWordLength return q } -// MaxWordLen sets the maximum word length above which words will be ignored. +// MaxWordLength sets the maximum word length above which words will be ignored. // Defaults to unbounded (0). -func (q *MoreLikeThisQuery) MaxWordLen(maxWordLen int) *MoreLikeThisQuery { - q.maxWordLen = &maxWordLen +func (q *MoreLikeThisQuery) MaxWordLength(maxWordLength int) *MoreLikeThisQuery { + q.maxWordLength = &maxWordLength return q } @@ -254,11 +254,11 @@ func (q *MoreLikeThisQuery) Source() (interface{}, error) { if q.maxDocFreq != nil { params["max_doc_freq"] = *q.maxDocFreq } - if q.minWordLen != nil { - params["min_word_len"] = *q.minWordLen + if q.minWordLength != nil { + params["min_word_length"] = *q.minWordLength } - if q.maxWordLen != nil { - params["max_word_len"] = *q.maxWordLen + if q.maxWordLength != nil { + params["max_word_length"] = *q.maxWordLength } if q.boostTerms != nil { params["boost_terms"] = *q.boostTerms diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_multi_match.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_multi_match.go similarity index 99% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_multi_match.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_multi_match.go index 9a149fed55..ccbb51139e 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_multi_match.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_multi_match.go @@ -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/5.2/query-dsl-multi-match-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-multi-match-query.html type MultiMatchQuery struct { text interface{} fields []string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_nested.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_nested.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_nested.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_nested.go index a95cc2b803..9a07f97e60 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_nested.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_nested.go @@ -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/5.2/query-dsl-nested-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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.v6/search_queries_parent_id.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_parent_id.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_parent_id.go index bd11cc2914..f3603076a0 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_parent_id.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_parent_id.go @@ -8,7 +8,7 @@ package elastic // 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 +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-parent-id-query.html type ParentIdQuery struct { typ string id string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_percolator.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_percolator.go similarity index 64% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_percolator.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_percolator.go index 16f7611ed3..da92bfbcf6 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_percolator.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_percolator.go @@ -9,11 +9,12 @@ 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 +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-percolate-query.html type PercolatorQuery struct { field string - documentType string - document interface{} + name string + documentType string // deprecated + documents []interface{} indexedDocumentIndex string indexedDocumentType string indexedDocumentId string @@ -32,13 +33,21 @@ func (q *PercolatorQuery) Field(field string) *PercolatorQuery { return q } +// Name used for identification purposes in "_percolator_document_slot" response +// field when multiple percolate queries have been specified in the main query. +func (q *PercolatorQuery) Name(name string) *PercolatorQuery { + q.name = name + return q +} + +// Deprecated: DocumentType is deprecated as of 6.0. func (q *PercolatorQuery) DocumentType(typ string) *PercolatorQuery { q.documentType = typ return q } -func (q *PercolatorQuery) Document(doc interface{}) *PercolatorQuery { - q.document = doc +func (q *PercolatorQuery) Document(docs ...interface{}) *PercolatorQuery { + q.documents = append(q.documents, docs...) return q } @@ -77,12 +86,6 @@ 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" : { ... } @@ -91,25 +94,38 @@ func (q *PercolatorQuery) Source() (interface{}, error) { 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 q.documentType != "" { + params["document_type"] = q.documentType } - if len(q.indexedDocumentType) > 0 { - params["type"] = q.indexedDocumentType + if q.name != "" { + params["name"] = q.name } - if len(q.indexedDocumentId) > 0 { - params["id"] = q.indexedDocumentId + + switch len(q.documents) { + case 0: + case 1: + params["document"] = q.documents[0] + default: + params["documents"] = q.documents } - if len(q.indexedDocumentRouting) > 0 { - params["routing"] = q.indexedDocumentRouting + + if s := q.indexedDocumentIndex; s != "" { + params["index"] = s } - if len(q.indexedDocumentPreference) > 0 { - params["preference"] = q.indexedDocumentPreference + if s := q.indexedDocumentType; s != "" { + params["type"] = s } - if q.indexedDocumentVersion != nil { - params["version"] = *q.indexedDocumentVersion + if s := q.indexedDocumentId; s != "" { + params["id"] = s + } + if s := q.indexedDocumentRouting; s != "" { + params["routing"] = s + } + if s := q.indexedDocumentPreference; s != "" { + params["preference"] = s + } + if v := q.indexedDocumentVersion; v != nil { + params["version"] = *v } return source, nil } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_prefix.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_prefix.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_prefix.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_prefix.go index 0d5077553f..67e7cc6509 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_prefix.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_prefix.go @@ -8,7 +8,7 @@ package elastic // with a specified prefix (not analyzed). // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-prefix-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-prefix-query.html type PrefixQuery struct { name string prefix string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_query_string.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_query_string.go similarity index 77% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_query_string.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_query_string.go index fa13936112..faa8fd5259 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_query_string.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_query_string.go @@ -11,39 +11,36 @@ import ( // QueryStringQuery uses the query parser in order to parse its content. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-query-string-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-query-string-query.html type QueryStringQuery struct { - queryString string - defaultField string - defaultOperator string - analyzer string - quoteAnalyzer string - quoteFieldSuffix string - autoGeneratePhraseQueries *bool - allowLeadingWildcard *bool - lowercaseExpandedTerms *bool - enablePositionIncrements *bool - analyzeWildcard *bool - locale string // Deprecated: Decision is now made by the analyzer. - boost *float64 - fuzziness string - fuzzyPrefixLength *int - fuzzyMaxExpansions *int - fuzzyRewrite string - phraseSlop *int - fields []string - fieldBoosts map[string]*float64 - useDisMax *bool - tieBreaker *float64 - rewrite string - minimumShouldMatch string - lenient *bool - queryName string - timeZone string - maxDeterminizedStates *int - escape *bool - splitOnWhitespace *bool - useAllFields *bool + queryString string + defaultField string + defaultOperator string + analyzer string + quoteAnalyzer string + quoteFieldSuffix string + allowLeadingWildcard *bool + lowercaseExpandedTerms *bool // Deprecated: Decision is now made by the analyzer + enablePositionIncrements *bool + analyzeWildcard *bool + locale string // Deprecated: Decision is now made by the analyzer + boost *float64 + fuzziness string + fuzzyPrefixLength *int + fuzzyMaxExpansions *int + fuzzyRewrite string + phraseSlop *int + fields []string + fieldBoosts map[string]*float64 + tieBreaker *float64 + rewrite string + minimumShouldMatch string + lenient *bool + queryName string + timeZone string + maxDeterminizedStates *int + escape *bool + typ string } // NewQueryStringQuery creates and initializes a new QueryStringQuery. @@ -69,11 +66,10 @@ func (q *QueryStringQuery) Field(field string) *QueryStringQuery { return q } -// AllFields tells the query string query to use all fields explicitly, -// even if _all is enabled. If the "default_field" parameter or "fields" -// are specified, they will be ignored. -func (q *QueryStringQuery) AllFields(useAllFields bool) *QueryStringQuery { - q.useAllFields = &useAllFields +// Type sets how multiple fields should be combined to build textual part queries, +// e.g. "best_fields". +func (q *QueryStringQuery) Type(typ string) *QueryStringQuery { + q.typ = typ return q } @@ -84,14 +80,6 @@ func (q *QueryStringQuery) FieldWithBoost(field string, boost float64) *QueryStr return q } -// UseDisMax specifies whether to combine queries using dis max or boolean -// query when more zhan one field is used with the query string. Defaults -// to dismax (true). -func (q *QueryStringQuery) UseDisMax(useDisMax bool) *QueryStringQuery { - q.useDisMax = &useDisMax - return q -} - // TieBreaker is used when more than one field is used with the query string, // and combined queries are using dismax. func (q *QueryStringQuery) TieBreaker(tieBreaker float64) *QueryStringQuery { @@ -129,15 +117,6 @@ func (q *QueryStringQuery) QuoteAnalyzer(quoteAnalyzer string) *QueryStringQuery return q } -// AutoGeneratePhraseQueries indicates whether or not phrase queries will -// be automatically generated when the analyzer returns more then one term -// from whitespace delimited text. Set to false if phrase queries should only -// be generated when surrounded by double quotes. -func (q *QueryStringQuery) AutoGeneratePhraseQueries(autoGeneratePhraseQueries bool) *QueryStringQuery { - q.autoGeneratePhraseQueries = &autoGeneratePhraseQueries - return q -} - // MaxDeterminizedState protects against too-difficult regular expression queries. func (q *QueryStringQuery) MaxDeterminizedState(maxDeterminizedStates int) *QueryStringQuery { q.maxDeterminizedStates = &maxDeterminizedStates @@ -153,6 +132,8 @@ func (q *QueryStringQuery) AllowLeadingWildcard(allowLeadingWildcard bool) *Quer // LowercaseExpandedTerms indicates whether terms of wildcard, prefix, fuzzy // and range queries are automatically lower-cased or not. Default is true. +// +// Deprecated: Decision is now made by the analyzer. func (q *QueryStringQuery) LowercaseExpandedTerms(lowercaseExpandedTerms bool) *QueryStringQuery { q.lowercaseExpandedTerms = &lowercaseExpandedTerms return q @@ -264,13 +245,6 @@ func (q *QueryStringQuery) Escape(escape bool) *QueryStringQuery { return q } -// SplitOnWhitespace indicates whether query text should be split on whitespace -// prior to analysis. -func (q *QueryStringQuery) SplitOnWhitespace(splitOnWhitespace bool) *QueryStringQuery { - q.splitOnWhitespace = &splitOnWhitespace - return q -} - // Source returns JSON for the query. func (q *QueryStringQuery) Source() (interface{}, error) { source := make(map[string]interface{}) @@ -302,9 +276,6 @@ func (q *QueryStringQuery) Source() (interface{}, error) { if q.tieBreaker != nil { query["tie_breaker"] = *q.tieBreaker } - if q.useDisMax != nil { - query["use_dis_max"] = *q.useDisMax - } if q.defaultOperator != "" { query["default_operator"] = q.defaultOperator } @@ -314,9 +285,6 @@ func (q *QueryStringQuery) Source() (interface{}, error) { if q.quoteAnalyzer != "" { query["quote_analyzer"] = q.quoteAnalyzer } - if q.autoGeneratePhraseQueries != nil { - query["auto_generate_phrase_queries"] = *q.autoGeneratePhraseQueries - } if q.maxDeterminizedStates != nil { query["max_determinized_states"] = *q.maxDeterminizedStates } @@ -374,11 +342,8 @@ func (q *QueryStringQuery) Source() (interface{}, error) { if q.escape != nil { query["escape"] = *q.escape } - if q.splitOnWhitespace != nil { - query["split_on_whitespace"] = *q.splitOnWhitespace - } - if q.useAllFields != nil { - query["all_fields"] = *q.useAllFields + if q.typ != "" { + query["type"] = q.typ } return source, nil diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_range.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_range.go similarity index 98% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_range.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_range.go index da7b5f965c..5bfb2a6f99 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_range.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_range.go @@ -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/5.2/query-dsl-range-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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.v6/search_queries_raw_string.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_raw_string.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_raw_string.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_regexp.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_regexp.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_regexp.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_regexp.go index 636e4baf9a..c67018f03a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_regexp.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_regexp.go @@ -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/5.2/query-dsl-regexp-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-regexp-query.html type RegexpQuery struct { name string regexp string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_script.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_script.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_script.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_script.go index 664555b3e1..6ce1de6fbd 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_script.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_script.go @@ -9,7 +9,7 @@ import "errors" // ScriptQuery allows to define scripts as filters. // // For details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-script-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-script-query.html type ScriptQuery struct { script *Script queryName string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_simple_query_string.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_simple_query_string.go similarity index 64% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_simple_query_string.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_simple_query_string.go index 4a1d0e5f3a..c222bfc65d 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_simple_query_string.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_simple_query_string.go @@ -15,30 +15,36 @@ import ( // and discards invalid parts of the query. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-simple-query-string-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-simple-query-string-query.html type SimpleQueryStringQuery struct { - queryText string - analyzer string - quoteFieldSuffix string - operator string - fields []string - fieldBoosts map[string]*float64 - minimumShouldMatch string - flags string - boost *float64 - lowercaseExpandedTerms *bool - lenient *bool - analyzeWildcard *bool - locale string - queryName string + queryText string + analyzer string + quoteFieldSuffix string + defaultOperator string + fields []string + fieldBoosts map[string]*float64 + minimumShouldMatch string + flags string + boost *float64 + lowercaseExpandedTerms *bool // deprecated + lenient *bool + analyzeWildcard *bool + locale string // deprecated + queryName string + autoGenerateSynonymsPhraseQuery *bool + fuzzyPrefixLength int + fuzzyMaxExpansions int + fuzzyTranspositions *bool } // NewSimpleQueryStringQuery creates and initializes a new SimpleQueryStringQuery. func NewSimpleQueryStringQuery(text string) *SimpleQueryStringQuery { return &SimpleQueryStringQuery{ - queryText: text, - fields: make([]string, 0), - fieldBoosts: make(map[string]*float64), + queryText: text, + fields: make([]string, 0), + fieldBoosts: make(map[string]*float64), + fuzzyPrefixLength: -1, + fuzzyMaxExpansions: -1, } } @@ -61,6 +67,13 @@ func (q *SimpleQueryStringQuery) Boost(boost float64) *SimpleQueryStringQuery { return q } +// QuoteFieldSuffix is an optional field name suffix to automatically +// try and add to the field searched when using quoted text. +func (q *SimpleQueryStringQuery) QuoteFieldSuffix(quoteFieldSuffix string) *SimpleQueryStringQuery { + q.quoteFieldSuffix = quoteFieldSuffix + return q +} + // QueryName sets the query name for the filter that can be used when // searching for matched_filters per hit. func (q *SimpleQueryStringQuery) QueryName(queryName string) *SimpleQueryStringQuery { @@ -74,16 +87,9 @@ func (q *SimpleQueryStringQuery) Analyzer(analyzer string) *SimpleQueryStringQue return q } -// QuoteFieldSuffix is an optional field name suffix to automatically -// try and add to the field searched when using quoted text. -func (q *SimpleQueryStringQuery) QuoteFieldSuffix(quoteFieldSuffix string) *SimpleQueryStringQuery { - q.quoteFieldSuffix = quoteFieldSuffix - return q -} - // DefaultOperator specifies the default operator for the query. func (q *SimpleQueryStringQuery) DefaultOperator(defaultOperator string) *SimpleQueryStringQuery { - q.operator = defaultOperator + q.defaultOperator = defaultOperator return q } @@ -95,11 +101,16 @@ func (q *SimpleQueryStringQuery) Flags(flags string) *SimpleQueryStringQuery { // LowercaseExpandedTerms indicates whether terms of wildcard, prefix, fuzzy // and range queries are automatically lower-cased or not. Default is true. +// +// Deprecated: Decision is now made by the analyzer. func (q *SimpleQueryStringQuery) LowercaseExpandedTerms(lowercaseExpandedTerms bool) *SimpleQueryStringQuery { q.lowercaseExpandedTerms = &lowercaseExpandedTerms return q } +// Locale to be used in the query. +// +// Deprecated: Decision is now made by the analyzer. func (q *SimpleQueryStringQuery) Locale(locale string) *SimpleQueryStringQuery { q.locale = locale return q @@ -119,11 +130,38 @@ func (q *SimpleQueryStringQuery) AnalyzeWildcard(analyzeWildcard bool) *SimpleQu return q } +// MinimumShouldMatch specifies the minimumShouldMatch to apply to the +// resulting query should that be a Boolean query. func (q *SimpleQueryStringQuery) MinimumShouldMatch(minimumShouldMatch string) *SimpleQueryStringQuery { q.minimumShouldMatch = minimumShouldMatch return q } +// AutoGenerateSynonymsPhraseQuery indicates whether phrase queries should be +// automatically generated for multi terms synonyms. Defaults to true. +func (q *SimpleQueryStringQuery) AutoGenerateSynonymsPhraseQuery(enable bool) *SimpleQueryStringQuery { + q.autoGenerateSynonymsPhraseQuery = &enable + return q +} + +// FuzzyPrefixLength defines the prefix length in fuzzy queries. +func (q *SimpleQueryStringQuery) FuzzyPrefixLength(fuzzyPrefixLength int) *SimpleQueryStringQuery { + q.fuzzyPrefixLength = fuzzyPrefixLength + return q +} + +// FuzzyMaxExpansions defines the number of terms fuzzy queries will expand to. +func (q *SimpleQueryStringQuery) FuzzyMaxExpansions(fuzzyMaxExpansions int) *SimpleQueryStringQuery { + q.fuzzyMaxExpansions = fuzzyMaxExpansions + return q +} + +// FuzzyTranspositions defines whether to use transpositions in fuzzy queries. +func (q *SimpleQueryStringQuery) FuzzyTranspositions(fuzzyTranspositions bool) *SimpleQueryStringQuery { + q.fuzzyTranspositions = &fuzzyTranspositions + return q +} + // Source returns JSON for the query. func (q *SimpleQueryStringQuery) Source() (interface{}, error) { // { @@ -164,8 +202,8 @@ func (q *SimpleQueryStringQuery) Source() (interface{}, error) { if q.analyzer != "" { query["analyzer"] = q.analyzer } - if q.operator != "" { - query["default_operator"] = strings.ToLower(q.operator) + if q.defaultOperator != "" { + query["default_operator"] = strings.ToLower(q.defaultOperator) } if q.lowercaseExpandedTerms != nil { query["lowercase_expanded_terms"] = *q.lowercaseExpandedTerms @@ -191,6 +229,18 @@ func (q *SimpleQueryStringQuery) Source() (interface{}, error) { if q.boost != nil { query["boost"] = *q.boost } + if v := q.autoGenerateSynonymsPhraseQuery; v != nil { + query["auto_generate_synonyms_phrase_query"] = *v + } + if v := q.fuzzyPrefixLength; v != -1 { + query["fuzzy_prefix_length"] = v + } + if v := q.fuzzyMaxExpansions; v != -1 { + query["fuzzy_max_expansions"] = v + } + if v := q.fuzzyTranspositions; v != nil { + query["fuzzy_transpositions"] = *v + } return source, nil } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_slice.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_slice.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_slice.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_slice.go index 0ebf880090..3361fcc3e3 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_slice.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_slice.go @@ -6,7 +6,7 @@ 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 +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-scroll.html#sliced-scroll // for details. type SliceQuery struct { field string diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_term.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_term.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_term.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_term.go index 051f6dee3e..d3bf3f5ca2 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_term.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_term.go @@ -8,7 +8,7 @@ package elastic // in the inverted index. // // For details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-term-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-term-query.html type TermQuery struct { name string value interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_terms.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_terms.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_terms.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_terms.go index 794c1f31cb..b04e209f0a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_terms.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_terms.go @@ -8,7 +8,7 @@ package elastic // of the provided terms (not analyzed). // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-terms-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-terms-query.html type TermsQuery struct { name string values []interface{} diff --git a/vendor/gopkg.in/olivere/elastic.v6/search_queries_terms_set.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_terms_set.go new file mode 100644 index 0000000000..9b32d68774 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_terms_set.go @@ -0,0 +1,97 @@ +// 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 + +// TermsSetQuery returns any documents that match with at least +// one or more of the provided terms. The terms are not analyzed +// and thus must match exactly. The number of terms that must +// match varies per document and is either controlled by a +// minimum should match field or computed per document in a +// minimum should match script. +// +// For more details, see +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-terms-set-query.html +type TermsSetQuery struct { + name string + values []interface{} + minimumShouldMatchField string + minimumShouldMatchScript *Script + queryName string + boost *float64 +} + +// NewTermsSetQuery creates and initializes a new TermsSetQuery. +func NewTermsSetQuery(name string, values ...interface{}) *TermsSetQuery { + q := &TermsSetQuery{ + name: name, + values: make([]interface{}, 0), + } + if len(values) > 0 { + q.values = append(q.values, values...) + } + return q +} + +// MinimumShouldMatchField specifies the field to match. +func (q *TermsSetQuery) MinimumShouldMatchField(minimumShouldMatchField string) *TermsSetQuery { + q.minimumShouldMatchField = minimumShouldMatchField + return q +} + +// MinimumShouldMatchScript specifies the script to match. +func (q *TermsSetQuery) MinimumShouldMatchScript(minimumShouldMatchScript *Script) *TermsSetQuery { + q.minimumShouldMatchScript = minimumShouldMatchScript + return q +} + +// Boost sets the boost for this query. +func (q *TermsSetQuery) Boost(boost float64) *TermsSetQuery { + q.boost = &boost + return q +} + +// QueryName sets the query name for the filter that can be used +// when searching for matched_filters per hit +func (q *TermsSetQuery) QueryName(queryName string) *TermsSetQuery { + q.queryName = queryName + return q +} + +// Source creates the query source for the term query. +func (q *TermsSetQuery) Source() (interface{}, error) { + // {"terms_set":{"codes":{"terms":["abc","def"],"minimum_should_match_field":"required_matches"}}} + source := make(map[string]interface{}) + inner := make(map[string]interface{}) + params := make(map[string]interface{}) + inner[q.name] = params + source["terms_set"] = inner + + // terms + params["terms"] = q.values + + // minimum_should_match_field + if match := q.minimumShouldMatchField; match != "" { + params["minimum_should_match_field"] = match + } + + // minimum_should_match_script + if match := q.minimumShouldMatchScript; match != nil { + src, err := match.Source() + if err != nil { + return nil, err + } + params["minimum_should_match_script"] = src + } + + // Common parameters for all queries + if q.boost != nil { + params["boost"] = *q.boost + } + if q.queryName != "" { + params["_name"] = q.queryName + } + + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_type.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_type.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_type.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_type.go index 70ace4541a..8697e99d21 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_type.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_type.go @@ -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/5.2/query-dsl-type-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-type-query.html type TypeQuery struct { typ string } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_wildcard.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_wildcard.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/search_queries_wildcard.go rename to vendor/gopkg.in/olivere/elastic.v6/search_queries_wildcard.go index 35f481542f..316f338577 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_wildcard.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_wildcard.go @@ -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/5.2/query-dsl-wildcard-query.html +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-wildcard-query.html type WildcardQuery struct { name string wildcard string diff --git a/vendor/gopkg.in/olivere/elastic.v6/search_queries_wrapper.go b/vendor/gopkg.in/olivere/elastic.v6/search_queries_wrapper.go new file mode 100644 index 0000000000..495d911224 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_queries_wrapper.go @@ -0,0 +1,28 @@ +// 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 + +// WrapperQuery accepts any other query as base64 encoded string. +// +// For details, see +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-wrapper-query.html. +type WrapperQuery struct { + source string +} + +// NewWrapperQuery creates and initializes a new WrapperQuery. +func NewWrapperQuery(source string) *WrapperQuery { + return &WrapperQuery{source: source} +} + +// Source returns JSON for the query. +func (q *WrapperQuery) Source() (interface{}, error) { + // {"wrapper":{"query":"..."}} + source := make(map[string]interface{}) + tq := make(map[string]interface{}) + source["wrapper"] = tq + tq["query"] = q.source + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/search_request.go b/vendor/gopkg.in/olivere/elastic.v6/search_request.go new file mode 100644 index 0000000000..16d1af716f --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/search_request.go @@ -0,0 +1,583 @@ +// 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" + "strings" +) + +// SearchRequest combines a search request and its +// query details (see SearchSource). +// It is used in combination with MultiSearch. +type SearchRequest struct { + searchType string + indices []string + types []string + routing *string + preference *string + requestCache *bool + allowPartialSearchResults *bool + ignoreUnavailable *bool + allowNoIndices *bool + expandWildcards string + scroll string + source interface{} + searchSource *SearchSource + batchedReduceSize *int + maxConcurrentShardRequests *int + preFilterShardSize *int +} + +// NewSearchRequest creates a new search request. +func NewSearchRequest() *SearchRequest { + return &SearchRequest{ + searchSource: NewSearchSource(), + } +} + +// SearchType must be one of "dfs_query_then_fetch", "dfs_query_and_fetch", +// "query_then_fetch", or "query_and_fetch". +func (r *SearchRequest) SearchType(searchType string) *SearchRequest { + r.searchType = searchType + return r +} + +// SearchTypeDfsQueryThenFetch sets search type to "dfs_query_then_fetch". +func (r *SearchRequest) SearchTypeDfsQueryThenFetch() *SearchRequest { + return r.SearchType("dfs_query_then_fetch") +} + +// SearchTypeQueryThenFetch sets search type to "query_then_fetch". +func (r *SearchRequest) SearchTypeQueryThenFetch() *SearchRequest { + return r.SearchType("query_then_fetch") +} + +// Index specifies the indices to use in the request. +func (r *SearchRequest) Index(indices ...string) *SearchRequest { + r.indices = append(r.indices, indices...) + return r +} + +// HasIndices returns true if there are indices used, false otherwise. +func (r *SearchRequest) HasIndices() bool { + return len(r.indices) > 0 +} + +// Type specifies one or more types to be used. +func (r *SearchRequest) Type(types ...string) *SearchRequest { + r.types = append(r.types, types...) + return r +} + +// Routing specifies the routing parameter. It is a comma-separated list. +func (r *SearchRequest) Routing(routing string) *SearchRequest { + r.routing = &routing + return r +} + +// Routings to be used in the request. +func (r *SearchRequest) Routings(routings ...string) *SearchRequest { + if routings != nil { + routings := strings.Join(routings, ",") + r.routing = &routings + } else { + r.routing = nil + } + return r +} + +// Preference to execute the search. Defaults to randomize across shards. +// Can be set to "_local" to prefer local shards, "_primary" to execute +// only on primary shards, or a custom value, which guarantees that the +// same order will be used across different requests. +func (r *SearchRequest) Preference(preference string) *SearchRequest { + r.preference = &preference + return r +} + +// RequestCache specifies if this request should use the request cache +// or not, assuming that it can. By default, will default to the index +// level setting if request cache is enabled or not. +func (r *SearchRequest) RequestCache(requestCache bool) *SearchRequest { + r.requestCache = &requestCache + 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 +} + +// Scroll, if set, will enable scrolling of the search request. +// Pass a timeout value, e.g. "2m" or "30s" as a value. +func (r *SearchRequest) Scroll(scroll string) *SearchRequest { + r.scroll = scroll + return r +} + +// SearchSource allows passing your own SearchSource, overriding +// all values set on the request (except Source). +func (r *SearchRequest) SearchSource(searchSource *SearchSource) *SearchRequest { + if searchSource == nil { + r.searchSource = NewSearchSource() + return r + } + r.searchSource = searchSource + return r +} + +// Source allows passing your own request body. It will have preference over +// all other properties set on the request. +func (r *SearchRequest) Source(source interface{}) *SearchRequest { + r.source = source + return r +} + +// Timeout value for the request, e.g. "30s" or "2m". +func (r *SearchRequest) Timeout(timeout string) *SearchRequest { + r.searchSource = r.searchSource.Timeout(timeout) + return r +} + +// TerminateAfter, when set, specifies an optional document count, +// upon collecting which the search query will terminate early. +func (r *SearchRequest) TerminateAfter(docs int) *SearchRequest { + r.searchSource = r.searchSource.TerminateAfter(docs) + return r +} + +// Query for the search. +func (r *SearchRequest) Query(query Query) *SearchRequest { + r.searchSource = r.searchSource.Query(query) + return r +} + +// PostFilter is a filter that will be executed after the query +// has been executed and only has affect on the search hits +// (not aggregations). This filter is always executed as last +// filtering mechanism. +func (r *SearchRequest) PostFilter(filter Query) *SearchRequest { + r.searchSource = r.searchSource.PostFilter(filter) + return r +} + +// MinScore below which documents are filtered out. +func (r *SearchRequest) MinScore(minScore float64) *SearchRequest { + r.searchSource = r.searchSource.MinScore(minScore) + return r +} + +// From index to start search from (default is 0). +func (r *SearchRequest) From(from int) *SearchRequest { + r.searchSource = r.searchSource.From(from) + return r +} + +// Size is the number of search hits to return (default is 10). +func (r *SearchRequest) Size(size int) *SearchRequest { + r.searchSource = r.searchSource.Size(size) + return r +} + +// Explain indicates whether to return an explanation for each hit. +func (r *SearchRequest) Explain(explain bool) *SearchRequest { + r.searchSource = r.searchSource.Explain(explain) + return r +} + +// Version indicates whether each hit should be returned with +// its version. +func (r *SearchRequest) Version(version bool) *SearchRequest { + r.searchSource = r.searchSource.Version(version) + return r +} + +// IndexBoost sets a boost a specific index will receive when +// the query is executed against it. +func (r *SearchRequest) IndexBoost(index string, boost float64) *SearchRequest { + r.searchSource = r.searchSource.IndexBoost(index, boost) + return r +} + +// Stats groups that this request will be aggregated under. +func (r *SearchRequest) Stats(statsGroup ...string) *SearchRequest { + r.searchSource = r.searchSource.Stats(statsGroup...) + return r +} + +// FetchSource indicates whether the response should contain the stored +// _source for every hit. +func (r *SearchRequest) FetchSource(fetchSource bool) *SearchRequest { + r.searchSource = r.searchSource.FetchSource(fetchSource) + return r +} + +// FetchSourceIncludeExclude specifies that _source should be returned +// with each hit, where "include" and "exclude" serve as a simple wildcard +// matcher that gets applied to its fields +// (e.g. include := []string{"obj1.*","obj2.*"}, exclude := []string{"description.*"}). +func (r *SearchRequest) FetchSourceIncludeExclude(include, exclude []string) *SearchRequest { + r.searchSource = r.searchSource.FetchSourceIncludeExclude(include, exclude) + return r +} + +// FetchSourceContext indicates how the _source should be fetched. +func (r *SearchRequest) FetchSourceContext(fsc *FetchSourceContext) *SearchRequest { + r.searchSource = r.searchSource.FetchSourceContext(fsc) + return r +} + +// DocValueField adds a docvalue based field to load and return. +// The field does not have to be stored, but it's recommended to use +// non analyzed or numeric fields. +func (r *SearchRequest) DocValueField(field string) *SearchRequest { + r.searchSource = r.searchSource.DocvalueField(field) + return r +} + +// DocValueFieldWithFormat adds a docvalue based field to load and return. +// The field does not have to be stored, but it's recommended to use +// non analyzed or numeric fields. +func (r *SearchRequest) DocValueFieldWithFormat(field DocvalueField) *SearchRequest { + r.searchSource = r.searchSource.DocvalueFieldWithFormat(field) + return r +} + +// DocValueFields adds one or more docvalue based field to load and return. +// The fields do not have to be stored, but it's recommended to use +// non analyzed or numeric fields. +func (r *SearchRequest) DocValueFields(fields ...string) *SearchRequest { + r.searchSource = r.searchSource.DocvalueFields(fields...) + return r +} + +// DocValueFieldsWithFormat adds one or more docvalue based field to load and return. +// The fields do not have to be stored, but it's recommended to use +// non analyzed or numeric fields. +func (r *SearchRequest) DocValueFieldsWithFormat(fields ...DocvalueField) *SearchRequest { + r.searchSource = r.searchSource.DocvalueFieldsWithFormat(fields...) + return r +} + +// StoredField adds a stored field to load and return +// (note, it must be stored) as part of the search request. +func (r *SearchRequest) StoredField(field string) *SearchRequest { + r.searchSource = r.searchSource.StoredField(field) + return r +} + +// NoStoredFields indicates that no fields should be loaded, +// resulting in only id and type to be returned per field. +func (r *SearchRequest) NoStoredFields() *SearchRequest { + r.searchSource = r.searchSource.NoStoredFields() + return r +} + +// StoredFields adds one or more stored field to load and return +// (note, they must be stored) as part of the search request. +func (r *SearchRequest) StoredFields(fields ...string) *SearchRequest { + r.searchSource = r.searchSource.StoredFields(fields...) + return r +} + +// ScriptField adds a script based field to load and return. +// The field does not have to be stored, but it's recommended +// to use non analyzed or numeric fields. +func (r *SearchRequest) ScriptField(field *ScriptField) *SearchRequest { + r.searchSource = r.searchSource.ScriptField(field) + return r +} + +// ScriptFields adds one or more script based field to load and return. +// The fields do not have to be stored, but it's recommended +// to use non analyzed or numeric fields. +func (r *SearchRequest) ScriptFields(fields ...*ScriptField) *SearchRequest { + r.searchSource = r.searchSource.ScriptFields(fields...) + return r +} + +// Sort adds a sort order. +func (r *SearchRequest) Sort(field string, ascending bool) *SearchRequest { + r.searchSource = r.searchSource.Sort(field, ascending) + return r +} + +// SortWithInfo adds a sort order. +func (r *SearchRequest) SortWithInfo(info SortInfo) *SearchRequest { + r.searchSource = r.searchSource.SortWithInfo(info) + return r +} + +// SortBy adds a sort order. +func (r *SearchRequest) SortBy(sorter ...Sorter) *SearchRequest { + r.searchSource = r.searchSource.SortBy(sorter...) + return r +} + +// SearchAfter sets the sort values that indicates which docs this +// request should "search after". +func (r *SearchRequest) SearchAfter(sortValues ...interface{}) *SearchRequest { + r.searchSource = r.searchSource.SearchAfter(sortValues...) + return r +} + +// 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/6.8/search-request-scroll.html#sliced-scroll +// for details. +func (r *SearchRequest) Slice(sliceQuery Query) *SearchRequest { + r.searchSource = r.searchSource.Slice(sliceQuery) + return r +} + +// TrackScores is applied when sorting and controls if scores will be +// tracked as well. Defaults to false. +func (r *SearchRequest) TrackScores(trackScores bool) *SearchRequest { + r.searchSource = r.searchSource.TrackScores(trackScores) + return r +} + +// TrackTotalHits indicates if the total hit count for the query should be tracked. +// Defaults to true. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/index-modules-index-sorting.html#early-terminate +// for details. +func (r *SearchRequest) TrackTotalHits(trackTotalHits bool) *SearchRequest { + r.searchSource = r.searchSource.TrackTotalHits(trackTotalHits) + return r +} + +// Aggregation adds an aggreation to perform as part of the search. +func (r *SearchRequest) Aggregation(name string, aggregation Aggregation) *SearchRequest { + r.searchSource = r.searchSource.Aggregation(name, aggregation) + return r +} + +// Highlight adds highlighting to the search. +func (r *SearchRequest) Highlight(highlight *Highlight) *SearchRequest { + r.searchSource = r.searchSource.Highlight(highlight) + return r +} + +// Suggester adds a suggester to the search. +func (r *SearchRequest) Suggester(suggester Suggester) *SearchRequest { + r.searchSource = r.searchSource.Suggester(suggester) + return r +} + +// Rescorer adds a rescorer to the search. +func (r *SearchRequest) Rescorer(rescore *Rescore) *SearchRequest { + r.searchSource = r.searchSource.Rescorer(rescore) + return r +} + +// ClearRescorers removes all rescorers from the search. +func (r *SearchRequest) ClearRescorers() *SearchRequest { + r.searchSource = r.searchSource.ClearRescorers() + return r +} + +// Profile specifies that this search source should activate the +// Profile API for queries made on it. +func (r *SearchRequest) Profile(profile bool) *SearchRequest { + r.searchSource = r.searchSource.Profile(profile) + return r +} + +// Collapse adds field collapsing. +func (r *SearchRequest) Collapse(collapse *CollapseBuilder) *SearchRequest { + r.searchSource = r.searchSource.Collapse(collapse) + return r +} + +// AllowPartialSearchResults indicates if this request should allow partial +// results. (If method is not called, will default to the cluster level +// setting). +func (r *SearchRequest) AllowPartialSearchResults(allow bool) *SearchRequest { + r.allowPartialSearchResults = &allow + return r +} + +// BatchedReduceSize specifies the number of shard results that should be +// reduced at once on the coordinating node. This value should be used +// as a protection mechanism to reduce the memory overhead per search request +// if the potential number of shards in the request can be large. +func (r *SearchRequest) BatchedReduceSize(size int) *SearchRequest { + r.batchedReduceSize = &size + return r +} + +// MaxConcurrentShardRequests sets the number of shard requests that should +// be executed concurrently. This value should be used as a protection +// mechanism to reduce the number of shard requests fired per high level +// search request. Searches that hit the entire cluster can be throttled +// with this number to reduce the cluster load. The default grows with +// the number of nodes in the cluster but is at most 256. +func (r *SearchRequest) MaxConcurrentShardRequests(size int) *SearchRequest { + r.maxConcurrentShardRequests = &size + return r +} + +// PreFilterShardSize sets a threshold that enforces a pre-filter roundtrip +// to pre-filter search shards based on query rewriting if the number of +// shards the search request expands to exceeds the threshold. +// This filter roundtrip can limit the number of shards significantly if for +// instance a shard can not match any documents based on it's rewrite +// method ie. if date filters are mandatory to match but the shard +// bounds and the query are disjoint. The default is 128. +func (r *SearchRequest) PreFilterShardSize(size int) *SearchRequest { + r.preFilterShardSize = &size + return r +} + +// header is used e.g. by MultiSearch to get information about the search header +// of one SearchRequest. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-multi-search.html +func (r *SearchRequest) header() interface{} { + h := make(map[string]interface{}) + if r.searchType != "" { + h["search_type"] = r.searchType + } + + switch len(r.indices) { + case 0: + case 1: + h["index"] = r.indices[0] + default: + h["indices"] = r.indices + } + + switch len(r.types) { + case 0: + case 1: + h["type"] = r.types[0] + default: + h["types"] = r.types + } + + 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"] = *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 v := r.allowPartialSearchResults; v != nil { + h["allow_partial_search_results"] = *v + } + if r.scroll != "" { + h["scroll"] = r.scroll + } + + return h +} + +// Body allows to access the search body of the request, as generated by the DSL. +// Notice that Body is read-only. You must not change the request body. +// +// Body is used e.g. by MultiSearch to get information about the search body +// of one SearchRequest. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-multi-search.html +func (r *SearchRequest) Body() (string, error) { + if r.source == nil { + // Default: No custom source specified + src, err := r.searchSource.Source() + if err != nil { + return "", err + } + body, err := json.Marshal(src) + if err != nil { + return "", err + } + return string(body), nil + } + switch t := r.source.(type) { + default: + body, err := json.Marshal(r.source) + if err != nil { + return "", err + } + return string(body), nil + case *SearchSource: + src, err := t.Source() + if err != nil { + return "", err + } + body, err := json.Marshal(src) + if err != nil { + return "", err + } + return string(body), nil + case json.RawMessage: + return string(t), nil + case *json.RawMessage: + return string(*t), nil + case string: + return t, nil + case *string: + if t != nil { + return *t, nil + } + return "{}", nil + } +} + +// source returns the search source. It is used by Reindex. +func (r *SearchRequest) sourceAsMap() (interface{}, error) { + if r.source == nil { + // Default: No custom source specified + return r.searchSource.Source() + } + switch t := r.source.(type) { + default: + body, err := json.Marshal(r.source) + if err != nil { + return "", err + } + return RawStringQuery(body), nil + case *SearchSource: + return t.Source() + case json.RawMessage: + return RawStringQuery(string(t)), nil + case *json.RawMessage: + return RawStringQuery(string(*t)), nil + case string: + return RawStringQuery(t), nil + case *string: + if t != nil { + return RawStringQuery(*t), nil + } + return RawStringQuery("{}"), nil + } +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_shards.go b/vendor/gopkg.in/olivere/elastic.v6/search_shards.go similarity index 74% rename from vendor/gopkg.in/olivere/elastic.v5/search_shards.go rename to vendor/gopkg.in/olivere/elastic.v6/search_shards.go index 7a29d0e40b..5ea0e776f8 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_shards.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_shards.go @@ -9,12 +9,13 @@ import ( "fmt" "net/url" "strings" + "time" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // SearchShardsService returns the indices and shards that a search request would be executed against. -// See https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search-shards.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-shards.html type SearchShardsService struct { client *Client pretty bool @@ -149,7 +150,11 @@ func (s *SearchShardsService) Do(ctx context.Context) (*SearchShardsResponse, er } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -164,17 +169,39 @@ func (s *SearchShardsService) Do(ctx context.Context) (*SearchShardsResponse, er // SearchShardsResponse is the response of SearchShardsService.Do. type SearchShardsResponse struct { - Nodes map[string]interface{} `json:"nodes"` - Indices map[string]interface{} `json:"indices"` - Shards [][]*SearchShardsResponseShardsInfo `json:"shards"` + Nodes map[string]interface{} `json:"nodes"` + Indices map[string]interface{} `json:"indices"` + Shards [][]*SearchShardsResponseShardsInfo `json:"shards"` } type SearchShardsResponseShardsInfo struct { - Index string `json:"index"` - Node string `json:"node"` - Primary bool `json:"primary"` - Shard uint `json:"shard"` - State string `json:"state"` - AllocationId interface{} `json:"allocation_id"` - RelocatingNode string `json:"relocating_node"` + Index string `json:"index"` + Node string `json:"node"` + Primary bool `json:"primary"` + Shard uint `json:"shard"` + State string `json:"state"` + AllocationId *AllocationId `json:"allocation_id,omitempty"` + RelocatingNode string `json:"relocating_node"` + ExpectedShardSizeInBytes int64 `json:"expected_shard_size_in_bytes,omitempty"` + RecoverySource *RecoverySource `json:"recovery_source,omitempty"` + UnassignedInfo *UnassignedInfo `json:"unassigned_info,omitempty"` +} + +type RecoverySource struct { + Type string `json:"type"` + // TODO add missing fields here based on the Type +} + +type AllocationId struct { + Id string `json:"id"` + RelocationId string `json:"relocation_id,omitempty"` +} + +type UnassignedInfo struct { + Reason string `json:"reason"` + At *time.Time `json:"at,omitempty"` + FailedAttempts int `json:"failed_attempts,omitempty"` + Delayed bool `json:"delayed"` + Details string `json:"details,omitempty"` + AllocationStatus string `json:"allocation_status"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_source.go b/vendor/gopkg.in/olivere/elastic.v6/search_source.go similarity index 86% rename from vendor/gopkg.in/olivere/elastic.v5/search_source.go rename to vendor/gopkg.in/olivere/elastic.v6/search_source.go index be63b5cd96..7475a35a08 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_source.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_source.go @@ -19,13 +19,14 @@ type SearchSource struct { explain *bool version *bool sorters []Sorter - trackScores bool + trackScores *bool + trackTotalHits *bool searchAfterSortValues []interface{} minScore *float64 timeout string terminateAfter *int storedFieldNames []string - docvalueFields []string + docvalueFields DocvalueFields scriptFields []*ScriptField fetchSourceContext *FetchSourceContext aggregations map[string]Aggregation @@ -39,6 +40,7 @@ type SearchSource struct { innerHits map[string]*InnerHit collapse *CollapseBuilder profile bool + // TODO extBuilders []SearchExtBuilder } // NewSearchSource initializes a new SearchSource. @@ -46,7 +48,6 @@ func NewSearchSource() *SearchSource { return &SearchSource{ from: -1, size: -1, - trackScores: false, aggregations: make(map[string]Aggregation), indexBoosts: make(map[string]float64), innerHits: make(map[string]*InnerHit), @@ -77,7 +78,7 @@ func (s *SearchSource) PostFilter(postFilter Query) *SearchSource { // 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 +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-scroll.html#sliced-scroll // for details. func (s *SearchSource) Slice(sliceQuery Query) *SearchSource { s.sliceQuery = sliceQuery @@ -161,14 +162,24 @@ func (s *SearchSource) hasSort() bool { // TrackScores is applied when sorting and controls if scores will be // tracked as well. Defaults to false. func (s *SearchSource) TrackScores(trackScores bool) *SearchSource { - s.trackScores = trackScores + s.trackScores = &trackScores + return s +} + +// TrackTotalHits indicates if the total hit count for the query should be tracked. +// Defaults to true. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/index-modules-index-sorting.html#early-terminate +// for details. +func (s *SearchSource) TrackTotalHits(trackTotalHits bool) *SearchSource { + s.trackTotalHits = &trackTotalHits 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 +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-search-after.html func (s *SearchSource) SearchAfter(sortValues ...interface{}) *SearchSource { s.searchAfterSortValues = append(s.searchAfterSortValues, sortValues...) return s @@ -243,6 +254,17 @@ func (s *SearchSource) FetchSourceContext(fetchSourceContext *FetchSourceContext return s } +// FetchSourceIncludeExclude specifies that _source should be returned +// with each hit, where "include" and "exclude" serve as a simple wildcard +// matcher that gets applied to its fields +// (e.g. include := []string{"obj1.*","obj2.*"}, exclude := []string{"description.*"}). +func (s *SearchSource) FetchSourceIncludeExclude(include, exclude []string) *SearchSource { + s.fetchSourceContext = NewFetchSourceContext(true). + Include(include...). + Exclude(exclude...) + return s +} + // NoStoredFields indicates that no fields should be loaded, resulting in only // id and type to be returned per field. func (s *SearchSource) NoStoredFields() *SearchSource { @@ -268,13 +290,29 @@ func (s *SearchSource) StoredFields(storedFieldNames ...string) *SearchSource { // DocvalueField adds a single field to load from the field data cache // and return as part of the search request. func (s *SearchSource) DocvalueField(fieldDataField string) *SearchSource { - s.docvalueFields = append(s.docvalueFields, fieldDataField) + s.docvalueFields = append(s.docvalueFields, DocvalueField{Field: fieldDataField}) + return s +} + +// DocvalueField adds a single docvalue field to load from the field data cache +// and return as part of the search request. +func (s *SearchSource) DocvalueFieldWithFormat(fieldDataFieldWithFormat DocvalueField) *SearchSource { + s.docvalueFields = append(s.docvalueFields, fieldDataFieldWithFormat) return s } // DocvalueFields adds one or more fields to load from the field data cache // and return as part of the search request. func (s *SearchSource) DocvalueFields(docvalueFields ...string) *SearchSource { + for _, f := range docvalueFields { + s.docvalueFields = append(s.docvalueFields, DocvalueField{Field: f}) + } + return s +} + +// DocvalueFields adds one or more docvalue fields to load from the field data cache +// and return as part of the search request. +func (s *SearchSource) DocvalueFieldsWithFormat(docvalueFields ...DocvalueField) *SearchSource { s.docvalueFields = append(s.docvalueFields, docvalueFields...) return s } @@ -346,13 +384,6 @@ 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 } @@ -365,13 +396,6 @@ func (s *SearchSource) Source() (interface{}, error) { if s.profile { source["profile"] = s.profile } - if s.collapse != nil { - src, err := s.collapse.Source() - if err != nil { - return nil, err - } - source["collapse"] = src - } if s.fetchSourceContext != nil { src, err := s.fetchSourceContext.Source() if err != nil { @@ -379,7 +403,6 @@ func (s *SearchSource) Source() (interface{}, error) { } source["_source"] = src } - if s.storedFieldNames != nil { switch len(s.storedFieldNames) { case 1: @@ -388,11 +411,13 @@ func (s *SearchSource) Source() (interface{}, error) { source["stored_fields"] = s.storedFieldNames } } - if len(s.docvalueFields) > 0 { - source["docvalue_fields"] = s.docvalueFields + src, err := s.docvalueFields.Source() + if err != nil { + return nil, err + } + source["docvalue_fields"] = src } - if len(s.scriptFields) > 0 { sfmap := make(map[string]interface{}) for _, scriptField := range s.scriptFields { @@ -404,7 +429,6 @@ func (s *SearchSource) Source() (interface{}, error) { } source["script_fields"] = sfmap } - if len(s.sorters) > 0 { var sortarr []interface{} for _, sorter := range s.sorters { @@ -416,19 +440,25 @@ func (s *SearchSource) Source() (interface{}, error) { } source["sort"] = sortarr } - - if s.trackScores { - source["track_scores"] = s.trackScores + if v := s.trackScores; v != nil { + source["track_scores"] = *v + } + if v := s.trackTotalHits; v != nil { + source["track_total_hits"] = *v } - if len(s.searchAfterSortValues) > 0 { source["search_after"] = s.searchAfterSortValues } - + if s.sliceQuery != nil { + src, err := s.sliceQuery.Source() + if err != nil { + return nil, err + } + source["slice"] = src + } if len(s.indexBoosts) > 0 { source["indices_boost"] = s.indexBoosts } - if len(s.aggregations) > 0 { aggsMap := make(map[string]interface{}) for name, aggregate := range s.aggregations { @@ -440,7 +470,6 @@ func (s *SearchSource) Source() (interface{}, error) { } source["aggregations"] = aggsMap } - if s.highlight != nil { src, err := s.highlight.Source() if err != nil { @@ -448,7 +477,6 @@ func (s *SearchSource) Source() (interface{}, error) { } source["highlight"] = src } - if len(s.suggesters) > 0 { suggesters := make(map[string]interface{}) for _, s := range s.suggesters { @@ -463,7 +491,6 @@ func (s *SearchSource) Source() (interface{}, error) { } source["suggest"] = suggesters } - if len(s.rescores) > 0 { // Strip empty rescores from request var rescores []*Rescore @@ -472,7 +499,6 @@ func (s *SearchSource) Source() (interface{}, error) { rescores = append(rescores, r) } } - if len(rescores) == 1 { rescores[0].defaultRescoreWindowSize = s.defaultRescoreWindowSize src, err := rescores[0].Source() @@ -493,10 +519,18 @@ func (s *SearchSource) Source() (interface{}, error) { source["rescore"] = slice } } - if len(s.stats) > 0 { source["stats"] = s.stats } + // TODO ext builders + + if s.collapse != nil { + src, err := s.collapse.Source() + if err != nil { + return nil, err + } + source["collapse"] = src + } if len(s.innerHits) > 0 { // Top-level inner hits diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_terms_lookup.go b/vendor/gopkg.in/olivere/elastic.v6/search_terms_lookup.go similarity index 95% rename from vendor/gopkg.in/olivere/elastic.v5/search_terms_lookup.go rename to vendor/gopkg.in/olivere/elastic.v6/search_terms_lookup.go index e59e15c124..7efe8394d0 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_terms_lookup.go +++ b/vendor/gopkg.in/olivere/elastic.v6/search_terms_lookup.go @@ -7,7 +7,7 @@ package elastic // TermsLookup encapsulates the parameters needed to fetch terms. // // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.3/query-dsl-terms-query.html#query-dsl-terms-lookup. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-terms-query.html#query-dsl-terms-lookup. type TermsLookup struct { index string typ string diff --git a/vendor/gopkg.in/olivere/elastic.v5/snapshot_create.go b/vendor/gopkg.in/olivere/elastic.v6/snapshot_create.go similarity index 79% rename from vendor/gopkg.in/olivere/elastic.v5/snapshot_create.go rename to vendor/gopkg.in/olivere/elastic.v6/snapshot_create.go index 1c6385e76f..fcf074794d 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/snapshot_create.go +++ b/vendor/gopkg.in/olivere/elastic.v6/snapshot_create.go @@ -9,12 +9,11 @@ import ( "encoding/json" "fmt" "net/url" - "time" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) -// SnapshotCreateService is documented at https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-snapshots.html. +// SnapshotCreateService is documented at https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-snapshots.html. type SnapshotCreateService struct { client *Client pretty bool @@ -89,7 +88,7 @@ func (s *SnapshotCreateService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.masterTimeout != "" { params.Set("master_timeout", s.masterTimeout) @@ -137,7 +136,12 @@ func (s *SnapshotCreateService) Do(ctx context.Context) (*SnapshotCreateResponse } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -167,20 +171,5 @@ type SnapshotCreateResponse struct { Accepted *bool `json:"accepted"` // Snapshot is available when waitForCompletion is true. - Snapshot *struct { - Snapshot string `json:"snapshot"` - UUID string `json:"uuid"` - VersionID int `json:"version_id"` - Version string `json:"version"` - Indices []string `json:"indices"` - State string `json:"state"` - Reason string `json:"reason"` - StartTime time.Time `json:"start_time"` - StartTimeInMillis int64 `json:"start_time_in_millis"` - EndTime time.Time `json:"end_time"` - EndTimeInMillis int64 `json:"end_time_in_millis"` - DurationInMillis int64 `json:"duration_in_millis"` - Failures []SnapshotShardFailure `json:"failures"` - Shards *ShardsInfo `json:"shards"` - } `json:"snapshot"` + Snapshot *Snapshot `json:"snapshot"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/snapshot_create_repository.go b/vendor/gopkg.in/olivere/elastic.v6/snapshot_create_repository.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/snapshot_create_repository.go rename to vendor/gopkg.in/olivere/elastic.v6/snapshot_create_repository.go index e4188495b4..85d9eda406 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/snapshot_create_repository.go +++ b/vendor/gopkg.in/olivere/elastic.v6/snapshot_create_repository.go @@ -10,11 +10,11 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // SnapshotCreateRepositoryService creates a snapshot repository. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.3/modules-snapshots.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-snapshots.html // for details. type SnapshotCreateRepositoryService struct { client *Client @@ -112,7 +112,7 @@ func (s *SnapshotCreateRepositoryService) buildURL() (string, url.Values, error) // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.masterTimeout != "" { params.Set("master_timeout", s.masterTimeout) @@ -179,7 +179,12 @@ func (s *SnapshotCreateRepositoryService) Do(ctx context.Context) (*SnapshotCrea } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "PUT", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -194,5 +199,7 @@ func (s *SnapshotCreateRepositoryService) Do(ctx context.Context) (*SnapshotCrea // SnapshotCreateRepositoryResponse is the response of SnapshotCreateRepositoryService.Do. type SnapshotCreateRepositoryResponse struct { - Acknowledged bool `json:"acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v6/snapshot_delete.go b/vendor/gopkg.in/olivere/elastic.v6/snapshot_delete.go new file mode 100644 index 0000000000..8cfa70701a --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/snapshot_delete.go @@ -0,0 +1,106 @@ +// 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// SnapshotDeleteService deletes a snapshot from a snapshot repository. +// It is documented at +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-snapshots.html. +type SnapshotDeleteService struct { + client *Client + repository string + snapshot string +} + +// NewSnapshotDeleteService creates a new SnapshotDeleteService. +func NewSnapshotDeleteService(client *Client) *SnapshotDeleteService { + return &SnapshotDeleteService{ + client: client, + } +} + +// Repository is the repository name. +func (s *SnapshotDeleteService) Repository(repository string) *SnapshotDeleteService { + s.repository = repository + return s +} + +// Snapshot is the snapshot name. +func (s *SnapshotDeleteService) Snapshot(snapshot string) *SnapshotDeleteService { + s.snapshot = snapshot + return s +} + +// buildURL builds the URL for the operation. +func (s *SnapshotDeleteService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_snapshot/{repository}/{snapshot}", map[string]string{ + "repository": s.repository, + "snapshot": s.snapshot, + }) + if err != nil { + return "", url.Values{}, err + } + return path, url.Values{}, nil +} + +// Validate checks if the operation is valid. +func (s *SnapshotDeleteService) Validate() error { + var invalid []string + if s.repository == "" { + invalid = append(invalid, "Repository") + } + if s.snapshot == "" { + invalid = append(invalid, "Snapshot") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *SnapshotDeleteService) Do(ctx context.Context) (*SnapshotDeleteResponse, 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, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(SnapshotDeleteResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// SnapshotDeleteResponse is the response of SnapshotDeleteService.Do. +type SnapshotDeleteResponse struct { + Acknowledged bool `json:"acknowledged"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/snapshot_delete_repository.go b/vendor/gopkg.in/olivere/elastic.v6/snapshot_delete_repository.go similarity index 87% rename from vendor/gopkg.in/olivere/elastic.v5/snapshot_delete_repository.go rename to vendor/gopkg.in/olivere/elastic.v6/snapshot_delete_repository.go index 1f402fba53..1695222c5d 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/snapshot_delete_repository.go +++ b/vendor/gopkg.in/olivere/elastic.v6/snapshot_delete_repository.go @@ -11,11 +11,11 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // SnapshotDeleteRepositoryService deletes a snapshot repository. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.3/modules-snapshots.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-snapshots.html // for details. type SnapshotDeleteRepositoryService struct { client *Client @@ -70,7 +70,7 @@ func (s *SnapshotDeleteRepositoryService) buildURL() (string, url.Values, error) // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.masterTimeout != "" { params.Set("master_timeout", s.masterTimeout) @@ -107,7 +107,11 @@ func (s *SnapshotDeleteRepositoryService) Do(ctx context.Context) (*SnapshotDele } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "DELETE", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + }) if err != nil { return nil, err } @@ -122,5 +126,7 @@ func (s *SnapshotDeleteRepositoryService) Do(ctx context.Context) (*SnapshotDele // SnapshotDeleteRepositoryResponse is the response of SnapshotDeleteRepositoryService.Do. type SnapshotDeleteRepositoryResponse struct { - Acknowledged bool `json:"acknowledged"` + Acknowledged bool `json:"acknowledged"` + ShardsAcknowledged bool `json:"shards_acknowledged"` + Index string `json:"index,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v6/snapshot_get.go b/vendor/gopkg.in/olivere/elastic.v6/snapshot_get.go new file mode 100644 index 0000000000..81a5fe79ca --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/snapshot_get.go @@ -0,0 +1,164 @@ +// 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + "strings" + "time" + + "github.com/olivere/elastic/uritemplates" +) + +// SnapshotGetService lists the snapshots on a repository +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-snapshots.html +// for details. +type SnapshotGetService struct { + client *Client + repository string + snapshot []string + masterTimeout string + ignoreUnavailable *bool + verbose *bool +} + +// NewSnapshotGetService creates a new SnapshotGetService. +func NewSnapshotGetService(client *Client) *SnapshotGetService { + return &SnapshotGetService{ + client: client, + } +} + +// Repository is the repository name. +func (s *SnapshotGetService) Repository(repository string) *SnapshotGetService { + s.repository = repository + return s +} + +// Snapshot is the list of snapshot names. If not set, defaults to all snapshots. +func (s *SnapshotGetService) Snapshot(snapshots ...string) *SnapshotGetService { + s.snapshot = append(s.snapshot, snapshots...) + return s +} + +// MasterTimeout specifies an explicit operation timeout for connection to master node. +func (s *SnapshotGetService) MasterTimeout(masterTimeout string) *SnapshotGetService { + s.masterTimeout = masterTimeout + return s +} + +// IgnoreUnavailable specifies whether to ignore unavailable snapshots, defaults to false +func (s *SnapshotGetService) IgnoreUnavailable(ignoreUnavailable bool) *SnapshotGetService { + s.ignoreUnavailable = &ignoreUnavailable + return s +} + +// Verbose specifies whether to show verbose snapshot info or only show the basic info found in the repository index blob +func (s *SnapshotGetService) Verbose(verbose bool) *SnapshotGetService { + s.verbose = &verbose + return s +} + +// buildURL builds the URL for the operation. +func (s *SnapshotGetService) buildURL() (string, url.Values, error) { + // Build URL + var err error + var path string + if len(s.snapshot) > 0 { + path, err = uritemplates.Expand("/_snapshot/{repository}/{snapshot}", map[string]string{ + "repository": s.repository, + "snapshot": strings.Join(s.snapshot, ","), + }) + } else { + path, err = uritemplates.Expand("/_snapshot/{repository}/_all", map[string]string{ + "repository": s.repository, + }) + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if s.ignoreUnavailable != nil { + params.Set("ignore_unavailable", fmt.Sprint(*s.ignoreUnavailable)) + } + if s.verbose != nil { + params.Set("verbose", fmt.Sprint(*s.verbose)) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *SnapshotGetService) Validate() error { + var invalid []string + if s.repository == "" { + invalid = append(invalid, "Repository") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *SnapshotGetService) Do(ctx context.Context) (*SnapshotGetResponse, 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, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(SnapshotGetResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// SnapshotGetResponse is the response of SnapshotGetService.Do. +type SnapshotGetResponse struct { + Snapshots []*Snapshot `json:"snapshots"` +} + +// Snapshot contains all information about a single snapshot +type Snapshot struct { + Snapshot string `json:"snapshot"` + UUID string `json:"uuid"` + VersionID int `json:"version_id"` + Version string `json:"version"` + Indices []string `json:"indices"` + State string `json:"state"` + Reason string `json:"reason"` + StartTime time.Time `json:"start_time"` + StartTimeInMillis int64 `json:"start_time_in_millis"` + EndTime time.Time `json:"end_time"` + EndTimeInMillis int64 `json:"end_time_in_millis"` + DurationInMillis int64 `json:"duration_in_millis"` + Failures []SnapshotShardFailure `json:"failures"` + Shards *ShardsInfo `json:"shards"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/snapshot_get_repository.go b/vendor/gopkg.in/olivere/elastic.v6/snapshot_get_repository.go similarity index 92% rename from vendor/gopkg.in/olivere/elastic.v5/snapshot_get_repository.go rename to vendor/gopkg.in/olivere/elastic.v6/snapshot_get_repository.go index 10b2d0b9c8..afdd4450a6 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/snapshot_get_repository.go +++ b/vendor/gopkg.in/olivere/elastic.v6/snapshot_get_repository.go @@ -11,11 +11,11 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // SnapshotGetRepositoryService reads a snapshot repository. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.3/modules-snapshots.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-snapshots.html // for details. type SnapshotGetRepositoryService struct { client *Client @@ -76,7 +76,7 @@ func (s *SnapshotGetRepositoryService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.local != nil { params.Set("local", fmt.Sprintf("%v", *s.local)) @@ -106,7 +106,11 @@ func (s *SnapshotGetRepositoryService) Do(ctx context.Context) (SnapshotGetRepos } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v6/snapshot_restore.go b/vendor/gopkg.in/olivere/elastic.v6/snapshot_restore.go new file mode 100644 index 0000000000..ad08e516d8 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/snapshot_restore.go @@ -0,0 +1,244 @@ +package elastic + +import ( + "context" + "encoding/json" + "fmt" + "net/url" + "strings" + + "github.com/olivere/elastic/uritemplates" +) + +// SnapshotRestoreService restores a snapshot from a snapshot repository. +// +// It is documented at +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-snapshots.html#_restore. +type SnapshotRestoreService struct { + client *Client + repository string + snapshot string + pretty bool + masterTimeout string + waitForCompletion *bool + ignoreUnavailable *bool + partial *bool + includeAliases *bool + includeGlobalState *bool + bodyString string + renamePattern string + renameReplacement string + indices []string + indexSettings map[string]interface{} +} + +// NewSnapshotCreateService creates a new SnapshotRestoreService. +func NewSnapshotRestoreService(client *Client) *SnapshotRestoreService { + return &SnapshotRestoreService{ + client: client, + } +} + +// Repository name. +func (s *SnapshotRestoreService) Repository(repository string) *SnapshotRestoreService { + s.repository = repository + return s +} + +// Snapshot name. +func (s *SnapshotRestoreService) Snapshot(snapshot string) *SnapshotRestoreService { + s.snapshot = snapshot + return s +} + +// MasterTimeout specifies an explicit operation timeout for connection to master node. +func (s *SnapshotRestoreService) MasterTimeout(masterTimeout string) *SnapshotRestoreService { + s.masterTimeout = masterTimeout + return s +} + +// WaitForCompletion indicates whether this request should wait until the operation has +// completed before returning. +func (s *SnapshotRestoreService) WaitForCompletion(waitForCompletion bool) *SnapshotRestoreService { + s.waitForCompletion = &waitForCompletion + return s +} + +// Indices sets the name of the indices that should be restored from the snapshot. +func (s *SnapshotRestoreService) Indices(indices ...string) *SnapshotRestoreService { + s.indices = indices + return s +} + +// IncludeGlobalState allows the global cluster state to be restored, defaults to false. +func (s *SnapshotRestoreService) IncludeGlobalState(includeGlobalState bool) *SnapshotRestoreService { + s.includeGlobalState = &includeGlobalState + return s +} + +// RenamePattern helps rename indices on restore using regular expressions. +func (s *SnapshotRestoreService) RenamePattern(renamePattern string) *SnapshotRestoreService { + s.renamePattern = renamePattern + return s +} + +// RenameReplacement as RenamePattern, helps rename indices on restore using regular expressions. +func (s *SnapshotRestoreService) RenameReplacement(renameReplacement string) *SnapshotRestoreService { + s.renameReplacement = renameReplacement + return s +} + +// Partial indicates whether to restore indices that where partially snapshoted, defaults to false. +func (s *SnapshotRestoreService) Partial(partial bool) *SnapshotRestoreService { + s.partial = &partial + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *SnapshotRestoreService) Pretty(pretty bool) *SnapshotRestoreService { + s.pretty = pretty + return s +} + +// BodyString allows the user to specify the body of the HTTP request manually. +func (s *SnapshotRestoreService) BodyString(body string) *SnapshotRestoreService { + s.bodyString = body + return s +} + +// IndexSettings sets the settings to be overwritten during the restore process +func (s *SnapshotRestoreService) IndexSettings(indexSettings map[string]interface{}) *SnapshotRestoreService { + s.indexSettings = indexSettings + return s +} + +// IncludeAliases flags whether indices should be restored with their respective aliases, +// defaults to false. +func (s *SnapshotRestoreService) IncludeAliases(includeAliases bool) *SnapshotRestoreService { + s.includeAliases = &includeAliases + return s +} + +// IgnoreUnavailable specifies whether to ignore unavailable snapshots, defaults to false. +func (s *SnapshotRestoreService) IgnoreUnavailable(ignoreUnavailable bool) *SnapshotRestoreService { + s.ignoreUnavailable = &ignoreUnavailable + return s +} + +// Do executes the operation. +func (s *SnapshotRestoreService) Do(ctx context.Context) (*SnapshotRestoreResponse, error) { + if err := s.Validate(); err != nil { + return nil, err + } + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + var body interface{} + if len(s.bodyString) > 0 { + body = s.bodyString + } else { + body = s.buildBody() + } + + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) + if err != nil { + return nil, err + } + + ret := new(SnapshotRestoreResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// Validate checks if the operation is valid. +func (s *SnapshotRestoreService) Validate() error { + var invalid []string + if s.repository == "" { + invalid = append(invalid, "Repository") + } + if s.snapshot == "" { + invalid = append(invalid, "Snapshot") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +func (s *SnapshotRestoreService) buildURL() (string, url.Values, error) { + path, err := uritemplates.Expand("/_snapshot/{repository}/{snapshot}/_restore", map[string]string{ + "snapshot": s.snapshot, + "repository": s.repository, + }) + if err != nil { + return "", url.Values{}, err + } + + params := url.Values{} + + if s.pretty { + params.Set("pretty", "true") + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if s.waitForCompletion != nil { + params.Set("wait_for_completion", fmt.Sprintf("%v", *s.waitForCompletion)) + } + if s.ignoreUnavailable != nil { + params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable)) + } + return path, params, nil +} + +func (s *SnapshotRestoreService) buildBody() interface{} { + body := map[string]interface{}{} + + if s.includeGlobalState != nil { + body["include_global_state"] = *s.includeGlobalState + } + if s.partial != nil { + body["partial"] = *s.partial + } + if s.includeAliases != nil { + body["include_aliases"] = *s.includeAliases + } + if len(s.indices) > 0 { + body["indices"] = strings.Join(s.indices, ",") + } + if len(s.renamePattern) > 0 { + body["rename_pattern"] = s.renamePattern + } + if len(s.renamePattern) > 0 { + body["rename_replacement"] = s.renameReplacement + } + if len(s.indexSettings) > 0 { + body["index_settings"] = s.indexSettings + } + return body +} + +// SnapshotRestoreResponse represents the response for SnapshotRestoreService.Do +type SnapshotRestoreResponse struct { + // Accepted indicates whether the request was accepted by Elasticsearch. + Accepted *bool `json:"accepted"` + + // Snapshot information. + Snapshot *RestoreInfo `json:"snapshot"` +} + +// RestoreInfo represents information about the restored snapshot. +type RestoreInfo struct { + Snapshot string `json:"snapshot"` + Indices []string `json:"indices"` + Shards ShardsInfo `json:"shards"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/snapshot_verify_repository.go b/vendor/gopkg.in/olivere/elastic.v6/snapshot_verify_repository.go similarity index 91% rename from vendor/gopkg.in/olivere/elastic.v5/snapshot_verify_repository.go rename to vendor/gopkg.in/olivere/elastic.v6/snapshot_verify_repository.go index 4e8c25a24e..a4e89529e4 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/snapshot_verify_repository.go +++ b/vendor/gopkg.in/olivere/elastic.v6/snapshot_verify_repository.go @@ -10,11 +10,11 @@ import ( "fmt" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // SnapshotVerifyRepositoryService verifies a snapshop repository. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.3/modules-snapshots.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-snapshots.html // for details. type SnapshotVerifyRepositoryService struct { client *Client @@ -68,7 +68,7 @@ func (s *SnapshotVerifyRepositoryService) buildURL() (string, url.Values, error) // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.masterTimeout != "" { params.Set("master_timeout", s.masterTimeout) @@ -105,7 +105,11 @@ func (s *SnapshotVerifyRepositoryService) Do(ctx context.Context) (*SnapshotVeri } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/sort.go b/vendor/gopkg.in/olivere/elastic.v6/sort.go similarity index 71% rename from vendor/gopkg.in/olivere/elastic.v5/sort.go rename to vendor/gopkg.in/olivere/elastic.v6/sort.go index fddbbb6108..28f9159bae 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/sort.go +++ b/vendor/gopkg.in/olivere/elastic.v6/sort.go @@ -9,7 +9,7 @@ import "errors" // -- Sorter -- // Sorter is an interface for sorting strategies, e.g. ScoreSort or FieldSort. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-sort.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html. type Sorter interface { Source() (interface{}, error) } @@ -25,8 +25,12 @@ type SortInfo struct { IgnoreUnmapped *bool UnmappedType string SortMode string - NestedFilter Query - NestedPath string + NestedFilter Query // deprecated in 6.1 and replaced by Filter + Filter Query + NestedPath string // deprecated in 6.1 and replaced by Path + Path string + NestedSort *NestedSort // deprecated in 6.1 and replaced by Nested + Nested *NestedSort } func (info SortInfo) Source() (interface{}, error) { @@ -48,15 +52,36 @@ func (info SortInfo) Source() (interface{}, error) { if info.SortMode != "" { prop["mode"] = info.SortMode } - if info.NestedFilter != nil { + if info.Filter != nil { + src, err := info.Filter.Source() + if err != nil { + return nil, err + } + prop["filter"] = src + } else if info.NestedFilter != nil { src, err := info.NestedFilter.Source() if err != nil { return nil, err } - prop["nested_filter"] = src + prop["nested_filter"] = src // deprecated in 6.1 } - if info.NestedPath != "" { - prop["nested_path"] = info.NestedPath + if info.Path != "" { + prop["path"] = info.Path + } else if info.NestedPath != "" { + prop["nested_path"] = info.NestedPath // deprecated in 6.1 + } + if info.Nested != nil { + src, err := info.Nested.Source() + if err != nil { + return nil, err + } + prop["nested"] = src + } else if info.NestedSort != nil { + src, err := info.NestedSort.Source() + if err != nil { + return nil, err + } + prop["nested"] = src } source := make(map[string]interface{}) source[info.Field] = prop @@ -66,7 +91,7 @@ func (info SortInfo) Source() (interface{}, error) { // -- SortByDoc -- // SortByDoc sorts by the "_doc" field, as described in -// https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-scroll.html. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-scroll.html. // // Example: // ss := elastic.NewSearchSource() @@ -134,8 +159,9 @@ type FieldSort struct { missing interface{} unmappedType *string sortMode *string - nestedFilter Query - nestedPath *string + filter Query + path *string + nested *NestedSort } // NewFieldSort creates a new FieldSort. @@ -195,15 +221,45 @@ func (s *FieldSort) SortMode(sortMode string) *FieldSort { // NestedFilter sets a filter that nested objects should match with // in order to be taken into account for sorting. +// Deprecated: Use Filter instead. func (s *FieldSort) NestedFilter(nestedFilter Query) *FieldSort { - s.nestedFilter = nestedFilter + s.filter = nestedFilter + return s +} + +// Filter sets a filter that nested objects should match with +// in order to be taken into account for sorting. +func (s *FieldSort) Filter(filter Query) *FieldSort { + s.filter = filter return s } // NestedPath is used if sorting occurs on a field that is inside a // nested object. +// Deprecated: Use Path instead. func (s *FieldSort) NestedPath(nestedPath string) *FieldSort { - s.nestedPath = &nestedPath + s.path = &nestedPath + return s +} + +// Path is used if sorting occurs on a field that is inside a +// nested object. +func (s *FieldSort) Path(path string) *FieldSort { + s.path = &path + return s +} + +// NestedSort is available starting with 6.1 and will replace NestedFilter +// and NestedPath. +// Deprecated: Use Nested instead. +func (s *FieldSort) NestedSort(nestedSort *NestedSort) *FieldSort { + s.nested = nestedSort + return s +} + +// Nested is available starting with 6.1 and will replace Filter and Path. +func (s *FieldSort) Nested(nested *NestedSort) *FieldSort { + s.nested = nested return s } @@ -226,15 +282,22 @@ func (s *FieldSort) Source() (interface{}, error) { if s.sortMode != nil { x["mode"] = *s.sortMode } - if s.nestedFilter != nil { - src, err := s.nestedFilter.Source() + if s.filter != nil { + src, err := s.filter.Source() if err != nil { return nil, err } - x["nested_filter"] = src + x["filter"] = src } - if s.nestedPath != nil { - x["nested_path"] = *s.nestedPath + if s.path != nil { + x["path"] = *s.path + } + if s.nested != nil { + src, err := s.nested.Source() + if err != nil { + return nil, err + } + x["nested"] = src } return source, nil } @@ -242,7 +305,7 @@ func (s *FieldSort) Source() (interface{}, error) { // -- GeoDistanceSort -- // GeoDistanceSort allows for sorting by geographic distance. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-sort.html#_geo_distance_sorting. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html#_geo_distance_sorting. type GeoDistanceSort struct { Sorter fieldName string @@ -254,6 +317,7 @@ type GeoDistanceSort struct { sortMode *string nestedFilter Query nestedPath *string + nestedSort *NestedSort } // NewGeoDistanceSort creates a new sorter for geo distances. @@ -307,7 +371,7 @@ func (s *GeoDistanceSort) GeoHashes(geohashes ...string) *GeoDistanceSort { } // Unit specifies the distance unit to use. It defaults to km. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/common-options.html#distance-units +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/common-options.html#distance-units // for details. func (s *GeoDistanceSort) Unit(unit string) *GeoDistanceSort { s.unit = unit @@ -320,7 +384,7 @@ func (s *GeoDistanceSort) GeoDistance(geoDistance string) *GeoDistanceSort { } // DistanceType describes how to compute the distance, e.g. "arc" or "plane". -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-sort.html#geo-sorting +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html#geo-sorting // for details. func (s *GeoDistanceSort) DistanceType(distanceType string) *GeoDistanceSort { s.distanceType = &distanceType @@ -349,6 +413,13 @@ func (s *GeoDistanceSort) NestedPath(nestedPath string) *GeoDistanceSort { return s } +// NestedSort is available starting with 6.1 and will replace NestedFilter +// and NestedPath. +func (s *GeoDistanceSort) NestedSort(nestedSort *NestedSort) *GeoDistanceSort { + s.nestedSort = nestedSort + return s +} + // Source returns the JSON-serializable data. func (s *GeoDistanceSort) Source() (interface{}, error) { source := make(map[string]interface{}) @@ -390,13 +461,20 @@ func (s *GeoDistanceSort) Source() (interface{}, error) { if s.nestedPath != nil { x["nested_path"] = *s.nestedPath } + if s.nestedSort != nil { + src, err := s.nestedSort.Source() + if err != nil { + return nil, err + } + x["nested"] = src + } return source, nil } // -- ScriptSort -- // ScriptSort sorts by a custom script. See -// https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-scripting.html#modules-scripting +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting.html#modules-scripting // for details about scripting. type ScriptSort struct { Sorter @@ -406,6 +484,7 @@ type ScriptSort struct { sortMode *string nestedFilter Query nestedPath *string + nestedSort *NestedSort } // NewScriptSort creates and initializes a new ScriptSort. @@ -464,6 +543,13 @@ func (s *ScriptSort) NestedPath(nestedPath string) *ScriptSort { return s } +// NestedSort is available starting with 6.1 and will replace NestedFilter +// and NestedPath. +func (s *ScriptSort) NestedSort(nestedSort *NestedSort) *ScriptSort { + s.nestedSort = nestedSort + return s +} + // Source returns the JSON-serializable data. func (s *ScriptSort) Source() (interface{}, error) { if s.script == nil { @@ -499,5 +585,70 @@ func (s *ScriptSort) Source() (interface{}, error) { if s.nestedPath != nil { x["nested_path"] = *s.nestedPath } + if s.nestedSort != nil { + src, err := s.nestedSort.Source() + if err != nil { + return nil, err + } + x["nested"] = src + } + return source, nil +} + +// -- NestedSort -- + +// NestedSort is used for fields that are inside a nested object. +// It takes a "path" argument and an optional nested filter that the +// nested objects should match with in order to be taken into account +// for sorting. +// +// NestedSort is available from 6.1 and replaces nestedFilter and nestedPath +// in the other sorters. +type NestedSort struct { + Sorter + path string + filter Query + nestedSort *NestedSort +} + +// NewNestedSort creates a new NestedSort. +func NewNestedSort(path string) *NestedSort { + return &NestedSort{path: path} +} + +// Filter sets the filter. +func (s *NestedSort) Filter(filter Query) *NestedSort { + s.filter = filter + return s +} + +// NestedSort embeds another level of nested sorting. +func (s *NestedSort) NestedSort(nestedSort *NestedSort) *NestedSort { + s.nestedSort = nestedSort + return s +} + +// Source returns the JSON-serializable data. +func (s *NestedSort) Source() (interface{}, error) { + source := make(map[string]interface{}) + + if s.path != "" { + source["path"] = s.path + } + if s.filter != nil { + src, err := s.filter.Source() + if err != nil { + return nil, err + } + source["filter"] = src + } + if s.nestedSort != nil { + src, err := s.nestedSort.Source() + if err != nil { + return nil, err + } + source["nested"] = src + } + return source, nil } diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggest_field.go b/vendor/gopkg.in/olivere/elastic.v6/suggest_field.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/suggest_field.go rename to vendor/gopkg.in/olivere/elastic.v6/suggest_field.go index 8e15b4ec24..8405a6f9e6 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/suggest_field.go +++ b/vendor/gopkg.in/olivere/elastic.v6/suggest_field.go @@ -67,7 +67,7 @@ func (f *SuggestField) MarshalJSON() ([]byte, error) { if err != nil { return nil, err } - source["context"] = src + source["contexts"] = src default: ctxq := make(map[string]interface{}) for _, query := range f.contextQueries { @@ -83,7 +83,7 @@ func (f *SuggestField) MarshalJSON() ([]byte, error) { ctxq[k] = v } } - source["context"] = ctxq + source["contexts"] = ctxq } return json.Marshal(source) diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggester.go b/vendor/gopkg.in/olivere/elastic.v6/suggester.go similarity index 100% rename from vendor/gopkg.in/olivere/elastic.v5/suggester.go rename to vendor/gopkg.in/olivere/elastic.v6/suggester.go diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggester_completion.go b/vendor/gopkg.in/olivere/elastic.v6/suggester_completion.go similarity index 88% rename from vendor/gopkg.in/olivere/elastic.v5/suggester_completion.go rename to vendor/gopkg.in/olivere/elastic.v6/suggester_completion.go index cf775c954c..2fb4f234a3 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/suggester_completion.go +++ b/vendor/gopkg.in/olivere/elastic.v6/suggester_completion.go @@ -7,7 +7,8 @@ package elastic import "errors" // CompletionSuggester is a fast suggester for e.g. type-ahead completion. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-completion.html +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-completion.html // for more details. type CompletionSuggester struct { Suggester @@ -22,8 +23,9 @@ type CompletionSuggester struct { contextQueries []SuggesterContextQuery payload interface{} - fuzzyOptions *FuzzyCompletionSuggesterOptions - regexOptions *RegexCompletionSuggesterOptions + fuzzyOptions *FuzzyCompletionSuggesterOptions + regexOptions *RegexCompletionSuggesterOptions + skipDuplicates *bool } // Creates a new completion suggester. @@ -64,6 +66,14 @@ func (q *CompletionSuggester) FuzzyOptions(options *FuzzyCompletionSuggesterOpti return q } +func (q *CompletionSuggester) Fuzziness(fuzziness interface{}) *CompletionSuggester { + if q.fuzzyOptions == nil { + q.fuzzyOptions = NewFuzzyCompletionSuggesterOptions() + } + q.fuzzyOptions = q.fuzzyOptions.EditDistance(fuzziness) + return q +} + func (q *CompletionSuggester) Regex(regex string) *CompletionSuggester { q.regex = regex return q @@ -80,6 +90,11 @@ func (q *CompletionSuggester) RegexOptions(options *RegexCompletionSuggesterOpti return q } +func (q *CompletionSuggester) SkipDuplicates(skipDuplicates bool) *CompletionSuggester { + q.skipDuplicates = &skipDuplicates + return q +} + func (q *CompletionSuggester) Field(field string) *CompletionSuggester { q.field = field return q @@ -157,7 +172,7 @@ func (q *CompletionSuggester) Source(includeName bool) (interface{}, error) { if err != nil { return nil, err } - suggester["context"] = src + suggester["contexts"] = src default: ctxq := make(map[string]interface{}) for _, query := range q.contextQueries { @@ -195,6 +210,10 @@ func (q *CompletionSuggester) Source(includeName bool) (interface{}, error) { suggester["regex"] = src } + if q.skipDuplicates != nil { + suggester["skip_duplicates"] = *q.skipDuplicates + } + // TODO(oe) Add completion-suggester specific parameters here if !includeName { @@ -224,7 +243,9 @@ func NewFuzzyCompletionSuggesterOptions() *FuzzyCompletionSuggesterOptions { } // EditDistance specifies the maximum number of edits, e.g. a number like "1" or "2" -// or a string like "0..2" or ">5". See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/common-options.html#fuzziness +// or a string like "0..2" or ">5". +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/common-options.html#fuzziness // for details. func (o *FuzzyCompletionSuggesterOptions) EditDistance(editDistance interface{}) *FuzzyCompletionSuggesterOptions { o.editDistance = editDistance @@ -304,7 +325,10 @@ func NewRegexCompletionSuggesterOptions() *RegexCompletionSuggesterOptions { return &RegexCompletionSuggesterOptions{} } -// Flags represents internal regex flags. See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters-completion.html#regex +// Flags represents internal regex flags. +// Possible flags are ALL (default), ANYSTRING, COMPLEMENT, EMPTY, INTERSECTION, INTERVAL, or NONE. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-completion.html#regex // for details. func (o *RegexCompletionSuggesterOptions) Flags(flags interface{}) *RegexCompletionSuggesterOptions { o.flags = flags @@ -312,7 +336,8 @@ func (o *RegexCompletionSuggesterOptions) Flags(flags interface{}) *RegexComplet } // MaxDeterminizedStates represents the maximum automaton states allowed for regex expansion. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters-completion.html#regex +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-completion.html#regex // for details. func (o *RegexCompletionSuggesterOptions) MaxDeterminizedStates(max int) *RegexCompletionSuggesterOptions { o.maxDeterminizedStates = &max diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggester_context.go b/vendor/gopkg.in/olivere/elastic.v6/suggester_context.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/suggester_context.go rename to vendor/gopkg.in/olivere/elastic.v6/suggester_context.go index ade0991513..26855cd18b 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/suggester_context.go +++ b/vendor/gopkg.in/olivere/elastic.v6/suggester_context.go @@ -13,7 +13,7 @@ type SuggesterContextQuery interface { } // ContextSuggester is a fast suggester for e.g. type-ahead completion that supports filtering and boosting based on contexts. -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/suggester-context.html // for more details. type ContextSuggester struct { Suggester @@ -94,7 +94,7 @@ func (q *ContextSuggester) Source(includeName bool) (interface{}, error) { if err != nil { return nil, err } - suggester["context"] = src + suggester["contexts"] = src default: ctxq := make(map[string]interface{}) for _, query := range q.contextQueries { diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go b/vendor/gopkg.in/olivere/elastic.v6/suggester_context_category.go similarity index 74% rename from vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go rename to vendor/gopkg.in/olivere/elastic.v6/suggester_context_category.go index 2d63fe8fbc..232a4c95b5 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go +++ b/vendor/gopkg.in/olivere/elastic.v6/suggester_context_category.go @@ -7,7 +7,7 @@ package elastic // -- SuggesterCategoryMapping -- // SuggesterCategoryMapping provides a mapping for a category context in a suggester. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_category_mapping. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/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 https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_category_query. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/suggester-context.html#_category_query. type SuggesterCategoryQuery struct { name string values map[string]*int @@ -117,3 +117,38 @@ func (q *SuggesterCategoryQuery) Source() (interface{}, error) { return source, nil } + +type SuggesterCategoryIndex struct { + name string + values []string +} + +// NewSuggesterCategoryIndex creates a new SuggesterCategoryIndex. +func NewSuggesterCategoryIndex(name string, values ...string) *SuggesterCategoryIndex { + q := &SuggesterCategoryIndex{ + name: name, + values: values, + } + return q +} + +func (q *SuggesterCategoryIndex) Values(values ...string) *SuggesterCategoryIndex { + q.values = append(q.values, values...) + return q +} + +// Source returns a map that will be used to serialize the context query as JSON. +func (q *SuggesterCategoryIndex) Source() (interface{}, error) { + source := make(map[string]interface{}) + + switch len(q.values) { + case 0: + source[q.name] = make([]string, 0) + case 1: + source[q.name] = q.values[0] + default: + source[q.name] = q.values + } + + return source, nil +} diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggester_context_geo.go b/vendor/gopkg.in/olivere/elastic.v6/suggester_context_geo.go similarity index 56% rename from vendor/gopkg.in/olivere/elastic.v5/suggester_context_geo.go rename to vendor/gopkg.in/olivere/elastic.v6/suggester_context_geo.go index 6815bfe730..3693327ede 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/suggester_context_geo.go +++ b/vendor/gopkg.in/olivere/elastic.v6/suggester_context_geo.go @@ -7,7 +7,7 @@ package elastic // -- SuggesterGeoMapping -- // SuggesterGeoMapping provides a mapping for a geolocation context in a suggester. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_geo_location_mapping. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/suggester-context.html#_geo_location_mapping. type SuggesterGeoMapping struct { name string defaultLocations []*GeoPoint @@ -80,24 +80,36 @@ func (q *SuggesterGeoMapping) Source() (interface{}, error) { // -- SuggesterGeoQuery -- // SuggesterGeoQuery provides querying a geolocation context in a suggester. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_geo_location_query +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/suggester-context.html#_geo_location_query type SuggesterGeoQuery struct { - name string - location *GeoPoint - precision []string + name string + location *GeoPoint + precision string + neighbours []string + boost *int } // NewSuggesterGeoQuery creates a new SuggesterGeoQuery. func NewSuggesterGeoQuery(name string, location *GeoPoint) *SuggesterGeoQuery { return &SuggesterGeoQuery{ - name: name, - location: location, - precision: make([]string, 0), + name: name, + location: location, + neighbours: make([]string, 0), } } -func (q *SuggesterGeoQuery) Precision(precision ...string) *SuggesterGeoQuery { - q.precision = append(q.precision, precision...) +func (q *SuggesterGeoQuery) Precision(precision string) *SuggesterGeoQuery { + q.precision = precision + return q +} + +func (q *SuggesterGeoQuery) Neighbours(neighbours ...string) *SuggesterGeoQuery { + q.neighbours = append(q.neighbours, neighbours...) + return q +} + +func (q *SuggesterGeoQuery) Boost(boost int) *SuggesterGeoQuery { + q.boost = &boost return q } @@ -105,25 +117,61 @@ func (q *SuggesterGeoQuery) Precision(precision ...string) *SuggesterGeoQuery { func (q *SuggesterGeoQuery) Source() (interface{}, error) { source := make(map[string]interface{}) - if len(q.precision) == 0 { - if q.location != nil { - source[q.name] = q.location.Source() - } - } else { - x := make(map[string]interface{}) - source[q.name] = x + x := make(map[string]interface{}) + source[q.name] = x - if q.location != nil { - x["value"] = q.location.Source() - } - - switch len(q.precision) { - case 0: - case 1: - x["precision"] = q.precision[0] - default: - x["precision"] = q.precision - } + if q.location != nil { + x["context"] = q.location.Source() + } + if q.precision != "" { + x["precision"] = q.precision + } + if q.boost != nil { + x["boost"] = q.boost + } + switch len(q.neighbours) { + case 0: + case 1: + x["neighbours"] = q.neighbours[0] + default: + x["neighbours"] = q.neighbours + } + + return source, nil +} + +type SuggesterGeoIndex struct { + name string + locations []*GeoPoint +} + +// NewSuggesterGeoQuery creates a new SuggesterGeoQuery. +func NewSuggesterGeoIndex(name string) *SuggesterGeoIndex { + return &SuggesterGeoIndex{ + name: name, + } +} + +func (q *SuggesterGeoIndex) Locations(locations ...*GeoPoint) *SuggesterGeoIndex { + q.locations = append(q.locations, locations...) + return q +} + +// Source returns a map that will be used to serialize the context query as JSON. +func (q *SuggesterGeoIndex) Source() (interface{}, error) { + source := make(map[string]interface{}) + + switch len(q.locations) { + case 0: + source[q.name] = make([]string, 0) + case 1: + source[q.name] = q.locations[0].Source() + default: + var arr []interface{} + for _, p := range q.locations { + arr = append(arr, p.Source()) + } + source[q.name] = arr } return source, nil diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggester_phrase.go b/vendor/gopkg.in/olivere/elastic.v6/suggester_phrase.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/suggester_phrase.go rename to vendor/gopkg.in/olivere/elastic.v6/suggester_phrase.go index f75e1ddc1b..ac3bbfc3cc 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/suggester_phrase.go +++ b/vendor/gopkg.in/olivere/elastic.v6/suggester_phrase.go @@ -7,7 +7,7 @@ package elastic // PhraseSuggester provides an API to access word alternatives // on a per token basis within a certain string distance. // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-phrase.html. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-phrase.html. type PhraseSuggester struct { Suggester name string @@ -29,7 +29,7 @@ type PhraseSuggester struct { forceUnigrams *bool tokenLimit *int preTag, postTag *string - collateQuery *string + collateQuery *Script collatePreference *string collateParams map[string]interface{} collatePrune *bool @@ -154,8 +154,8 @@ func (q *PhraseSuggester) Highlight(preTag, postTag string) *PhraseSuggester { return q } -func (q *PhraseSuggester) CollateQuery(collateQuery string) *PhraseSuggester { - q.collateQuery = &collateQuery +func (q *PhraseSuggester) CollateQuery(collateQuery *Script) *PhraseSuggester { + q.collateQuery = collateQuery return q } @@ -213,7 +213,7 @@ func (q *PhraseSuggester) Source(includeName bool) (interface{}, error) { if err != nil { return nil, err } - suggester["context"] = src + suggester["contexts"] = src default: var ctxq []interface{} for _, query := range q.contextQueries { @@ -223,7 +223,7 @@ func (q *PhraseSuggester) Source(includeName bool) (interface{}, error) { } ctxq = append(ctxq, src) } - suggester["context"] = ctxq + suggester["contexts"] = ctxq } // Phase-specified parameters @@ -282,7 +282,11 @@ func (q *PhraseSuggester) Source(includeName bool) (interface{}, error) { collate := make(map[string]interface{}) suggester["collate"] = collate if q.collateQuery != nil { - collate["query"] = *q.collateQuery + src, err := q.collateQuery.Source() + if err != nil { + return nil, err + } + collate["query"] = src } if q.collatePreference != nil { collate["preference"] = *q.collatePreference @@ -312,7 +316,7 @@ type SmoothingModel interface { } // StupidBackoffSmoothingModel implements a stupid backoff smoothing model. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-phrase.html#_smoothing_models +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-phrase.html#_smoothing_models // for details about smoothing models. type StupidBackoffSmoothingModel struct { discount float64 @@ -337,7 +341,7 @@ func (sm *StupidBackoffSmoothingModel) Source() (interface{}, error) { // -- // LaplaceSmoothingModel implements a laplace smoothing model. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-phrase.html#_smoothing_models +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-phrase.html#_smoothing_models // for details about smoothing models. type LaplaceSmoothingModel struct { alpha float64 @@ -363,7 +367,7 @@ func (sm *LaplaceSmoothingModel) Source() (interface{}, error) { // LinearInterpolationSmoothingModel implements a linear interpolation // smoothing model. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-phrase.html#_smoothing_models +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-phrase.html#_smoothing_models // for details about smoothing models. type LinearInterpolationSmoothingModel struct { trigramLamda float64 @@ -399,7 +403,7 @@ type CandidateGenerator interface { } // DirectCandidateGenerator implements a direct candidate generator. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-phrase.html#_smoothing_models +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-phrase.html#_smoothing_models // for details about smoothing models. type DirectCandidateGenerator struct { field string diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggester_term.go b/vendor/gopkg.in/olivere/elastic.v6/suggester_term.go similarity index 97% rename from vendor/gopkg.in/olivere/elastic.v5/suggester_term.go rename to vendor/gopkg.in/olivere/elastic.v6/suggester_term.go index 9c199f69d9..3f5859cc0b 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/suggester_term.go +++ b/vendor/gopkg.in/olivere/elastic.v6/suggester_term.go @@ -6,7 +6,7 @@ package elastic // TermSuggester suggests terms based on edit distance. // For more details, see -// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-term.html. +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-term.html. type TermSuggester struct { Suggester name string @@ -178,7 +178,7 @@ func (q *TermSuggester) Source(includeName bool) (interface{}, error) { if err != nil { return nil, err } - suggester["context"] = src + suggester["contexts"] = src default: ctxq := make([]interface{}, len(q.contextQueries)) for i, query := range q.contextQueries { @@ -188,7 +188,7 @@ func (q *TermSuggester) Source(includeName bool) (interface{}, error) { } ctxq[i] = src } - suggester["context"] = ctxq + suggester["contexts"] = ctxq } // Specific to term suggester diff --git a/vendor/gopkg.in/olivere/elastic.v5/tasks_cancel.go b/vendor/gopkg.in/olivere/elastic.v6/tasks_cancel.go similarity index 54% rename from vendor/gopkg.in/olivere/elastic.v5/tasks_cancel.go rename to vendor/gopkg.in/olivere/elastic.v6/tasks_cancel.go index 2c74fd87ec..b2c56face5 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/tasks_cancel.go +++ b/vendor/gopkg.in/olivere/elastic.v6/tasks_cancel.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // TasksCancelService can cancel long-running tasks. @@ -19,54 +19,66 @@ import ( // See http://www.elastic.co/guide/en/elasticsearch/reference/5.2/tasks-cancel.html // for details. type TasksCancelService struct { - client *Client - pretty bool - taskId *int64 - actions []string - nodeId []string - parentNode string - parentTask *int64 + client *Client + pretty bool + taskId string + actions []string + nodeId []string + parentTaskId string } // NewTasksCancelService creates a new TasksCancelService. func NewTasksCancelService(client *Client) *TasksCancelService { return &TasksCancelService{ - client: client, - actions: make([]string, 0), - nodeId: make([]string, 0), + client: client, } } -// TaskId specifies the task to cancel. Set to -1 to cancel all tasks. -func (s *TasksCancelService) TaskId(taskId int64) *TasksCancelService { - s.taskId = &taskId +// TaskId specifies the task to cancel. Notice that the caller is responsible +// for using the correct format, i.e. node_id:task_number, as specified in +// the REST API. +func (s *TasksCancelService) TaskId(taskId string) *TasksCancelService { + s.taskId = taskId + return s +} + +// TaskIdFromNodeAndId specifies the task to cancel. Set id to -1 for all tasks. +func (s *TasksCancelService) TaskIdFromNodeAndId(nodeId string, id int64) *TasksCancelService { + // See https://github.com/elastic/elasticsearch/blob/6.7/server/src/main/java/org/elasticsearch/tasks/TaskId.java#L107-L118 + if id != -1 { + s.taskId = fmt.Sprintf("%s:%d", nodeId, id) + } return s } // Actions is a list of actions that should be cancelled. Leave empty to cancel all. -func (s *TasksCancelService) Actions(actions []string) *TasksCancelService { - s.actions = actions +func (s *TasksCancelService) Actions(actions ...string) *TasksCancelService { + s.actions = append(s.actions, actions...) 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 *TasksCancelService) NodeId(nodeId []string) *TasksCancelService { - s.nodeId = nodeId +func (s *TasksCancelService) NodeId(nodeId ...string) *TasksCancelService { + s.nodeId = append(s.nodeId, nodeId...) return s } -// ParentNode specifies to cancel tasks with specified parent node. -func (s *TasksCancelService) ParentNode(parentNode string) *TasksCancelService { - s.parentNode = parentNode +// ParentTaskId specifies to cancel tasks with specified parent task id. +// Notice that the caller is responsible for using the correct format, +// i.e. node_id:task_number, as specified in the REST API. +func (s *TasksCancelService) ParentTaskId(parentTaskId string) *TasksCancelService { + s.parentTaskId = parentTaskId return s } -// ParentTask specifies to cancel tasks with specified parent task id. -// Set to -1 to cancel all. -func (s *TasksCancelService) ParentTask(parentTask int64) *TasksCancelService { - s.parentTask = &parentTask +// ParentTaskIdFromNodeAndId specifies to cancel tasks with specified parent task id. +func (s *TasksCancelService) ParentTaskIdFromNodeAndId(nodeId string, id int64) *TasksCancelService { + // See https://github.com/elastic/elasticsearch/blob/6.7/server/src/main/java/org/elasticsearch/tasks/TaskId.java#L107-L118 + if id != -1 { + s.parentTaskId = fmt.Sprintf("%s:%d", nodeId, id) + } return s } @@ -81,9 +93,9 @@ func (s *TasksCancelService) buildURL() (string, url.Values, error) { // Build URL var err error var path string - if s.taskId != nil { + if s.taskId != "" { path, err = uritemplates.Expand("/_tasks/{task_id}/_cancel", map[string]string{ - "task_id": fmt.Sprintf("%d", *s.taskId), + "task_id": s.taskId, }) } else { path = "/_tasks/_cancel" @@ -95,7 +107,7 @@ func (s *TasksCancelService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if len(s.actions) > 0 { params.Set("actions", strings.Join(s.actions, ",")) @@ -103,11 +115,8 @@ func (s *TasksCancelService) buildURL() (string, url.Values, error) { if len(s.nodeId) > 0 { params.Set("node_id", strings.Join(s.nodeId, ",")) } - if s.parentNode != "" { - params.Set("parent_node", s.parentNode) - } - if s.parentTask != nil { - params.Set("parent_task", fmt.Sprintf("%v", *s.parentTask)) + if s.parentTaskId != "" { + params.Set("parent_task_id", s.parentTaskId) } return path, params, nil } @@ -131,7 +140,11 @@ func (s *TasksCancelService) Do(ctx context.Context) (*TasksListResponse, error) } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/tasks_get_task.go b/vendor/gopkg.in/olivere/elastic.v6/tasks_get_task.go similarity index 70% rename from vendor/gopkg.in/olivere/elastic.v5/tasks_get_task.go rename to vendor/gopkg.in/olivere/elastic.v6/tasks_get_task.go index 5368169ece..072ee1475e 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/tasks_get_task.go +++ b/vendor/gopkg.in/olivere/elastic.v6/tasks_get_task.go @@ -3,9 +3,10 @@ package elastic import ( "context" "fmt" + "net/http" "net/url" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // TasksGetTaskService retrieves the state of a task in the cluster. It is part of the Task Management API @@ -17,6 +18,7 @@ type TasksGetTaskService struct { pretty bool taskId string waitForCompletion *bool + headers http.Header } // NewTasksGetTaskService creates a new TasksGetTaskService. @@ -26,12 +28,20 @@ func NewTasksGetTaskService(client *Client) *TasksGetTaskService { } } -// TaskId indicates to return the task with specified id. +// TaskId specifies the task to return. Notice that the caller is responsible +// for using the correct format, i.e. node_id:task_number, as specified in +// the REST API. func (s *TasksGetTaskService) TaskId(taskId string) *TasksGetTaskService { s.taskId = taskId return s } +// TaskIdFromNodeAndId indicates to return the task on the given node with specified id. +func (s *TasksGetTaskService) TaskIdFromNodeAndId(nodeId string, id int64) *TasksGetTaskService { + s.taskId = fmt.Sprintf("%s:%d", nodeId, id) + return s +} + // WaitForCompletion indicates whether to wait for the matching tasks // to complete (default: false). func (s *TasksGetTaskService) WaitForCompletion(waitForCompletion bool) *TasksGetTaskService { @@ -39,6 +49,15 @@ func (s *TasksGetTaskService) WaitForCompletion(waitForCompletion bool) *TasksGe return s } +// Header sets headers on the request +func (s *TasksGetTaskService) Header(name string, value string) *TasksGetTaskService { + if s.headers == nil { + s.headers = http.Header{} + } + s.headers.Add(name, value) + return s +} + // Pretty indicates that the JSON response be indented and human readable. func (s *TasksGetTaskService) Pretty(pretty bool) *TasksGetTaskService { s.pretty = pretty @@ -85,7 +104,12 @@ func (s *TasksGetTaskService) Do(ctx context.Context) (*TasksGetTaskResponse, er } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + Headers: s.headers, + }) if err != nil { return nil, err } @@ -95,10 +119,12 @@ func (s *TasksGetTaskService) Do(ctx context.Context) (*TasksGetTaskResponse, er if err := s.client.decoder.Decode(res.Body, ret); err != nil { return nil, err } + ret.Header = res.Header return ret, nil } type TasksGetTaskResponse struct { - Completed bool `json:"completed"` - Task *TaskInfo `json:"task,omitempty"` + Header http.Header `json:"-"` + Completed bool `json:"completed"` + Task *TaskInfo `json:"task,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/tasks_list.go b/vendor/gopkg.in/olivere/elastic.v6/tasks_list.go similarity index 69% rename from vendor/gopkg.in/olivere/elastic.v5/tasks_list.go rename to vendor/gopkg.in/olivere/elastic.v6/tasks_list.go index 6cad558afc..0759e62f5a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/tasks_list.go +++ b/vendor/gopkg.in/olivere/elastic.v6/tasks_list.go @@ -7,15 +7,16 @@ package elastic import ( "context" "fmt" + "net/http" "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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 https://www.elastic.co/guide/en/elasticsearch/reference/5.6/tasks.html. +// documented at https://www.elastic.co/guide/en/elasticsearch/reference/6.8/tasks.html. // // It is supported as of Elasticsearch 2.3.0. type TasksListService struct { @@ -24,11 +25,12 @@ type TasksListService struct { taskId []string actions []string detailed *bool + human *bool nodeId []string - parentNode string - parentTaskId *string + parentTaskId string waitForCompletion *bool groupBy string + headers http.Header } // NewTasksListService creates a new TasksListService. @@ -39,6 +41,8 @@ func NewTasksListService(client *Client) *TasksListService { } // TaskId indicates to returns the task(s) with specified id(s). +// Notice that the caller is responsible for using the correct format, +// i.e. node_id:task_number, as specified in the REST API. func (s *TasksListService) TaskId(taskId ...string) *TasksListService { s.taskId = append(s.taskId, taskId...) return s @@ -56,6 +60,12 @@ func (s *TasksListService) Detailed(detailed bool) *TasksListService { return s } +// Human indicates whether to return time and byte values in human-readable format. +func (s *TasksListService) Human(human bool) *TasksListService { + s.human = &human + 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. @@ -64,15 +74,11 @@ func (s *TasksListService) NodeId(nodeId ...string) *TasksListService { return s } -// ParentNode returns tasks with specified parent node. -func (s *TasksListService) ParentNode(parentNode string) *TasksListService { - s.parentNode = parentNode - return s -} - -// ParentTaskId returns tasks with specified parent task id (node_id:task_number). Set to -1 to return all. +// ParentTaskId returns tasks with specified parent task id. +// Notice that the caller is responsible for using the correct format, +// i.e. node_id:task_number, as specified in the REST API. func (s *TasksListService) ParentTaskId(parentTaskId string) *TasksListService { - s.parentTaskId = &parentTaskId + s.parentTaskId = parentTaskId return s } @@ -84,12 +90,21 @@ func (s *TasksListService) WaitForCompletion(waitForCompletion bool) *TasksListS } // GroupBy groups tasks by nodes or parent/child relationships. -// As of now, it can either be "nodes" (default) or "parents". +// As of now, it can either be "nodes" (default) or "parents" or "none". func (s *TasksListService) GroupBy(groupBy string) *TasksListService { s.groupBy = groupBy return s } +// Header sets headers on the request +func (s *TasksListService) Header(name string, value string) *TasksListService { + if s.headers == nil { + s.headers = http.Header{} + } + s.headers.Add(name, value) + return s +} + // Pretty indicates that the JSON response be indented and human readable. func (s *TasksListService) Pretty(pretty bool) *TasksListService { s.pretty = pretty @@ -115,7 +130,7 @@ func (s *TasksListService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if len(s.actions) > 0 { params.Set("actions", strings.Join(s.actions, ",")) @@ -123,14 +138,14 @@ func (s *TasksListService) buildURL() (string, url.Values, error) { if s.detailed != nil { params.Set("detailed", fmt.Sprintf("%v", *s.detailed)) } + if s.human != nil { + params.Set("human", fmt.Sprintf("%v", *s.human)) + } if len(s.nodeId) > 0 { params.Set("node_id", strings.Join(s.nodeId, ",")) } - if s.parentNode != "" { - params.Set("parent_node", s.parentNode) - } - if s.parentTaskId != nil { - params.Set("parent_task_id", *s.parentTaskId) + if s.parentTaskId != "" { + params.Set("parent_task_id", s.parentTaskId) } if s.waitForCompletion != nil { params.Set("wait_for_completion", fmt.Sprintf("%v", *s.waitForCompletion)) @@ -160,7 +175,12 @@ func (s *TasksListService) Do(ctx context.Context) (*TasksListResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, nil) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + Headers: s.headers, + }) if err != nil { return nil, err } @@ -170,11 +190,13 @@ func (s *TasksListService) Do(ctx context.Context) (*TasksListResponse, error) { if err := s.client.decoder.Decode(res.Body, ret); err != nil { return nil, err } + ret.Header = res.Header return ret, nil } // TasksListResponse is the response of TasksListService.Do. type TasksListResponse struct { + Header http.Header `json:"-"` TaskFailures []*TaskOperationFailure `json:"task_failures"` NodeFailures []*FailedNodeException `json:"node_failures"` // Nodes returns the tasks per node. The key is the node id. @@ -206,22 +228,24 @@ type DiscoveryNode struct { // TaskInfo represents information about a currently running task. type TaskInfo struct { - Node string `json:"node"` - Id int64 `json:"id"` // the task id (yes, this is a long in the Java source) - Type string `json:"type"` - Action string `json:"action"` - Status interface{} `json:"status"` // has separate implementations of Task.Status in Java for reindexing, replication, and "RawTaskStatus" - Description interface{} `json:"description"` // same as Status - StartTime string `json:"start_time"` - StartTimeInMillis int64 `json:"start_time_in_millis"` - RunningTime string `json:"running_time"` - RunningTimeInNanos int64 `json:"running_time_in_nanos"` - Cancellable bool `json:"cancellable"` - ParentTaskId string `json:"parent_task_id"` // like "YxJnVYjwSBm_AUbzddTajQ:12356" + Node string `json:"node"` + Id int64 `json:"id"` // the task id (yes, this is a long in the Java source) + Type string `json:"type"` + Action string `json:"action"` + Status interface{} `json:"status"` // has separate implementations of Task.Status in Java for reindexing, replication, and "RawTaskStatus" + Description interface{} `json:"description"` // same as Status + StartTime string `json:"start_time"` + StartTimeInMillis int64 `json:"start_time_in_millis"` + RunningTime string `json:"running_time"` + RunningTimeInNanos int64 `json:"running_time_in_nanos"` + Cancellable bool `json:"cancellable"` + ParentTaskId string `json:"parent_task_id"` // like "YxJnVYjwSBm_AUbzddTajQ:12356" + Headers map[string]string `json:"headers"` } // StartTaskResult is used in cases where a task gets started asynchronously and // the operation simply returnes a TaskID to watch for via the Task Management API. type StartTaskResult struct { - TaskId string `json:"task"` + Header http.Header `json:"-"` + TaskId string `json:"task"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/termvectors.go b/vendor/gopkg.in/olivere/elastic.v6/termvectors.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/termvectors.go rename to vendor/gopkg.in/olivere/elastic.v6/termvectors.go index 6bbcf8f3b9..64689c025a 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/termvectors.go +++ b/vendor/gopkg.in/olivere/elastic.v6/termvectors.go @@ -10,14 +10,14 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/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/5.2/docs-termvectors.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-termvectors.html // for documentation. type TermvectorsService struct { client *Client @@ -169,7 +169,7 @@ func (s *TermvectorsService) Version(version interface{}) *TermvectorsService { return s } -// VersionType specifies a version type ("internal", "external", "external_gte", or "force"). +// VersionType specifies a version type ("internal", "external", or "external_gte"). func (s *TermvectorsService) VersionType(versionType string) *TermvectorsService { s.versionType = versionType return s @@ -217,7 +217,7 @@ func (s *TermvectorsService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if s.dfs != nil { params.Set("dfs", fmt.Sprintf("%v", *s.dfs)) @@ -316,7 +316,12 @@ func (s *TermvectorsService) Do(ctx context.Context) (*TermvectorsResponse, erro } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -333,7 +338,7 @@ func (s *TermvectorsService) Do(ctx context.Context) (*TermvectorsResponse, erro // 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/5.2/docs-termvectors.html#_terms_filtering +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-termvectors.html#_terms_filtering // for more information. type TermvectorsFilterSettings struct { maxNumTerms *int64 diff --git a/vendor/gopkg.in/olivere/elastic.v5/update.go b/vendor/gopkg.in/olivere/elastic.v6/update.go similarity index 83% rename from vendor/gopkg.in/olivere/elastic.v5/update.go rename to vendor/gopkg.in/olivere/elastic.v6/update.go index c3d075f466..6f664f4359 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/update.go +++ b/vendor/gopkg.in/olivere/elastic.v6/update.go @@ -10,11 +10,11 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // UpdateService updates a document in Elasticsearch. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-update.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update.html // for details. type UpdateService struct { client *Client @@ -37,6 +37,8 @@ type UpdateService struct { detectNoop *bool doc interface{} timeout string + ifSeqNo *int64 + ifPrimaryTerm *int64 pretty bool } @@ -105,13 +107,16 @@ func (b *UpdateService) Version(version int64) *UpdateService { return b } -// VersionType is one of "internal" or "force". +// VersionType is e.g. "internal". func (b *UpdateService) VersionType(versionType string) *UpdateService { b.versionType = versionType return b } // Refresh the index after performing the update. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html +// for details. func (b *UpdateService) Refresh(refresh string) *UpdateService { b.refresh = refresh return b @@ -167,6 +172,20 @@ func (b *UpdateService) Timeout(timeout string) *UpdateService { return b } +// IfSeqNo indicates to only perform the update operation if the last +// operation that has changed the document has the specified sequence number. +func (b *UpdateService) IfSeqNo(seqNo int64) *UpdateService { + b.ifSeqNo = &seqNo + return b +} + +// IfPrimaryTerm indicates to only perform the update operation if the +// last operation that has changed the document has the specified primary term. +func (b *UpdateService) IfPrimaryTerm(primaryTerm int64) *UpdateService { + b.ifPrimaryTerm = &primaryTerm + return b +} + // Pretty instructs to return human readable, prettified JSON. func (b *UpdateService) Pretty(pretty bool) *UpdateService { b.pretty = pretty @@ -235,6 +254,12 @@ func (b *UpdateService) url() (string, url.Values, error) { if b.retryOnConflict != nil { params.Set("retry_on_conflict", fmt.Sprintf("%v", *b.retryOnConflict)) } + if v := b.ifSeqNo; v != nil { + params.Set("if_seq_no", fmt.Sprintf("%d", *v)) + } + if v := b.ifPrimaryTerm; v != nil { + params.Set("if_primary_term", fmt.Sprintf("%d", *v)) + } return path, params, nil } @@ -293,7 +318,12 @@ func (b *UpdateService) Do(ctx context.Context) (*UpdateResponse, error) { } // Get response - res, err := b.client.PerformRequest(ctx, "POST", path, params, body) + res, err := b.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } @@ -308,12 +338,15 @@ func (b *UpdateService) Do(ctx context.Context) (*UpdateResponse, error) { // UpdateResponse is the result of updating a document in Elasticsearch. type UpdateResponse struct { - Index string `json:"_index"` - Type string `json:"_type"` - Id string `json:"_id"` - Version int `json:"_version"` - Shards *ShardsInfo `json:"_shards"` + Index string `json:"_index,omitempty"` + Type string `json:"_type,omitempty"` + Id string `json:"_id,omitempty"` + Version int64 `json:"_version,omitempty"` Result string `json:"result,omitempty"` + Shards *ShardsInfo `json:"_shards,omitempty"` + SeqNo int64 `json:"_seq_no,omitempty"` + PrimaryTerm int64 `json:"_primary_term,omitempty"` + Status int `json:"status,omitempty"` ForcedRefresh bool `json:"forced_refresh,omitempty"` GetResult *GetResult `json:"get,omitempty"` } diff --git a/vendor/gopkg.in/olivere/elastic.v5/update_by_query.go b/vendor/gopkg.in/olivere/elastic.v6/update_by_query.go similarity index 94% rename from vendor/gopkg.in/olivere/elastic.v5/update_by_query.go rename to vendor/gopkg.in/olivere/elastic.v6/update_by_query.go index 509e7d8628..733a965a83 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/update_by_query.go +++ b/vendor/gopkg.in/olivere/elastic.v6/update_by_query.go @@ -7,10 +7,11 @@ package elastic import ( "context" "fmt" + "net/http" "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // UpdateByQueryService is documented at https://www.elastic.co/guide/en/elasticsearch/plugins/master/plugins-reindex.html. @@ -51,6 +52,7 @@ type UpdateByQueryService struct { searchTimeout string searchType string size *int + slices interface{} sort []string stats []string storedFields []string @@ -259,6 +261,9 @@ func (s *UpdateByQueryService) Query(query Query) *UpdateByQueryService { } // Refresh indicates whether the effected indexes should be refreshed. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-refresh.html +// for details. func (s *UpdateByQueryService) Refresh(refresh string) *UpdateByQueryService { s.refresh = refresh return s @@ -317,6 +322,16 @@ func (s *UpdateByQueryService) Size(size int) *UpdateByQueryService { return s } +// Slices represents the number of slices (default: 1). +// It used to be a number, but can be set to "auto" as of 6.7. +// +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update-by-query.html#docs-update-by-query-slice +// for details. +func (s *UpdateByQueryService) Slices(slices interface{}) *UpdateByQueryService { + s.slices = slices + return s +} + // Sort is a list of : pairs. func (s *UpdateByQueryService) Sort(sort ...string) *UpdateByQueryService { s.sort = append(s.sort, sort...) @@ -447,7 +462,7 @@ func (s *UpdateByQueryService) buildURL() (string, url.Values, error) { // Add query string parameters params := url.Values{} if s.pretty { - params.Set("pretty", "1") + params.Set("pretty", "true") } if len(s.xSource) > 0 { params.Set("_source", strings.Join(s.xSource, ",")) @@ -536,6 +551,9 @@ func (s *UpdateByQueryService) buildURL() (string, url.Values, error) { if s.size != nil { params.Set("size", fmt.Sprintf("%d", *s.size)) } + if s.slices != nil { + params.Set("slices", fmt.Sprintf("%v", s.slices)) + } if len(s.sort) > 0 { params.Set("sort", strings.Join(s.sort, ",")) } @@ -636,7 +654,13 @@ func (s *UpdateByQueryService) Do(ctx context.Context) (*BulkIndexByScrollRespon } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + IgnoreErrors: []int{http.StatusConflict}, + }) if err != nil { return nil, err } @@ -649,7 +673,7 @@ func (s *UpdateByQueryService) Do(ctx context.Context) (*BulkIndexByScrollRespon return ret, nil } -// DoAsync executes the reindexing operation asynchronously by starting a new task. +// DoAsync executes the update-by-query operation asynchronously by starting a new task. // Callers need to use the Task Management API to watch the outcome of the reindexing // operation. func (s *UpdateByQueryService) DoAsync(ctx context.Context) (*StartTaskResult, error) { @@ -678,7 +702,13 @@ func (s *UpdateByQueryService) DoAsync(ctx context.Context) (*StartTaskResult, e } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "POST", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + Body: body, + IgnoreErrors: []int{http.StatusConflict}, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v5/validate.go b/vendor/gopkg.in/olivere/elastic.v6/validate.go similarity index 96% rename from vendor/gopkg.in/olivere/elastic.v5/validate.go rename to vendor/gopkg.in/olivere/elastic.v6/validate.go index 69a43cdd98..2f509150bb 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/validate.go +++ b/vendor/gopkg.in/olivere/elastic.v6/validate.go @@ -10,12 +10,12 @@ import ( "net/url" "strings" - "gopkg.in/olivere/elastic.v5/uritemplates" + "github.com/olivere/elastic/uritemplates" ) // ValidateService allows a user to validate a potentially // expensive query without executing it. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-validate.html. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-validate.html. type ValidateService struct { client *Client pretty bool @@ -259,7 +259,12 @@ func (s *ValidateService) Do(ctx context.Context) (*ValidateResponse, error) { } // Get HTTP response - res, err := s.client.PerformRequest(ctx, "GET", path, params, body) + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + Body: body, + }) if err != nil { return nil, err } diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_delete_lifecycle.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_delete_lifecycle.go new file mode 100644 index 0000000000..5baca2042c --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_delete_lifecycle.go @@ -0,0 +1,142 @@ +// 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 ( + "context" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// See the documentation at +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/ilm-get-lifecycle.html. +type XPackIlmDeleteLifecycleService struct { + client *Client + policy string + pretty bool + timeout string + masterTimeout string + flatSettings *bool + local *bool +} + +// NewXPackIlmDeleteLifecycleService creates a new XPackIlmDeleteLifecycleService. +func NewXPackIlmDeleteLifecycleService(client *Client) *XPackIlmDeleteLifecycleService { + return &XPackIlmDeleteLifecycleService{ + client: client, + } +} + +// Policy is the name of the index lifecycle policy. +func (s *XPackIlmDeleteLifecycleService) Policy(policy string) *XPackIlmDeleteLifecycleService { + s.policy = policy + return s +} + +// Timeout is an explicit operation timeout. +func (s *XPackIlmDeleteLifecycleService) Timeout(timeout string) *XPackIlmDeleteLifecycleService { + s.timeout = timeout + return s +} + +// MasterTimeout specifies the timeout for connection to master. +func (s *XPackIlmDeleteLifecycleService) MasterTimeout(masterTimeout string) *XPackIlmDeleteLifecycleService { + s.masterTimeout = masterTimeout + return s +} + +// FlatSettings is returns settings in flat format (default: false). +func (s *XPackIlmDeleteLifecycleService) FlatSettings(flatSettings bool) *XPackIlmDeleteLifecycleService { + s.flatSettings = &flatSettings + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackIlmDeleteLifecycleService) Pretty(pretty bool) *XPackIlmDeleteLifecycleService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackIlmDeleteLifecycleService) buildURL() (string, url.Values, error) { + // Build URL + var err error + var path string + path, err = uritemplates.Expand("/_ilm/policy/{policy}", map[string]string{ + "policy": s.policy, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + if s.flatSettings != nil { + params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings)) + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + 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 *XPackIlmDeleteLifecycleService) Validate() error { + var invalid []string + if s.policy == "" { + invalid = append(invalid, "Policy") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackIlmDeleteLifecycleService) Do(ctx context.Context) (*XPackIlmDeleteLifecycleResponse, error) { + // Check pre-conditions + if err := s.Validate(); err != nil { + return nil, err + } + + // Delete URL for request + path, params, err := s.buildURL() + if err != nil { + return nil, err + } + + // Delete HTTP response + res, err := s.client.PerformRequest(ctx, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackIlmDeleteLifecycleResponse) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackIlmDeleteLifecycleResponse is the response of XPackIlmDeleteLifecycleService.Do. +type XPackIlmDeleteLifecycleResponse struct { + Acknowledged bool `json:"acknowledged"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_get_lifecycle.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_get_lifecycle.go new file mode 100644 index 0000000000..45b5348d18 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_get_lifecycle.go @@ -0,0 +1,142 @@ +// 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 ( + "context" + "fmt" + "net/url" + "strings" + + "github.com/olivere/elastic/uritemplates" +) + +// See the documentation at +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/ilm-get-lifecycle.html. +type XPackIlmGetLifecycleService struct { + client *Client + policy []string + pretty bool + timeout string + masterTimeout string + flatSettings *bool + local *bool +} + +// NewXPackIlmGetLifecycleService creates a new XPackIlmGetLifecycleService. +func NewXPackIlmGetLifecycleService(client *Client) *XPackIlmGetLifecycleService { + return &XPackIlmGetLifecycleService{ + client: client, + } +} + +// Policy is the name of the index lifecycle policy. +func (s *XPackIlmGetLifecycleService) Policy(policies ...string) *XPackIlmGetLifecycleService { + s.policy = append(s.policy, policies...) + return s +} + +// Timeout is an explicit operation timeout. +func (s *XPackIlmGetLifecycleService) Timeout(timeout string) *XPackIlmGetLifecycleService { + s.timeout = timeout + return s +} + +// MasterTimeout specifies the timeout for connection to master. +func (s *XPackIlmGetLifecycleService) MasterTimeout(masterTimeout string) *XPackIlmGetLifecycleService { + s.masterTimeout = masterTimeout + return s +} + +// FlatSettings is returns settings in flat format (default: false). +func (s *XPackIlmGetLifecycleService) FlatSettings(flatSettings bool) *XPackIlmGetLifecycleService { + s.flatSettings = &flatSettings + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackIlmGetLifecycleService) Pretty(pretty bool) *XPackIlmGetLifecycleService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackIlmGetLifecycleService) buildURL() (string, url.Values, error) { + // Build URL + var err error + var path string + if len(s.policy) > 0 { + path, err = uritemplates.Expand("/_ilm/policy/{policy}", map[string]string{ + "policy": strings.Join(s.policy, ","), + }) + } else { + path = "/_ilm/policy" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + if s.flatSettings != nil { + params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings)) + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + 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 *XPackIlmGetLifecycleService) Validate() error { + return nil +} + +// Do executes the operation. +func (s *XPackIlmGetLifecycleService) Do(ctx context.Context) (map[string]*XPackIlmGetLifecycleResponse, 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, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + var ret map[string]*XPackIlmGetLifecycleResponse + if err := s.client.decoder.Decode(res.Body, &ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackIlmGetLifecycleResponse is the response of XPackIlmGetLifecycleService.Do. +type XPackIlmGetLifecycleResponse struct { + Version int `json:"version,omitempty"` + ModifiedDate int `json:"modified,omitempty"` + Policy map[string]interface{} `json:"policy,omitempty"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_put_lifecycle.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_put_lifecycle.go new file mode 100644 index 0000000000..fb5934b661 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_ilm_put_lifecycle.go @@ -0,0 +1,162 @@ +// 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 ( + "context" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// See the documentation at +// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/ilm-put-lifecycle.html +type XPackIlmPutLifecycleService struct { + client *Client + policy string + pretty bool + timeout string + masterTimeout string + flatSettings *bool + bodyJson interface{} + bodyString string +} + +// NewXPackIlmPutLifecycleService creates a new XPackIlmPutLifecycleService. +func NewXPackIlmPutLifecycleService(client *Client) *XPackIlmPutLifecycleService { + return &XPackIlmPutLifecycleService{ + client: client, + } +} + +// Policy is the name of the index lifecycle policy. +func (s *XPackIlmPutLifecycleService) Policy(policy string) *XPackIlmPutLifecycleService { + s.policy = policy + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackIlmPutLifecycleService) Pretty(pretty bool) *XPackIlmPutLifecycleService { + s.pretty = pretty + return s +} + +// Timeout is an explicit operation timeout. +func (s *XPackIlmPutLifecycleService) Timeout(timeout string) *XPackIlmPutLifecycleService { + s.timeout = timeout + return s +} + +// MasterTimeout specifies the timeout for connection to master. +func (s *XPackIlmPutLifecycleService) MasterTimeout(masterTimeout string) *XPackIlmPutLifecycleService { + s.masterTimeout = masterTimeout + return s +} + +// FlatSettings indicates whether to return settings in flat format (default: false). +func (s *XPackIlmPutLifecycleService) FlatSettings(flatSettings bool) *XPackIlmPutLifecycleService { + s.flatSettings = &flatSettings + return s +} + +// BodyJson is documented as: The template definition. +func (s *XPackIlmPutLifecycleService) BodyJson(body interface{}) *XPackIlmPutLifecycleService { + s.bodyJson = body + return s +} + +// BodyString is documented as: The template definition. +func (s *XPackIlmPutLifecycleService) BodyString(body string) *XPackIlmPutLifecycleService { + s.bodyString = body + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackIlmPutLifecycleService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_ilm/policy/{policy}", map[string]string{ + "policy": s.policy, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + if s.timeout != "" { + params.Set("timeout", s.timeout) + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if s.flatSettings != nil { + params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings)) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackIlmPutLifecycleService) Validate() error { + var invalid []string + if s.policy == "" { + invalid = append(invalid, "Policy") + } + 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 *XPackIlmPutLifecycleService) Do(ctx context.Context) (*XPackIlmPutLifecycleResponse, 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, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: body, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackIlmPutLifecycleResponse) + if err := s.client.decoder.Decode(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackIlmPutLifecycleSResponse is the response of XPackIlmPutLifecycleService.Do. +type XPackIlmPutLifecycleResponse struct { + Acknowledged bool `json:"acknowledged"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_info.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_info.go new file mode 100644 index 0000000000..5f5d3c63ab --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_info.go @@ -0,0 +1,175 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackInfoService retrieves xpack info. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/info-api.html. +type XPackInfoService struct { + client *Client + pretty bool + name string +} + +// NewXPackInfoService creates a new XPackInfoService. +func NewXPackInfoService(client *Client) *XPackInfoService { + return &XPackInfoService{ + client: client, + } +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackInfoService) Pretty(pretty bool) *XPackInfoService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackInfoService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack", map[string]string{}) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackInfoService) Validate() error { + var invalid []string + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackInfoService) Do(ctx context.Context) (*XPackInfoServiceResponse, 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, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := XPackInfoServiceResponse{} + if err := json.Unmarshal(res.Body, &ret); err != nil { + return nil, err + } + return &ret, nil +} + +// XPackInfoServiceResponse is the response of XPackInfoService.Do. +type XPackInfoServiceResponse struct { + Build XPackInfoBuild `json:"build"` + License XPackInfoLicense `json:"license"` + Features XPackInfoFeatures `json:"features"` + Tagline string `json:"tagline"` +} + +// XPackInfoBuild is the xpack build info +type XPackInfoBuild struct { + Hash string `json:"hash"` + Date string `json:"date"` +} + +// XPackInfoLicense is the xpack license info +type XPackInfoLicense struct { + UID string `json:"uid"` + Type string `json:"type"` + Mode string `json:"mode"` + Status string `json:"status"` + ExpiryMilis int `json:"expiry_date_in_millis"` +} + +// XPackInfoFeatures is the xpack feature info object +type XPackInfoFeatures struct { + Graph XPackInfoGraph `json:"graph"` + Logstash XPackInfoLogstash `json:"logstash"` + MachineLearning XPackInfoML `json:"ml"` + Monitoring XPackInfoMonitoring `json:"monitoring"` + Rollup XPackInfoRollup `json:"rollup"` + Security XPackInfoSecurity `json:"security"` + Watcher XPackInfoWatcher `json:"watcher"` +} + +// XPackInfoGraph is the xpack graph plugin info +type XPackInfoGraph struct { + Description string `json:"description"` + Available bool `json:"available"` + Enabled bool `json:"enabled"` +} + +// XPackInfoLogstash is the xpack logstash plugin info +type XPackInfoLogstash struct { + Description string `json:"description"` + Available bool `json:"available"` + Enabled bool `json:"enabled"` +} + +// XPackInfoML is the xpack machine learning plugin info +type XPackInfoML struct { + Description string `json:"description"` + Available bool `json:"available"` + Enabled bool `json:"enabled"` + NativeCodeInfo map[string]string `json:"native_code_info"` +} + +// XPackInfoMonitoring is the xpack monitoring plugin info +type XPackInfoMonitoring struct { + Description string `json:"description"` + Available bool `json:"available"` + Enabled bool `json:"enabled"` +} + +// XPackInfoRollup is the xpack rollup plugin info +type XPackInfoRollup struct { + Description string `json:"description"` + Available bool `json:"available"` + Enabled bool `json:"enabled"` +} + +// XPackInfoSecurity is the xpack security plugin info +type XPackInfoSecurity struct { + Description string `json:"description"` + Available bool `json:"available"` + Enabled bool `json:"enabled"` +} + +// XPackInfoWatcher is the xpack watcher plugin info +type XPackInfoWatcher struct { + Description string `json:"description"` + Available bool `json:"available"` + Enabled bool `json:"enabled"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_security_delete_role.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_delete_role.go new file mode 100644 index 0000000000..3cccb20662 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_delete_role.go @@ -0,0 +1,107 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackSecurityDeleteRoleService delete a role by its name. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/security-api-delete-role.html. +type XPackSecurityDeleteRoleService struct { + client *Client + pretty bool + name string +} + +// NewXPackSecurityDeleteRoleService creates a new XPackSecurityDeleteRoleService. +func NewXPackSecurityDeleteRoleService(client *Client) *XPackSecurityDeleteRoleService { + return &XPackSecurityDeleteRoleService{ + client: client, + } +} + +// Name is name of the role to delete. +func (s *XPackSecurityDeleteRoleService) Name(name string) *XPackSecurityDeleteRoleService { + s.name = name + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackSecurityDeleteRoleService) Pretty(pretty bool) *XPackSecurityDeleteRoleService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackSecurityDeleteRoleService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/security/role/{name}", map[string]string{ + "name": s.name, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackSecurityDeleteRoleService) Validate() error { + var invalid []string + if s.name == "" { + invalid = append(invalid, "Name") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackSecurityDeleteRoleService) Do(ctx context.Context) (*XPackSecurityDeleteRoleResponse, 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, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackSecurityDeleteRoleResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackSecurityDeleteRoleResponse is the response of XPackSecurityDeleteRoleService.Do. +type XPackSecurityDeleteRoleResponse struct { + Found bool `json:"found"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_security_delete_role_mapping.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_delete_role_mapping.go new file mode 100644 index 0000000000..0858a6df99 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_delete_role_mapping.go @@ -0,0 +1,107 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackSecurityDeleteRoleMappingService delete a role mapping by its name. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/security-api-delete-role-mapping.html. +type XPackSecurityDeleteRoleMappingService struct { + client *Client + pretty bool + name string +} + +// NewXPackSecurityDeleteRoleMappingService creates a new XPackSecurityDeleteRoleMappingService. +func NewXPackSecurityDeleteRoleMappingService(client *Client) *XPackSecurityDeleteRoleMappingService { + return &XPackSecurityDeleteRoleMappingService{ + client: client, + } +} + +// Name is name of the role mapping to delete. +func (s *XPackSecurityDeleteRoleMappingService) Name(name string) *XPackSecurityDeleteRoleMappingService { + s.name = name + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackSecurityDeleteRoleMappingService) Pretty(pretty bool) *XPackSecurityDeleteRoleMappingService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackSecurityDeleteRoleMappingService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/security/role_mapping/{name}", map[string]string{ + "name": s.name, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackSecurityDeleteRoleMappingService) Validate() error { + var invalid []string + if s.name == "" { + invalid = append(invalid, "Name") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackSecurityDeleteRoleMappingService) Do(ctx context.Context) (*XPackSecurityDeleteRoleMappingResponse, 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, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackSecurityDeleteRoleMappingResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackSecurityDeleteRoleMappingResponse is the response of XPackSecurityDeleteRoleMappingService.Do. +type XPackSecurityDeleteRoleMappingResponse struct { + Found bool `json:"found"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_security_get_role.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_get_role.go new file mode 100644 index 0000000000..68ce72927d --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_get_role.go @@ -0,0 +1,134 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackSecurityGetRoleService retrieves a role by its name. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/security-api-get-role.html. +type XPackSecurityGetRoleService struct { + client *Client + pretty bool + name string +} + +// NewXPackSecurityGetRoleService creates a new XPackSecurityGetRoleService. +func NewXPackSecurityGetRoleService(client *Client) *XPackSecurityGetRoleService { + return &XPackSecurityGetRoleService{ + client: client, + } +} + +// Name is name of the role to retrieve. +func (s *XPackSecurityGetRoleService) Name(name string) *XPackSecurityGetRoleService { + s.name = name + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackSecurityGetRoleService) Pretty(pretty bool) *XPackSecurityGetRoleService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackSecurityGetRoleService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/security/role/{name}", map[string]string{ + "name": s.name, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackSecurityGetRoleService) Validate() error { + var invalid []string + if s.name == "" { + invalid = append(invalid, "Name") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackSecurityGetRoleService) Do(ctx context.Context) (*XPackSecurityGetRoleResponse, 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, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := XPackSecurityGetRoleResponse{} + if err := json.Unmarshal(res.Body, &ret); err != nil { + return nil, err + } + return &ret, nil +} + +// XPackSecurityGetRoleResponse is the response of XPackSecurityGetRoleService.Do. +type XPackSecurityGetRoleResponse map[string]XPackSecurityRole + +// XPackSecurityRole is the role object. +// +// The Java source for this struct is defined here: +// https://github.com/elastic/elasticsearch/blob/6.7/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/RoleDescriptor.java +type XPackSecurityRole struct { + Cluster []string `json:"cluster"` + Indices []XPackSecurityIndicesPermissions `json:"indices"` + Applications []XPackSecurityApplicationPrivileges `json:"applications"` + RunAs []string `json:"run_as"` + Global map[string]interface{} `json:"global"` + Metadata map[string]interface{} `json:"metadata"` + TransientMetadata map[string]interface{} `json:"transient_metadata"` +} + +// XPackSecurityApplicationPrivileges is the application privileges object +type XPackSecurityApplicationPrivileges struct { + Application string `json:"application"` + Privileges []string `json:"privileges"` + Ressources []string `json:"resources"` +} + +// XPackSecurityIndicesPermissions is the indices permission object +type XPackSecurityIndicesPermissions struct { + Names []string `json:"names"` + Privileges []string `json:"privileges"` + FieldSecurity interface{} `json:"field_security"` + Query string `json:"query"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_security_get_role_mapping.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_get_role_mapping.go new file mode 100644 index 0000000000..a6db53a553 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_get_role_mapping.go @@ -0,0 +1,113 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackSecurityGetRoleMappingService retrieves a role mapping by its name. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/security-api-get-role-mapping.html. +type XPackSecurityGetRoleMappingService struct { + client *Client + pretty bool + name string +} + +// NewXPackSecurityGetRoleMappingService creates a new XPackSecurityGetRoleMappingService. +func NewXPackSecurityGetRoleMappingService(client *Client) *XPackSecurityGetRoleMappingService { + return &XPackSecurityGetRoleMappingService{ + client: client, + } +} + +// Name is name of the role mapping to retrieve. +func (s *XPackSecurityGetRoleMappingService) Name(name string) *XPackSecurityGetRoleMappingService { + s.name = name + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackSecurityGetRoleMappingService) Pretty(pretty bool) *XPackSecurityGetRoleMappingService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackSecurityGetRoleMappingService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/security/role_mapping/{name}", map[string]string{ + "name": s.name, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackSecurityGetRoleMappingService) Validate() error { + var invalid []string + if s.name == "" { + invalid = append(invalid, "Name") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackSecurityGetRoleMappingService) Do(ctx context.Context) (*XPackSecurityGetRoleMappingResponse, 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, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := XPackSecurityGetRoleMappingResponse{} + if err := json.Unmarshal(res.Body, &ret); err != nil { + return nil, err + } + return &ret, nil +} + +// XPackSecurityGetRoleMappingResponse is the response of XPackSecurityGetRoleMappingService.Do. +type XPackSecurityGetRoleMappingResponse map[string]XPackSecurityRoleMapping + +// XPackSecurityRoleMapping is the role mapping object +type XPackSecurityRoleMapping struct { + Enabled bool `json:"enabled"` + Roles []string `json:"roles"` + Rules map[string]interface{} `json:"rules"` + Metadata interface{} `json:"metadata"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_security_put_role.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_put_role.go new file mode 100644 index 0000000000..f351627c81 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_put_role.go @@ -0,0 +1,122 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackSecurityPutRoleService retrieves a role by its name. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/security-api-put-role.html. +type XPackSecurityPutRoleService struct { + client *Client + pretty bool + name string + body interface{} +} + +// NewXPackSecurityPutRoleService creates a new XPackSecurityPutRoleService. +func NewXPackSecurityPutRoleService(client *Client) *XPackSecurityPutRoleService { + return &XPackSecurityPutRoleService{ + client: client, + } +} + +// Name is name of the role to create. +func (s *XPackSecurityPutRoleService) Name(name string) *XPackSecurityPutRoleService { + s.name = name + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackSecurityPutRoleService) Pretty(pretty bool) *XPackSecurityPutRoleService { + s.pretty = pretty + return s +} + +// Body specifies the role. Use a string or a type that will get serialized as JSON. +func (s *XPackSecurityPutRoleService) Body(body interface{}) *XPackSecurityPutRoleService { + s.body = body + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackSecurityPutRoleService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/security/role/{name}", map[string]string{ + "name": s.name, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackSecurityPutRoleService) Validate() error { + var invalid []string + if s.name == "" { + invalid = append(invalid, "Name") + } + if s.body == nil { + invalid = append(invalid, "Body") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackSecurityPutRoleService) Do(ctx context.Context) (*XPackSecurityPutRoleResponse, 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, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: s.body, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackSecurityPutRoleResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackSecurityPutRoleResponse is the response of XPackSecurityPutRoleService.Do. +type XPackSecurityPutRoleResponse struct { + Role XPackSecurityPutRole +} + +type XPackSecurityPutRole struct { + Created bool `json:"created"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_security_put_role_mapping.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_put_role_mapping.go new file mode 100644 index 0000000000..b86b8424e8 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_security_put_role_mapping.go @@ -0,0 +1,122 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackSecurityPutRoleMappingService create or update a role mapping by its name. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/security-api-put-role-mapping.html. +type XPackSecurityPutRoleMappingService struct { + client *Client + pretty bool + name string + body interface{} +} + +// NewXPackSecurityPutRoleMappingService creates a new XPackSecurityPutRoleMappingService. +func NewXPackSecurityPutRoleMappingService(client *Client) *XPackSecurityPutRoleMappingService { + return &XPackSecurityPutRoleMappingService{ + client: client, + } +} + +// Name is name of the role mapping to create/update. +func (s *XPackSecurityPutRoleMappingService) Name(name string) *XPackSecurityPutRoleMappingService { + s.name = name + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackSecurityPutRoleMappingService) Pretty(pretty bool) *XPackSecurityPutRoleMappingService { + s.pretty = pretty + return s +} + +// Body specifies the role mapping. Use a string or a type that will get serialized as JSON. +func (s *XPackSecurityPutRoleMappingService) Body(body interface{}) *XPackSecurityPutRoleMappingService { + s.body = body + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackSecurityPutRoleMappingService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/security/role_mapping/{name}", map[string]string{ + "name": s.name, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackSecurityPutRoleMappingService) Validate() error { + var invalid []string + if s.name == "" { + invalid = append(invalid, "Name") + } + if s.body == nil { + invalid = append(invalid, "Body") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackSecurityPutRoleMappingService) Do(ctx context.Context) (*XPackSecurityPutRoleMappingResponse, 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, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: s.body, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackSecurityPutRoleMappingResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackSecurityPutRoleMappingResponse is the response of XPackSecurityPutRoleMappingService.Do. +type XPackSecurityPutRoleMappingResponse struct { + Role_Mapping XPackSecurityPutRoleMapping +} + +type XPackSecurityPutRoleMapping struct { + Created bool `json:"created"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_ack_watch.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_ack_watch.go new file mode 100644 index 0000000000..0296dbcd36 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_ack_watch.go @@ -0,0 +1,147 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + "strings" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackWatcherAckWatchService enables you to manually throttle execution of the watch’s actions. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-ack-watch.html. +type XPackWatcherAckWatchService struct { + client *Client + pretty bool + watchId string + actionId []string + masterTimeout string +} + +// NewXPackWatcherAckWatchService creates a new XPackWatcherAckWatchService. +func NewXPackWatcherAckWatchService(client *Client) *XPackWatcherAckWatchService { + return &XPackWatcherAckWatchService{ + client: client, + } +} + +// WatchId is the unique ID of the watch. +func (s *XPackWatcherAckWatchService) WatchId(watchId string) *XPackWatcherAckWatchService { + s.watchId = watchId + return s +} + +// ActionId is a slice of action ids to be acked. +func (s *XPackWatcherAckWatchService) ActionId(actionId ...string) *XPackWatcherAckWatchService { + s.actionId = append(s.actionId, actionId...) + return s +} + +// MasterTimeout indicates an explicit operation timeout for +// connection to master node. +func (s *XPackWatcherAckWatchService) MasterTimeout(masterTimeout string) *XPackWatcherAckWatchService { + s.masterTimeout = masterTimeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherAckWatchService) Pretty(pretty bool) *XPackWatcherAckWatchService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherAckWatchService) buildURL() (string, url.Values, error) { + // Build URL + var ( + path string + err error + ) + if len(s.actionId) > 0 { + path, err = uritemplates.Expand("/_xpack/watcher/watch/{watch_id}/_ack/{action_id}", map[string]string{ + "watch_id": s.watchId, + "action_id": strings.Join(s.actionId, ","), + }) + } else { + path, err = uritemplates.Expand("/_xpack/watcher/watch/{watch_id}/_ack", map[string]string{ + "watch_id": s.watchId, + }) + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherAckWatchService) Validate() error { + var invalid []string + if s.watchId == "" { + invalid = append(invalid, "WatchId") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackWatcherAckWatchService) Do(ctx context.Context) (*XPackWatcherAckWatchResponse, 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, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherAckWatchResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherAckWatchResponse is the response of XPackWatcherAckWatchService.Do. +type XPackWatcherAckWatchResponse struct { + Status *XPackWatcherAckWatchStatus `json:"status"` +} + +// XPackWatcherAckWatchStatus is the status of a XPackWatcherAckWatchResponse. +type XPackWatcherAckWatchStatus struct { + State map[string]interface{} `json:"state"` + LastChecked string `json:"last_checked"` + LastMetCondition string `json:"last_met_condition"` + Actions map[string]map[string]interface{} `json:"actions"` + ExecutionState string `json:"execution_state"` + Version int `json:"version"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_activate_watch.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_activate_watch.go new file mode 100644 index 0000000000..b936cd8f59 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_activate_watch.go @@ -0,0 +1,117 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackWatcherActivateWatchService enables you to activate a currently inactive watch. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-activate-watch.html. +type XPackWatcherActivateWatchService struct { + client *Client + pretty bool + watchId string + masterTimeout string +} + +// NewXPackWatcherActivateWatchService creates a new XPackWatcherActivateWatchService. +func NewXPackWatcherActivateWatchService(client *Client) *XPackWatcherActivateWatchService { + return &XPackWatcherActivateWatchService{ + client: client, + } +} + +// WatchId is the ID of the watch to activate. +func (s *XPackWatcherActivateWatchService) WatchId(watchId string) *XPackWatcherActivateWatchService { + s.watchId = watchId + return s +} + +// MasterTimeout specifies an explicit operation timeout for connection to master node. +func (s *XPackWatcherActivateWatchService) MasterTimeout(masterTimeout string) *XPackWatcherActivateWatchService { + s.masterTimeout = masterTimeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherActivateWatchService) Pretty(pretty bool) *XPackWatcherActivateWatchService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherActivateWatchService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/watcher/watch/{watch_id}/_activate", map[string]string{ + "watch_id": s.watchId, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherActivateWatchService) Validate() error { + var invalid []string + if s.watchId == "" { + invalid = append(invalid, "WatchId") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackWatcherActivateWatchService) Do(ctx context.Context) (*XPackWatcherActivateWatchResponse, 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, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherActivateWatchResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherActivateWatchResponse is the response of XPackWatcherActivateWatchService.Do. +type XPackWatcherActivateWatchResponse struct { + Status *XPackWatchStatus `json:"status"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_deactivate_watch.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_deactivate_watch.go new file mode 100644 index 0000000000..c6d395921e --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_deactivate_watch.go @@ -0,0 +1,119 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackWatcherDeactivateWatchService enables you to deactivate a currently active watch. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-deactivate-watch.html. +type XPackWatcherDeactivateWatchService struct { + client *Client + pretty bool + watchId string + masterTimeout string + bodyJson interface{} + bodyString string +} + +// NewXPackWatcherDeactivateWatchService creates a new XPackWatcherDeactivateWatchService. +func NewXPackWatcherDeactivateWatchService(client *Client) *XPackWatcherDeactivateWatchService { + return &XPackWatcherDeactivateWatchService{ + client: client, + } +} + +// WatchId is the ID of the watch to deactivate. +func (s *XPackWatcherDeactivateWatchService) WatchId(watchId string) *XPackWatcherDeactivateWatchService { + s.watchId = watchId + return s +} + +// MasterTimeout specifies an explicit operation timeout for connection to master node. +func (s *XPackWatcherDeactivateWatchService) MasterTimeout(masterTimeout string) *XPackWatcherDeactivateWatchService { + s.masterTimeout = masterTimeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherDeactivateWatchService) Pretty(pretty bool) *XPackWatcherDeactivateWatchService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherDeactivateWatchService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/watcher/watch/{watch_id}/_deactivate", map[string]string{ + "watch_id": s.watchId, + }) + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherDeactivateWatchService) Validate() error { + var invalid []string + if s.watchId == "" { + invalid = append(invalid, "WatchId") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackWatcherDeactivateWatchService) Do(ctx context.Context) (*XPackWatcherDeactivateWatchResponse, 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, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherDeactivateWatchResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherDeactivateWatchResponse is the response of XPackWatcherDeactivateWatchService.Do. +type XPackWatcherDeactivateWatchResponse struct { + Status *XPackWatchStatus `json:"status"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_delete_watch.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_delete_watch.go new file mode 100644 index 0000000000..98c7412b46 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_delete_watch.go @@ -0,0 +1,119 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackWatcherDeleteWatchService removes a watch. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-delete-watch.html. +type XPackWatcherDeleteWatchService struct { + client *Client + pretty bool + id string + masterTimeout string +} + +// NewXPackWatcherDeleteWatchService creates a new XPackWatcherDeleteWatchService. +func NewXPackWatcherDeleteWatchService(client *Client) *XPackWatcherDeleteWatchService { + return &XPackWatcherDeleteWatchService{ + client: client, + } +} + +// Id of the watch to delete. +func (s *XPackWatcherDeleteWatchService) Id(id string) *XPackWatcherDeleteWatchService { + s.id = id + return s +} + +// MasterTimeout specifies an explicit operation timeout for connection to master node. +func (s *XPackWatcherDeleteWatchService) MasterTimeout(masterTimeout string) *XPackWatcherDeleteWatchService { + s.masterTimeout = masterTimeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherDeleteWatchService) Pretty(pretty bool) *XPackWatcherDeleteWatchService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherDeleteWatchService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/watcher/watch/{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", "true") + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherDeleteWatchService) 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 *XPackWatcherDeleteWatchService) Do(ctx context.Context) (*XPackWatcherDeleteWatchResponse, 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, PerformRequestOptions{ + Method: "DELETE", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherDeleteWatchResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherDeleteWatchResponse is the response of XPackWatcherDeleteWatchService.Do. +type XPackWatcherDeleteWatchResponse struct { + Found bool `json:"found"` + Id string `json:"_id"` + Version int `json:"_version"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_execute_watch.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_execute_watch.go new file mode 100644 index 0000000000..c82083e300 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_execute_watch.go @@ -0,0 +1,162 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackWatcherExecuteWatchService forces the execution of a stored watch. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-execute-watch.html. +type XPackWatcherExecuteWatchService struct { + client *Client + pretty bool + id string + debug *bool + bodyJson interface{} + bodyString string +} + +// NewXPackWatcherExecuteWatchService creates a new XPackWatcherExecuteWatchService. +func NewXPackWatcherExecuteWatchService(client *Client) *XPackWatcherExecuteWatchService { + return &XPackWatcherExecuteWatchService{ + client: client, + } +} + +// Id of the watch to execute on. +func (s *XPackWatcherExecuteWatchService) Id(id string) *XPackWatcherExecuteWatchService { + s.id = id + return s +} + +// Debug indicates whether the watch should execute in debug mode. +func (s *XPackWatcherExecuteWatchService) Debug(debug bool) *XPackWatcherExecuteWatchService { + s.debug = &debug + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherExecuteWatchService) Pretty(pretty bool) *XPackWatcherExecuteWatchService { + s.pretty = pretty + return s +} + +// BodyJson is documented as: Execution control. +func (s *XPackWatcherExecuteWatchService) BodyJson(body interface{}) *XPackWatcherExecuteWatchService { + s.bodyJson = body + return s +} + +// BodyString is documented as: Execution control. +func (s *XPackWatcherExecuteWatchService) BodyString(body string) *XPackWatcherExecuteWatchService { + s.bodyString = body + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherExecuteWatchService) buildURL() (string, url.Values, error) { + // Build URL + var ( + path string + err error + ) + if s.id != "" { + path, err = uritemplates.Expand("/_xpack/watcher/watch/{id}/_execute", map[string]string{ + "id": s.id, + }) + } else { + path = "/_xpack/watcher/watch/_execute" + } + if err != nil { + return "", url.Values{}, err + } + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + if s.debug != nil { + params.Set("debug", fmt.Sprintf("%v", *s.debug)) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherExecuteWatchService) Validate() error { + return nil +} + +// Do executes the operation. +func (s *XPackWatcherExecuteWatchService) Do(ctx context.Context) (*XPackWatcherExecuteWatchResponse, 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, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: body, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherExecuteWatchResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherExecuteWatchResponse is the response of XPackWatcherExecuteWatchService.Do. +type XPackWatcherExecuteWatchResponse struct { + Id string `json:"_id"` + WatchRecord *XPackWatchRecord `json:"watch_record"` +} + +type XPackWatchRecord struct { + WatchId string `json:"watch_id"` + Node string `json:"node"` + Messages []string `json:"messages"` + State string `json:"state"` + Status *XPackWatchRecordStatus `json:"status"` + Input map[string]map[string]interface{} `json:"input"` + Condition map[string]map[string]interface{} `json:"condition"` + Result map[string]interface{} `json:"Result"` +} + +type XPackWatchRecordStatus struct { + Version int `json:"version"` + State map[string]interface{} `json:"state"` + LastChecked string `json:"last_checked"` + LastMetCondition string `json:"last_met_condition"` + Actions map[string]map[string]interface{} `json:"actions"` + ExecutionState string `json:"execution_state"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_get_watch.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_get_watch.go new file mode 100644 index 0000000000..03911838d7 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_get_watch.go @@ -0,0 +1,162 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + "time" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackWatcherGetWatchService retrieves a watch by its ID. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-get-watch.html. +type XPackWatcherGetWatchService struct { + client *Client + pretty bool + id string +} + +// NewXPackWatcherGetWatchService creates a new XPackWatcherGetWatchService. +func NewXPackWatcherGetWatchService(client *Client) *XPackWatcherGetWatchService { + return &XPackWatcherGetWatchService{ + client: client, + } +} + +// Id is ID of the watch to retrieve. +func (s *XPackWatcherGetWatchService) Id(id string) *XPackWatcherGetWatchService { + s.id = id + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherGetWatchService) Pretty(pretty bool) *XPackWatcherGetWatchService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherGetWatchService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/watcher/watch/{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", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherGetWatchService) 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 *XPackWatcherGetWatchService) Do(ctx context.Context) (*XPackWatcherGetWatchResponse, 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, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherGetWatchResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherGetWatchResponse is the response of XPackWatcherGetWatchService.Do. +type XPackWatcherGetWatchResponse struct { + Found bool `json:"found"` + Id string `json:"_id"` + Version int64 `json:"_version,omitempty"` + Status *XPackWatchStatus `json:"status,omitempty"` + Watch *XPackWatch `json:"watch,omitempty"` +} + +type XPackWatchStatus struct { + State *XPackWatchExecutionState `json:"state,omitempty"` + LastChecked *time.Time `json:"last_checked,omitempty"` + LastMetCondition *time.Time `json:"last_met_condition,omitempty"` + Actions map[string]*XPackWatchActionStatus `json:"actions,omitempty"` + ExecutionState *XPackWatchActionExecutionState `json:"execution_state,omitempty"` + Headers map[string]string `json:"headers,omitempty"` + Version int64 `json:"version"` +} + +type XPackWatchExecutionState struct { + Active bool `json:"active"` + Timestamp time.Time `json:"timestamp"` +} + +type XPackWatchActionStatus struct { + AckStatus *XPackWatchActionAckStatus `json:"ack"` + LastExecution *time.Time `json:"last_execution,omitempty"` + LastSuccessfulExecution *time.Time `json:"last_successful_execution,omitempty"` + LastThrottle *XPackWatchActionThrottle `json:"last_throttle,omitempty"` +} + +type XPackWatchActionAckStatus struct { + Timestamp time.Time `json:"timestamp"` + AckStatusState string `json:"ack_status_state"` +} + +type XPackWatchActionExecutionState struct { + Timestamp time.Time `json:"timestamp"` + Successful bool `json:"successful"` + Reason string `json:"reason,omitempty"` +} + +type XPackWatchActionThrottle struct { + Timestamp time.Time `json:"timestamp"` + Reason string `json:"reason,omitempty"` +} + +type XPackWatch struct { + Trigger map[string]map[string]interface{} `json:"trigger"` + Input map[string]map[string]interface{} `json:"input"` + Condition map[string]map[string]interface{} `json:"condition"` + Transform map[string]interface{} `json:"transform,omitempty"` + ThrottlePeriod string `json:"throttle_period,omitempty"` + ThrottlePeriodInMillis int64 `json:"throttle_period_in_millis,omitempty"` + Actions map[string]*XPackWatchActionStatus `json:"actions"` + Metadata map[string]interface{} `json:"metadata,omitempty"` + Status *XPackWatchStatus `json:"status,omitempty"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_put_watch.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_put_watch.go new file mode 100644 index 0000000000..82c434512e --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_put_watch.go @@ -0,0 +1,160 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/olivere/elastic/uritemplates" +) + +// XPackWatcherPutWatchService either registers a new watch in Watcher +// or update an existing one. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-put-watch.html. +type XPackWatcherPutWatchService struct { + client *Client + pretty bool + id string + active *bool + masterTimeout string + ifSeqNo *int64 + ifPrimaryTerm *int64 + body interface{} +} + +// NewXPackWatcherPutWatchService creates a new XPackWatcherPutWatchService. +func NewXPackWatcherPutWatchService(client *Client) *XPackWatcherPutWatchService { + return &XPackWatcherPutWatchService{ + client: client, + } +} + +// Id of the watch to upsert. +func (s *XPackWatcherPutWatchService) Id(id string) *XPackWatcherPutWatchService { + s.id = id + return s +} + +// Active specifies whether the watch is in/active by default. +func (s *XPackWatcherPutWatchService) Active(active bool) *XPackWatcherPutWatchService { + s.active = &active + return s +} + +// MasterTimeout is an explicit operation timeout for connection to master node. +func (s *XPackWatcherPutWatchService) MasterTimeout(masterTimeout string) *XPackWatcherPutWatchService { + s.masterTimeout = masterTimeout + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherPutWatchService) Pretty(pretty bool) *XPackWatcherPutWatchService { + s.pretty = pretty + return s +} + +// IfSeqNo indicates to update the watch only if the last operation that +// has changed the watch has the specified sequence number. +func (s *XPackWatcherPutWatchService) IfSeqNo(seqNo int64) *XPackWatcherPutWatchService { + s.ifSeqNo = &seqNo + return s +} + +// IfPrimaryTerm indicates to update the watch only if the last operation that +// has changed the watch has the specified primary term. +func (s *XPackWatcherPutWatchService) IfPrimaryTerm(primaryTerm int64) *XPackWatcherPutWatchService { + s.ifPrimaryTerm = &primaryTerm + return s +} + +// Body specifies the watch. Use a string or a type that will get serialized as JSON. +func (s *XPackWatcherPutWatchService) Body(body interface{}) *XPackWatcherPutWatchService { + s.body = body + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherPutWatchService) buildURL() (string, url.Values, error) { + // Build URL + path, err := uritemplates.Expand("/_xpack/watcher/watch/{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", "true") + } + if s.active != nil { + params.Set("active", fmt.Sprintf("%v", *s.active)) + } + if s.masterTimeout != "" { + params.Set("master_timeout", s.masterTimeout) + } + if v := s.ifSeqNo; v != nil { + params.Set("if_seq_no", fmt.Sprintf("%d", *v)) + } + if v := s.ifPrimaryTerm; v != nil { + params.Set("if_primary_term", fmt.Sprintf("%d", *v)) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherPutWatchService) Validate() error { + var invalid []string + if s.id == "" { + invalid = append(invalid, "Id") + } + if s.body == nil { + invalid = append(invalid, "Body") + } + if len(invalid) > 0 { + return fmt.Errorf("missing required fields: %v", invalid) + } + return nil +} + +// Do executes the operation. +func (s *XPackWatcherPutWatchService) Do(ctx context.Context) (*XPackWatcherPutWatchResponse, 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, PerformRequestOptions{ + Method: "PUT", + Path: path, + Params: params, + Body: s.body, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherPutWatchResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherPutWatchResponse is the response of XPackWatcherPutWatchService.Do. +type XPackWatcherPutWatchResponse struct { +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_restart.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_restart.go new file mode 100644 index 0000000000..7a1160d232 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_restart.go @@ -0,0 +1,85 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "net/url" +) + +// XPackWatcherRestartService stops the starts the watcher service. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-restart.html. +type XPackWatcherRestartService struct { + client *Client + pretty bool +} + +// NewXPackWatcherRestartService creates a new XPackWatcherRestartService. +func NewXPackWatcherRestartService(client *Client) *XPackWatcherRestartService { + return &XPackWatcherRestartService{ + client: client, + } +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherRestartService) Pretty(pretty bool) *XPackWatcherRestartService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherRestartService) buildURL() (string, url.Values, error) { + // Build URL path + path := "/_xpack/watcher/_restart" + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherRestartService) Validate() error { + return nil +} + +// Do executes the operation. +func (s *XPackWatcherRestartService) Do(ctx context.Context) (*XPackWatcherRestartResponse, 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, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherRestartResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherRestartResponse is the response of XPackWatcherRestartService.Do. +type XPackWatcherRestartResponse struct { + Acknowledged bool `json:"acknowledged"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_start.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_start.go new file mode 100644 index 0000000000..89f44d2efe --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_start.go @@ -0,0 +1,85 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "net/url" +) + +// XPackWatcherStartService starts the watcher service if it is not already running. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-start.html. +type XPackWatcherStartService struct { + client *Client + pretty bool +} + +// NewXPackWatcherStartService creates a new XPackWatcherStartService. +func NewXPackWatcherStartService(client *Client) *XPackWatcherStartService { + return &XPackWatcherStartService{ + client: client, + } +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherStartService) Pretty(pretty bool) *XPackWatcherStartService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherStartService) buildURL() (string, url.Values, error) { + // Build URL path + path := "/_xpack/watcher/_start" + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherStartService) Validate() error { + return nil +} + +// Do executes the operation. +func (s *XPackWatcherStartService) Do(ctx context.Context) (*XPackWatcherStartResponse, 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, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherStartResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherStartResponse is the response of XPackWatcherStartService.Do. +type XPackWatcherStartResponse struct { + Acknowledged bool `json:"acknowledged"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_stats.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_stats.go new file mode 100644 index 0000000000..cb776683ee --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_stats.go @@ -0,0 +1,113 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "fmt" + "net/url" +) + +// XPackWatcherStatsService returns the current watcher metrics. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-stats.html. +type XPackWatcherStatsService struct { + client *Client + pretty bool + metric string + emitStacktraces *bool +} + +// NewXPackWatcherStatsService creates a new XPackWatcherStatsService. +func NewXPackWatcherStatsService(client *Client) *XPackWatcherStatsService { + return &XPackWatcherStatsService{ + client: client, + } +} + +// Metric controls what additional stat metrics should be include in the response. +func (s *XPackWatcherStatsService) Metric(metric string) *XPackWatcherStatsService { + s.metric = metric + return s +} + +// EmitStacktraces, if enabled, emits stack traces of currently running watches. +func (s *XPackWatcherStatsService) EmitStacktraces(emitStacktraces bool) *XPackWatcherStatsService { + s.emitStacktraces = &emitStacktraces + return s +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherStatsService) Pretty(pretty bool) *XPackWatcherStatsService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherStatsService) buildURL() (string, url.Values, error) { + // Build URL + path := "/_xpack/watcher/stats" + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + if s.emitStacktraces != nil { + params.Set("emit_stacktraces", fmt.Sprintf("%v", *s.emitStacktraces)) + } + if s.metric != "" { + params.Set("metric", s.metric) + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherStatsService) Validate() error { + return nil +} + +// Do executes the operation. +func (s *XPackWatcherStatsService) Do(ctx context.Context) (*XPackWatcherStatsResponse, 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, PerformRequestOptions{ + Method: "GET", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherStatsResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherStatsResponse is the response of XPackWatcherStatsService.Do. +type XPackWatcherStatsResponse struct { + Stats []XPackWatcherStats `json:"stats"` +} + +// XPackWatcherStats represents the stats used in XPackWatcherStatsResponse. +type XPackWatcherStats struct { + WatcherState string `json:"watcher_state"` + WatchCount int `json:"watch_count"` + ExecutionThreadPool map[string]interface{} `json:"execution_thread_pool"` +} diff --git a/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_stop.go b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_stop.go new file mode 100644 index 0000000000..ba10331879 --- /dev/null +++ b/vendor/gopkg.in/olivere/elastic.v6/xpack_watcher_stop.go @@ -0,0 +1,85 @@ +// Copyright 2012-2018 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 ( + "context" + "encoding/json" + "net/url" +) + +// XPackWatcherStopService stops the watcher service if it is running. +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.8/watcher-api-stop.html. +type XPackWatcherStopService struct { + client *Client + pretty bool +} + +// NewXPackWatcherStopService creates a new XPackWatcherStopService. +func NewXPackWatcherStopService(client *Client) *XPackWatcherStopService { + return &XPackWatcherStopService{ + client: client, + } +} + +// Pretty indicates that the JSON response be indented and human readable. +func (s *XPackWatcherStopService) Pretty(pretty bool) *XPackWatcherStopService { + s.pretty = pretty + return s +} + +// buildURL builds the URL for the operation. +func (s *XPackWatcherStopService) buildURL() (string, url.Values, error) { + // Build URL path + path := "/_xpack/watcher/_stop" + + // Add query string parameters + params := url.Values{} + if s.pretty { + params.Set("pretty", "true") + } + return path, params, nil +} + +// Validate checks if the operation is valid. +func (s *XPackWatcherStopService) Validate() error { + return nil +} + +// Do executes the operation. +func (s *XPackWatcherStopService) Do(ctx context.Context) (*XPackWatcherStopResponse, 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, PerformRequestOptions{ + Method: "POST", + Path: path, + Params: params, + }) + if err != nil { + return nil, err + } + + // Return operation response + ret := new(XPackWatcherStopResponse) + if err := json.Unmarshal(res.Body, ret); err != nil { + return nil, err + } + return ret, nil +} + +// XPackWatcherStopResponse is the response of XPackWatcherStopService.Do. +type XPackWatcherStopResponse struct { + Acknowledged bool `json:"acknowledged"` +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 0742894695..5ae311ce80 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -157,6 +157,9 @@ github.com/nfnt/resize github.com/oklog/run # github.com/olekukonko/tablewriter v0.0.1 github.com/olekukonko/tablewriter +# github.com/olivere/elastic v6.2.23+incompatible +github.com/olivere/elastic/config +github.com/olivere/elastic/uritemplates # github.com/pborman/uuid v1.2.0 github.com/pborman/uuid # github.com/pelletier/go-toml v1.4.0 @@ -233,19 +236,19 @@ go.uber.org/zap/zapcore # golang.org/x/crypto v0.0.0-20191001170739-f9e2070545dc golang.org/x/crypto/acme golang.org/x/crypto/acme/autocert +golang.org/x/crypto/argon2 +golang.org/x/crypto/bcrypt +golang.org/x/crypto/blake2b +golang.org/x/crypto/blowfish +golang.org/x/crypto/cast5 +golang.org/x/crypto/ed25519 +golang.org/x/crypto/ed25519/internal/edwards25519 golang.org/x/crypto/openpgp golang.org/x/crypto/openpgp/armor -golang.org/x/crypto/bcrypt +golang.org/x/crypto/openpgp/elgamal golang.org/x/crypto/openpgp/errors golang.org/x/crypto/openpgp/packet golang.org/x/crypto/openpgp/s2k -golang.org/x/crypto/blowfish -golang.org/x/crypto/argon2 -golang.org/x/crypto/cast5 -golang.org/x/crypto/openpgp/elgamal -golang.org/x/crypto/blake2b -golang.org/x/crypto/ed25519 -golang.org/x/crypto/ed25519/internal/edwards25519 # golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a golang.org/x/image/bmp golang.org/x/image/ccitt @@ -359,10 +362,8 @@ gopkg.in/ini.v1 gopkg.in/mail.v2 # gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/natefinch/lumberjack.v2 -# gopkg.in/olivere/elastic.v5 v5.0.82 -gopkg.in/olivere/elastic.v5 -gopkg.in/olivere/elastic.v5/config -gopkg.in/olivere/elastic.v5/uritemplates +# gopkg.in/olivere/elastic.v6 v6.2.23 +gopkg.in/olivere/elastic.v6 # gopkg.in/yaml.v2 v2.2.3 gopkg.in/yaml.v2 # willnorris.com/go/gifresize v1.0.0