From def28e33d1ec9879599b925f8b0123039355cd69 Mon Sep 17 00:00:00 2001 From: delvedor Date: Mon, 16 Aug 2021 11:27:35 +0200 Subject: [PATCH] API generation --- api/api/search_mvt.js | 87 +++++++++++++++++++++++++++++++++++++++++ api/index.js | 3 ++ api/requestParams.d.ts | 14 +++++++ docs/reference.asciidoc | 61 +++++++++++++++++++++++++++++ index.d.ts | 8 ++++ 5 files changed, 173 insertions(+) create mode 100644 api/api/search_mvt.js diff --git a/api/api/search_mvt.js b/api/api/search_mvt.js new file mode 100644 index 000000000..242622b0d --- /dev/null +++ b/api/api/search_mvt.js @@ -0,0 +1,87 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils') +const acceptedQuerystring = ['exact_bounds', 'extent', 'grid_precision', 'grid_type', 'size', 'pretty', 'human', 'error_trace', 'source', 'filter_path'] +const snakeCase = { exactBounds: 'exact_bounds', gridPrecision: 'grid_precision', gridType: 'grid_type', errorTrace: 'error_trace', filterPath: 'filter_path' } + +function searchMvtApi (params, options, callback) { + ;[params, options, callback] = normalizeArguments(params, options, callback) + + // check required parameters + if (params.index == null) { + const err = new this[kConfigurationError]('Missing required parameter: index') + return handleError(err, callback) + } + if (params.field == null) { + const err = new this[kConfigurationError]('Missing required parameter: field') + return handleError(err, callback) + } + if (params.zoom == null) { + const err = new this[kConfigurationError]('Missing required parameter: zoom') + return handleError(err, callback) + } + if (params.x == null) { + const err = new this[kConfigurationError]('Missing required parameter: x') + return handleError(err, callback) + } + if (params.y == null) { + const err = new this[kConfigurationError]('Missing required parameter: y') + return handleError(err, callback) + } + + // check required url components + if (params.y != null && (params.x == null || params.zoom == null || params.field == null || params.index == null)) { + const err = new this[kConfigurationError]('Missing required parameter of the url: x, zoom, field, index') + return handleError(err, callback) + } else if (params.x != null && (params.zoom == null || params.field == null || params.index == null)) { + const err = new this[kConfigurationError]('Missing required parameter of the url: zoom, field, index') + return handleError(err, callback) + } else if (params.zoom != null && (params.field == null || params.index == null)) { + const err = new this[kConfigurationError]('Missing required parameter of the url: field, index') + return handleError(err, callback) + } else if (params.field != null && (params.index == null)) { + const err = new this[kConfigurationError]('Missing required parameter of the url: index') + return handleError(err, callback) + } + + let { method, body, index, field, zoom, x, y, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring) + + let path = '' + if (method == null) method = body == null ? 'GET' : 'POST' + path = '/' + encodeURIComponent(index) + '/' + '_mvt' + '/' + encodeURIComponent(field) + '/' + encodeURIComponent(zoom) + '/' + encodeURIComponent(x) + '/' + encodeURIComponent(y) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + return this.transport.request(request, options, callback) +} + +module.exports = searchMvtApi diff --git a/api/index.js b/api/index.js index 0ea8e1b84..2b37a5bfb 100644 --- a/api/index.js +++ b/api/index.js @@ -74,6 +74,7 @@ const RollupApi = require('./api/rollup') const scriptsPainlessExecuteApi = require('./api/scripts_painless_execute') const scrollApi = require('./api/scroll') const searchApi = require('./api/search') +const searchMvtApi = require('./api/search_mvt') const searchShardsApi = require('./api/search_shards') const searchTemplateApi = require('./api/search_template') const SearchableSnapshotsApi = require('./api/searchable_snapshots') @@ -200,6 +201,7 @@ ESAPI.prototype.renderSearchTemplate = renderSearchTemplateApi ESAPI.prototype.scriptsPainlessExecute = scriptsPainlessExecuteApi ESAPI.prototype.scroll = scrollApi ESAPI.prototype.search = searchApi +ESAPI.prototype.searchMvt = searchMvtApi ESAPI.prototype.searchShards = searchShardsApi ESAPI.prototype.searchTemplate = searchTemplateApi ESAPI.prototype.termsEnum = termsEnumApi @@ -397,6 +399,7 @@ Object.defineProperties(ESAPI.prototype, { } }, scripts_painless_execute: { get () { return this.scriptsPainlessExecute } }, + search_mvt: { get () { return this.searchMvt } }, search_shards: { get () { return this.searchShards } }, search_template: { get () { return this.searchTemplate } }, searchableSnapshots: { diff --git a/api/requestParams.d.ts b/api/requestParams.d.ts index 151072bc9..682142a2a 100644 --- a/api/requestParams.d.ts +++ b/api/requestParams.d.ts @@ -2180,6 +2180,20 @@ export interface Search extends Generic { body?: T; } +export interface SearchMvt extends Generic { + index: string | string[]; + field: string; + zoom: integer; + x: integer; + y: integer; + exact_bounds?: boolean; + extent?: number; + grid_precision?: number; + grid_type?: 'grid' | 'point'; + size?: number; + body?: T; +} + export interface SearchShards extends Generic { index?: string | string[]; preference?: string; diff --git a/docs/reference.asciidoc b/docs/reference.asciidoc index 276398f41..4a5e37087 100644 --- a/docs/reference.asciidoc +++ b/docs/reference.asciidoc @@ -8993,6 +8993,67 @@ _Default:_ `5` |=== +[discrete] +=== searchMvt +*Stability:* experimental +[source,ts] +---- +client.searchMvt({ + index: string | string[], + field: string, + zoom: integer, + x: integer, + y: integer, + exact_bounds: boolean, + extent: number, + grid_precision: number, + grid_type: 'grid' | 'point', + size: number, + body: object +}) +---- +link:{ref}/search-vector-tile-api.html[Documentation] + +[cols=2*] +|=== +|`index` +|`string \| string[]` - Comma-separated list of data streams, indices, or aliases to search + +|`field` +|`string` - Field containing geospatial data to return + +|`zoom` +|`integer` - Zoom level for the vector tile to search + +|`x` +|`integer` - X coordinate for the vector tile to search + +|`y` +|`integer` - Y coordinate for the vector tile to search + +|`exact_bounds` or `exactBounds` +|`boolean` - 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. + +|`extent` +|`number` - Size, in pixels, of a side of the vector tile. + +_Default:_ `4096` + +|`grid_precision` or `gridPrecision` +|`number` - Additional zoom levels available through the aggs layer. Accepts 0-8. + +_Default:_ `8` + +|`grid_type` or `gridType` +|`'grid' \| 'point'` - Determines the geometry type for features in the aggs layer. + +_Default:_ `grid` + +|`size` +|`number` - Maximum number of features to return in the hits layer. Accepts 0-10000. + +_Default:_ `10000` + +|`body` +|`object` - Search request body. + +|=== + [discrete] === searchShards diff --git a/index.d.ts b/index.d.ts index 5de87f4b9..365368fdf 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2101,6 +2101,14 @@ declare class Client { search, TRequestBody extends RequestBody = Record, TContext = Context>(callback: callbackFn): TransportRequestCallback search, TRequestBody extends RequestBody = Record, TContext = Context>(params: RequestParams.Search, callback: callbackFn): TransportRequestCallback search, TRequestBody extends RequestBody = Record, TContext = Context>(params: RequestParams.Search, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback + search_mvt, TRequestBody extends RequestBody = Record, TContext = Context>(params?: RequestParams.SearchMvt, options?: TransportRequestOptions): TransportRequestPromise> + search_mvt, TRequestBody extends RequestBody = Record, TContext = Context>(callback: callbackFn): TransportRequestCallback + search_mvt, TRequestBody extends RequestBody = Record, TContext = Context>(params: RequestParams.SearchMvt, callback: callbackFn): TransportRequestCallback + search_mvt, TRequestBody extends RequestBody = Record, TContext = Context>(params: RequestParams.SearchMvt, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback + searchMvt, TRequestBody extends RequestBody = Record, TContext = Context>(params?: RequestParams.SearchMvt, options?: TransportRequestOptions): TransportRequestPromise> + searchMvt, TRequestBody extends RequestBody = Record, TContext = Context>(callback: callbackFn): TransportRequestCallback + searchMvt, TRequestBody extends RequestBody = Record, TContext = Context>(params: RequestParams.SearchMvt, callback: callbackFn): TransportRequestCallback + searchMvt, TRequestBody extends RequestBody = Record, TContext = Context>(params: RequestParams.SearchMvt, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback search_shards, TContext = Context>(params?: RequestParams.SearchShards, options?: TransportRequestOptions): TransportRequestPromise> search_shards, TContext = Context>(callback: callbackFn): TransportRequestCallback search_shards, TContext = Context>(params: RequestParams.SearchShards, callback: callbackFn): TransportRequestCallback