|
| 1 | +# Licensed to Elasticsearch B.V. under one or more contributor |
| 2 | +# license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright |
| 4 | +# ownership. Elasticsearch B.V. licenses this file to you under |
| 5 | +# the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +module Elasticsearch |
| 19 | + module API |
| 20 | + module Actions |
| 21 | + # Searches a vector tile for geospatial values. Returns results as a binary Mapbox vector tile. |
| 22 | + # This functionality is Experimental and may be changed or removed |
| 23 | + # completely in a future release. Elastic will take a best effort approach |
| 24 | + # to fix any issues, but experimental features are not subject to the |
| 25 | + # support SLA of official GA features. |
| 26 | + # |
| 27 | + # @option arguments [List] :index Comma-separated list of data streams, indices, or aliases to search |
| 28 | + # @option arguments [String] :field Field containing geospatial data to return |
| 29 | + # @option arguments [Integer] :zoom Zoom level for the vector tile to search |
| 30 | + # @option arguments [Integer] :x X coordinate for the vector tile to search |
| 31 | + # @option arguments [Integer] :y Y coordinate for the vector tile to search |
| 32 | + # @option arguments [Boolean] :exact_bounds If false, the meta layer's feature is the bounding box of the tile. If true, the meta layer's feature is a bounding box resulting from a `geo_bounds` aggregation. |
| 33 | + # @option arguments [Number] :extent Size, in pixels, of a side of the vector tile. |
| 34 | + # @option arguments [Number] :grid_precision Additional zoom levels available through the aggs layer. Accepts 0-8. |
| 35 | + # @option arguments [String] :grid_type Determines the geometry type for features in the aggs layer. (options: grid, point) |
| 36 | + # @option arguments [Number] :size Maximum number of features to return in the hits layer. Accepts 0-10000. |
| 37 | + # @option arguments [Hash] :headers Custom HTTP headers |
| 38 | + # @option arguments [Hash] :body Search request body. |
| 39 | + # |
| 40 | + # @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-vector-tile-api.html |
| 41 | + # |
| 42 | + def search_mvt(arguments = {}) |
| 43 | + raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] |
| 44 | + raise ArgumentError, "Required argument 'field' missing" unless arguments[:field] |
| 45 | + raise ArgumentError, "Required argument 'zoom' missing" unless arguments[:zoom] |
| 46 | + raise ArgumentError, "Required argument 'x' missing" unless arguments[:x] |
| 47 | + raise ArgumentError, "Required argument 'y' missing" unless arguments[:y] |
| 48 | + |
| 49 | + headers = arguments.delete(:headers) || {} |
| 50 | + |
| 51 | + arguments = arguments.clone |
| 52 | + |
| 53 | + _index = arguments.delete(:index) |
| 54 | + |
| 55 | + _field = arguments.delete(:field) |
| 56 | + |
| 57 | + _zoom = arguments.delete(:zoom) |
| 58 | + |
| 59 | + _x = arguments.delete(:x) |
| 60 | + |
| 61 | + _y = arguments.delete(:y) |
| 62 | + |
| 63 | + method = if arguments[:body] |
| 64 | + Elasticsearch::API::HTTP_POST |
| 65 | + else |
| 66 | + Elasticsearch::API::HTTP_GET |
| 67 | + end |
| 68 | + |
| 69 | + path = "#{Utils.__listify(_index)}/_mvt/#{Utils.__listify(_field)}/#{Utils.__listify(_zoom)}/#{Utils.__listify(_x)}/#{Utils.__listify(_y)}" |
| 70 | + params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) |
| 71 | + |
| 72 | + body = arguments[:body] |
| 73 | + perform_request(method, path, params, body, headers).body |
| 74 | + end |
| 75 | + |
| 76 | + # Register this action with its valid params when the module is loaded. |
| 77 | + # |
| 78 | + # @since 6.2.0 |
| 79 | + ParamsRegistry.register(:search_mvt, [ |
| 80 | + :exact_bounds, |
| 81 | + :extent, |
| 82 | + :grid_precision, |
| 83 | + :grid_type, |
| 84 | + :size |
| 85 | + ].freeze) |
| 86 | + end |
| 87 | + end |
| 88 | +end |
0 commit comments