From 0f35880143e26d1ac6a7536c77d7aa204554f7b2 Mon Sep 17 00:00:00 2001 From: delvedor Date: Wed, 11 Aug 2021 12:00:15 +0200 Subject: [PATCH] API generation --- api/api/search_mvt.js | 87 +++++++++++++++++++++++++++++++++++++++++ api/index.js | 3 ++ api/requestParams.d.ts | 14 +++++++ docs/reference.asciidoc | 69 ++++++++++++++++++++++++++++++-- index.d.ts | 8 ++++ 5 files changed, 177 insertions(+), 4 deletions(-) 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 f8036f850..52e925b44 100644 --- a/api/requestParams.d.ts +++ b/api/requestParams.d.ts @@ -2236,6 +2236,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 2b6ed7bb0..dd30b4ef0 100644 --- a/docs/reference.asciidoc +++ b/docs/reference.asciidoc @@ -1969,7 +1969,7 @@ link:{ref}/cluster-allocation-explain.html[Documentation] + |`boolean` - Return information about disk usage and shard sizes (default: false) |`body` -|`object` - The index, shard, and primary flag to explain. Empty means 'explain the first unassigned shard' +|`object` - The index, shard, and primary flag to explain. Empty means 'explain a randomly-chosen unassigned shard' |=== @@ -9248,6 +9248,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 @@ -10865,7 +10926,7 @@ client.sql.clearCursor({ body: object }) ---- -link:{ref}/sql-pagination.html[Documentation] + +link:{ref}/clear-sql-cursor-api.html[Documentation] + [cols=2*] |=== |`body` @@ -10952,7 +11013,7 @@ client.sql.query({ body: object }) ---- -link:{ref}/sql-rest-overview.html[Documentation] + +link:{ref}/sql-search-api.html[Documentation] + {jsclient}/sql_query_examples.html[Code Example] + [cols=2*] |=== @@ -10973,7 +11034,7 @@ client.sql.translate({ body: object }) ---- -link:{ref}/sql-translate.html[Documentation] + +link:{ref}/sql-translate-api.html[Documentation] + [cols=2*] |=== |`body` diff --git a/index.d.ts b/index.d.ts index 83a1da088..3cd158f79 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2105,6 +2105,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