diff --git a/src/plugins/console/api_server/es_5_0.js b/src/plugins/console/api_server/es_5_0.js new file mode 100644 index 0000000000000..99c9b1c25b6f8 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0.js @@ -0,0 +1,54 @@ +let _ = require("lodash"); +let Api = require('./api'); +let parts = [ + require('./es_5_0/aliases'), + require('./es_5_0/aggregations'), + require('./es_5_0/cat'), + require('./es_5_0/cluster'), + require('./es_5_0/count'), + require('./es_5_0/document'), + require('./es_5_0/field_stats'), + require('./es_5_0/filter'), + require('./es_5_0/nodes'), + require('./es_5_0/globals'), + require('./es_5_0/indices'), + require('./es_5_0/mappings'), + require('./es_5_0/percolator'), + require('./es_5_0/query'), + require('./es_5_0/snapshot_restore'), + require('./es_5_0/search'), + require('./es_5_0/settings'), + require('./es_5_0/templates') +]; + +function ES_5_0() { + Api.call(this, "es_5_0"); + _.each(parts, function (apiSection) { + apiSection(this); + }, this); +} + +ES_5_0.prototype = _.create(Api.prototype, {'constructor': ES_5_0}); + +(function (cls) { + cls.addEndpointDescription = function (endpoint, description) { + if (description) { + var url_params_def = {}; + _.each(description.patterns || [], function (p) { + if (p.indexOf("{indices}") >= 0) { + url_params_def["ignore_unavailable"] = "__flag__"; + url_params_def["allow_no_indices"] = "__flag__"; + url_params_def["expand_wildcards"] = ["open", "closed"]; + } + }); + + if (url_params_def) { + description.url_params = description.url_params || {}; + _.defaults(description.url_params, url_params_def); + } + } + Object.getPrototypeOf(cls).addEndpointDescription.call(this, endpoint, description); + }; +})(ES_5_0.prototype); + +module.exports = new ES_5_0(); diff --git a/src/plugins/console/api_server/es_5_0/aggregations.js b/src/plugins/console/api_server/es_5_0/aggregations.js new file mode 100644 index 0000000000000..ac32e5f72d1ae --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/aggregations.js @@ -0,0 +1,436 @@ +var simple_metric = { + __template: {field: ""}, + field: "{field}", + missing: 0, + script: { + // populated by a global rule + } +}, field_metric = { + __template: {field: ""}, + field: "{field}" +}, gap_policy = { + __one_of: ["skip", "insert_zeros"] +}, simple_pipeline = { + __template: { + buckets_path: "" + }, + buckets_path: "", + format: "", + gap_policy: gap_policy +}; +var rules = { + "*": { + "aggs": { + __template: { + "NAME": { + "AGG_TYPE": {} + } + } + }, + "min": simple_metric, + "max": simple_metric, + "avg": simple_metric, + "sum": simple_metric, + "stats": simple_metric, + "extended_stats": simple_metric, + "value_count": { + __template: { + "field": "" + }, + "field": "{field}", + "script": { + // populated by a global rule + } + }, + "global": {}, + "filter": {}, + "filters": { + __template: { + "filters": { + "NAME": {} + } + }, + "filters": { + "*": {__scope_link: "GLOBAL.filter"} + }, + "other_bucket": {__one_of: [true, false]}, + "other_bucket_key": "" + }, + "missing": field_metric, + "nested": { + __template: { + "path": "" + }, + "path": "" + }, + "reverse_nested": { + __template: { + "path": "" + }, + "path": "" + }, + "terms": { + __template: { + "field": "", + "size": 10 + }, + "field": "{field}", + "size": 10, + "shard_size": 10, + "order": { + __template: { + "_term": "asc" + }, + "_term": {__one_of: ["asc", "desc"]}, + "_count": {__one_of: ["asc", "desc"]}, + "*": {__one_of: ["asc", "desc"]} + }, + "min_doc_count": 10, + "script": { + // populated by a global rule + }, + "include": ".*", + "exclude": ".*", + "execution_hint": {__one_of: ["map", "global_ordinals", "global_ordinals_hash", "global_ordinals_low_cardinality"]}, + "show_term_doc_count_error": {__one_of: [true, false]}, + "collect_mode": {__one_of: ["depth_first", "breadth_first"]}, + "missing": "" + }, + "significant_terms": { + __template: { + "field": "" + }, + "field": "{field}", + "size": 10, + "shard_size": 10, + "shard_min_doc_count": 10, + "min_doc_count": 10, + "include": {__one_of: ["*", {pattern: "", flags: ""}]}, + "exclude": {__one_of: ["*", {pattern: "", flags: ""}]}, + "execution_hint": {__one_of: ["map", "global_ordinals", "global_ordinals_hash"]}, + "background_filter": { + __scope_link: "GLOBAL.filter" + }, + "mutual_information": { + "include_negatives": {__one_of: [true, false]} + }, + "chi_square": { + "include_negatives": {__one_of: [true, false]}, + "background_is_superset": {__one_of: [true, false]} + }, + "percentage": {}, + "gnd": { + "background_is_superset": {__one_of: [true, false]} + }, + "script_heuristic": { + __template: { + "script": "_subset_freq/(_superset_freq - _subset_freq + 1)" + }, + "script": { + // populated by a global rule + } + } + }, + "range": { + __template: { + "field": "", + "ranges": [ + {"from": 50, "to": 100}, + ] + }, + "field": "{field}", + "ranges": [ + {"to": 50, "from": 100, "key": ""} + ], + "keyed": {__one_of: [true, false]}, + "script": { + // populated by a global rule + } + }, + "date_range": { + __template: { + "field": "", + "ranges": [ + {"from": "now-10d/d", "to": "now"}, + ] + }, + "field": "{field}", + "format": "MM-yyy", + "ranges": [ + {"to": "", "from": "", "key": ""} + ], + "keyed": {__one_of: [true, false]}, + "script": { + // populated by a global rule + } + }, + "ip_range": { + __template: { + "field": "", + "ranges": [ + {"from": "10.0.0.5", "to": "10.0.0.10"}, + ] + }, + "field": "{field}", + "format": "MM-yyy", + "ranges": [ + {"to": "", "from": "", "key": "", "mask": "10.0.0.127/25"} + ], + "keyed": {__one_of: [true, false]}, + "script": { + // populated by a global rule + } + }, + "histogram": { + __template: { + "field": "price", + "interval": 50 + }, + "field": "{field}", + "interval": 50, + "min_doc_count": 0, + "order": { + __template: { + "_key": "asc" + }, + "_key": {__one_of: ["asc", "desc"]}, + "_count": {__one_of: ["asc", "desc"]}, + "*": {__one_of: ["asc", "desc"]} + }, + "keyed": {__one_of: [true, false]}, + "missing": 0 + }, + "date_histogram": { + __template: { + "field": "date", + "interval": "month" + }, + "field": "{field}", + "interval": {__one_of: ["year", "quarter", "week", "day", "hour", "minute", "second"]}, + "min_doc_count": 0, + "order": { + __template: { + "_key": "asc" + }, + "_key": {__one_of: ["asc", "desc"]}, + "_count": {__one_of: ["asc", "desc"]}, + "*": {__one_of: ["asc", "desc"]} + }, + "keyed": {__one_of: [true, false]}, + "pre_zone": "-01:00", + "post_zone": "-01:00", + "pre_zone_adjust_large_interval": {__one_of: [true, false]}, + "factor": 1000, + "pre_offset": "1d", + "post_offset": "1d", + "format": "yyyy-MM-dd", + "time_zone": "00:00", + "missing": "" + }, + "geo_distance": { + __template: { + "field": "location", + "origin": {"lat": 52.3760, "lon": 4.894}, + "ranges": [ + {"from": 100, "to": 300}, + ] + }, + "field": "{field}", + "origin": {"lat": 0.0, "lon": 0.0}, + "unit": {__one_of: ["mi", "km", "in", "yd", "m", "cm", "mm"]}, + "ranges": [ + {"from": 50, "to": 100} + ], + "distance_type": {__one_of: ["arc", "sloppy_arc", "plane"]} + + }, + "geohash_grid": { + __template: { + "field": "", + "precision": 3 + }, + "field": "{field}", + "precision": {__one_of: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]}, + "size": 10, + "shard_size": 10 + }, + "percentiles": { + __template: { + "field": "", + "percents": [1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0] + }, + "field": "{field}", + "percents": { + __template: [1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0], + // mark type as list + __any_of: [] + }, + "script": { + // populated by a global rule + }, + "compression": 100, + "method": {__one_of: ["hdr", "tdigest"]}, + missing: 0 + }, + "cardinality": { + __template: { + "field": "" + }, + "precision_threshold": 100, + "rehash": true, + "script": { + // populated by a global rule + }, + missing: "" + }, + "scripted_metric": { + __template: { + "init_script": "", + "map_script": "", + "combine_script": "", + "reduce_script": "" + }, + "init_script": { + __scope_link: "GLOBAL.script" + }, + "map_script": { + __scope_link: "GLOBAL.script" + }, + "combine_script": { + __scope_link: "GLOBAL.script" + }, + "reduce_script": { + __scope_link: "GLOBAL.script" + }, + "lang": "groovy", + "params": {}, + "reduce_params": {} + }, + "geo_bounds": { + __template: { + field: "" + }, + field: "{field}", + wrap_longitude: {__one_of: [true, false]} + }, + "top_hits": { + __template: { + size: 10 + }, + from: 0, + size: 10, + sort: { + __template: [], + __scope_link: "_search.sort" + }, + highlight: {}, + explain: {__one_of: [true, false]}, + _source: { + __template: "", + __scope_link: "_search._source" + }, + script_fields: { + __scope_link: "_search.script_fields" + }, + fielddata_fields: ["{field}"], + version: {__one_of: [true, false]} + }, + "percentile_ranks": { + __template: { + field: "", + values: [10, 15] + }, + field: "{field}", + values: [], + "script": { + // populated by a global rule + }, + "compression": 100, + "method": {__one_of: ["hdr", "tdigest"]}, + missing: 0 + }, + "sampler": { + __template: {}, + "field": "{field}", + "script": { + // populated by a global rule + }, + "shard_size": 100, + "max_docs_per_value": 3, + "execution_hint": {__one_of: ["map", "global_ordinals", "bytes_hash"]} + }, + "children": { + __template: { + "type": "", + }, + "type": "" + }, + "derivative": simple_pipeline, + "avg_bucket": simple_pipeline, + "max_bucket": simple_pipeline, + "min_bucket": simple_pipeline, + "sum_bucket": simple_pipeline, + "moving_avg": { + __template: { + buckets_path: "" + }, + buckets_path: "", + format: "", + gap_policy: gap_policy, + "window": 5, + model: {__one_of: ["simple", "linear", "ewma", "holt", "holt_winters"]}, + settings: { + type: {__one_of: ["add", "mult"]}, + alpha: 0.5, + beta: 0.5, + gamma: 0.5, + period: 7 + } + }, + "cumulative_sum": { + __template: { + buckets_path: "" + }, + buckets_path: "", + format: "" + }, + "serial_diff": { + __template: { + buckets_path: "", + lag: 7 + }, + lag: 7, + gap_policy: gap_policy, + buckets_path: "", + format: "" + }, + "bucket_script": { + __template: { + buckets_path: "", + script: {} + }, + buckets_path: "", + format: "", + gap_policy: gap_policy, + script: { + // populated by a global rule + } + }, + "bucket_selector": { + __template: { + buckets_path: "", + script: {} + }, + buckets_path: "", + gap_policy: gap_policy, + script: { + // populated by a global rule + } + } + } +}; +module.exports = function (api) { + + api.addGlobalAutocompleteRules('aggregations', rules); + api.addGlobalAutocompleteRules('aggs', rules); +}; diff --git a/src/plugins/console/api_server/es_5_0/aliases.js b/src/plugins/console/api_server/es_5_0/aliases.js new file mode 100644 index 0000000000000..832a1ed8a3ae0 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/aliases.js @@ -0,0 +1,71 @@ +module.exports = function (api) { + api.addEndpointDescription('_post_aliases', { + methods: ['POST'], + patterns: [ + "_aliases", + ], + data_autocomplete_rules: { + 'actions': { + __template: [ + {'add': {'index': 'test1', 'alias': 'alias1'}} + ], + __any_of: [ + { + add: { + index: '{index}', + alias: '', + filter: {}, + routing: '1', + search_routing: '1,2', + index_routing: '1' + }, + remove: { + index: '', + alias: '' + } + } + ] + } + } + }); + api.addEndpointDescription('_get_aliases', { + methods: ['GET'], + patterns: [ + "_aliases", + ] + }); + + var aliasRules = { + filter: {}, + routing: '1', + search_routing: '1,2', + index_routing: '1' + }; + + api.addEndpointDescription('_post_alias', { + methods: ["POST", "PUT"], + patterns: [ + "{indices}/_alias/{name}" + ], + data_autocomplete_rules: aliasRules + }); + api.addEndpointDescription('_delete_alias', { + methods: ["DELETE"], + patterns: [ + "{indices}/_alias/{name}" + ] + }); + api.addEndpointDescription('_get_alias', { + methods: ["GET"], + patterns: [ + "_alias", + "{indices}/_alias", + "{indices}/_alias/{name}", + "_alias/{name}" + ] + }); + + api.addGlobalAutocompleteRules('aliases', { + '*': aliasRules + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/cat.js b/src/plugins/console/api_server/es_5_0/cat.js new file mode 100644 index 0000000000000..af8a496d63e4e --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/cat.js @@ -0,0 +1,56 @@ +let _ = require("lodash"); + +function addSimpleCat(endpoint, api, params, patterns) { + var url_params = {"help": "__flag__", "v": "__flag__", "bytes": ["b"]}; + _.each(params || [], function (p) { + if (_.isString(p)) { + url_params[p] = "__flag__"; + } + else { + var k = Object.keys(p)[0]; + url_params[k] = p[k]; + } + }); + api.addEndpointDescription(endpoint, { + match: endpoint, + url_params: url_params, + patterns: patterns || [endpoint] + }); +} + +function addNodeattrsCat(api) { + api.addEndpointDescription('_cat/nodeattrs', { + methods: ['GET'], + patterns: [ + "_cat/nodeattrs" + ], + url_params: { + help: "__flag__", + v: "__flag__", + h: ["node", "name", "id", "nodeId", "pid", "p", "host", "h", "ip", "i", "port", "po", "attr", "attr.name", "value", "attr.value"] + } + }); +} + +module.exports = function (api) { + addSimpleCat('_cat/aliases', api); + addSimpleCat('_cat/allocation', api, null, ['_cat/allocation', '_cat/allocation/{nodes}']); + addSimpleCat('_cat/count', api); + addSimpleCat('_cat/health', api, [ + {"ts": ["false", "true"]} + ]); + addSimpleCat('_cat/indices', api, [ + {h: []}, + "pri", + ], + ['_cat/indices', '_cat/indices/{indices}']); + addSimpleCat('_cat/master', api); + addSimpleCat('_cat/nodes', api); + addSimpleCat('_cat/pending_tasks', api); + addSimpleCat('_cat/recovery', api); + addSimpleCat('_cat/thread_pool', api); + addSimpleCat('_cat/shards', api); + addSimpleCat('_cat/plugins', api); + addSimpleCat('_cat/segments', api); + addNodeattrsCat(api); +}; diff --git a/src/plugins/console/api_server/es_5_0/cluster.js b/src/plugins/console/api_server/es_5_0/cluster.js new file mode 100644 index 0000000000000..a6519e81ed6e4 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/cluster.js @@ -0,0 +1,142 @@ +module.exports = function (api) { + api.addEndpointDescription('_cluster/nodes/stats'); + api.addEndpointDescription('_cluster/state', { + patterns: [ + "_cluster/state", + "_cluster/state/{metrics}", + "_cluster/state/{metrics}/{indices}" + ], + url_components: { + "metrics": ["version", "master_node", "nodes", "routing_table", "routing_node", "metadata", "blocks"] + } + }); + api.addEndpointDescription('_cluster/health', { + url_params: { + "local": "__flag__", + "level": ["indices", "shards"], + "master_timeout": "30s", + "timeout": "30s", + "wait_for_status": ["yellow", "green"], + "wait_for_relocating_shards": 0, + "wait_for_active_shards": 0, + "wait_for_nodes": 0 + } + }); + api.addEndpointDescription('_cluster/pending_tasks'); + api.addEndpointDescription('get_cluster/settings', { + patterns: [ + '_cluster/settings' + ] + }); + + api.addEndpointDescription('put_cluster/settings', { + methods: ['PUT'], + patterns: [ + '_cluster/settings' + ], + data_autocomplete_rules: { + persistent: { + cluster: { + routing: { + 'allocation.enable': {__one_of: ["all", "primaries", "new_primaries", "none"]}, + 'allocation.disk.threshold_enabled': {__one_of: [false, true]}, + 'allocation.disk.watermark.low': '85%', + 'allocation.disk.watermark.high': '90%', + 'allocation.disk.include_relocations': {__one_of: [true, false]}, + 'allocation.disk.reroute_interval': '60s', + 'allocation.exclude': { + '_ip': "", + '_name': "", + '_host': "", + '_id': "" + }, + 'allocation.include': { + '_ip': "", + '_name': "", + '_host': "", + '_id': "" + }, + 'allocation.require': { + '_ip': "", + '_name': "", + '_host': "", + '_id': "" + }, + 'allocation.awareness.attributes': [], + 'allocation.awareness.force': { + '*': { + 'values': [] + } + }, + 'allocation.allow_rebalance': {__one_of: ['always', 'indices_primaries_active', 'indices_all_active']}, + 'allocation.cluster_concurrent_rebalance': 2, + 'allocation.node_initial_primaries_recoveries': 4, + 'allocation.node_concurrent_recoveries': 2, + 'allocation.same_shard.host': {__one_of: [false, true]} + } + }, + indices: { + breaker: { + "total.limit": "70%", + "fielddata.limit": "60%", + "fielddata.overhead": 1.03, + "request.limit": "40%", + "request.overhead": 1.0 + } + } + }, + transient: { + __scope_link: '.persistent' + } + } + }); + + api.addEndpointDescription('_cluster/reroute', { + methods: ['POST'], + url_params: { + explain: "__flag__", + dry_run: "__flag__" + }, + data_autocomplete_rules: { + commands: [ + { + move: { + __template: { + index: "", + shard: 0, + from_node: "", + to_node: "" + }, + index: "{index}", + shard: 0, + from_node: "{node}", + to_node: "{node}" + }, + cancel: { + __template: { + index: "", + shard: 0, + node: "" + }, + index: "{index}", + shard: 0, + node: "{node}", + allow_primary: {__one_of: [true, false]} + }, + allocate: { + __template: { + index: "", + shard: 0, + node: "" + }, + index: "{index}", + shard: 0, + node: "{node}", + allow_primary: {__one_of: [true, false]} + } + } + ], + dry_run: {__one_of: [true, false]} + } + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/count.js b/src/plugins/console/api_server/es_5_0/count.js new file mode 100644 index 0000000000000..6bbcb3a9f6b85 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/count.js @@ -0,0 +1,22 @@ +module.exports = function (api) { + api.addEndpointDescription('_count', { + methods: ['GET', 'POST'], + priority: 10, // collides with get doc by id + patterns: [ + "{indices}/{types}/_count", + "{indices}/_count", + "_count" + ], + url_params: { + preference: ["_primary", "_primary_first", "_local", "_only_node:xyz", "_prefer_node:xyz", "_shards:2,3"], + routing: "", + min_score: 1.0, + terminate_after: 10, + }, + data_autocomplete_rules: { + query: { + // populated by a global rule + } + } + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/document.js b/src/plugins/console/api_server/es_5_0/document.js new file mode 100644 index 0000000000000..caf36cb33a5ac --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/document.js @@ -0,0 +1,233 @@ +module.exports = function (api) { + api.addEndpointDescription('_get_doc', { + methods: ['GET'], + patterns: [ + "{index}/{type}/{id}" + ], + url_params: { + "version": 1, + "routing": "", + "parent": "", + "_source": "", + "_source_exclude": "", + "_source_include": "" + } + }); + api.addEndpointDescription('_get_doc_source', { + methods: ['GET'], + patterns: [ + "{index}/{type}/{id}/_source" + ], + url_params: { + "version": 1, + "routing": "", + "parent": "", + "_source_exclude": "", + "_source_include": "" + } + }); + api.addEndpointDescription('_delete_doc', { + methods: ['DELETE'], + patterns: [ + "{index}/{type}/{id}" + ], + url_params: { + "version": 1, + "version_type": ["external", "internal"], + "routing": "", + "parent": "" + } + }); + api.addEndpointDescription('index_doc', { + methods: ['PUT', 'POST'], + patterns: [ + "{index}/{type}/{id}" + ], + url_params: { + "version": 1, + "version_type": ["external", "internal"], + "op_type": ["create"], + "routing": "", + "parent": "", + "timestamp": "", + "ttl": "5m", + "consistency": ["qurom", "one", "all"], + "refresh": "__flag__", + "timeout": "1m" + } + }); + api.addEndpointDescription('create_doc', { + methods: ['PUT', 'POST'], + patterns: [ + "{index}/{type}/{id}/_create" + ], + url_params: { + "version": 1, + "version_type": ["external", "internal"], + "routing": "", + "parent": "", + "timestamp": "", + "ttl": "5m", + "consistency": ["qurom", "one", "all"], + "refresh": "__flag__", + "timeout": "1m" + } + }); + api.addEndpointDescription('index_doc_no_id', { + methods: ['POST'], + patterns: [ + "{index}/{type}" + ], + url_params: { + "version": 1, + "version_type": ["external", "internal"], + "routing": "", + "parent": "", + "timestamp": "", + "ttl": "5m", + "consistency": ["qurom", "one", "all"], + "refresh": "__flag__", + "timeout": "1m" + } + }); + + api.addEndpointDescription('_update', { + methods: ['POST'], + patterns: [ + "{index}/{type}/{id}/_update" + ], + url_params: { + "version": 1, + "version_type": ["force", "internal"], + "routing": "", + "parent": "", + "timestamp": "", + "consistency": ["qurom", "one", "all"], + "refresh": "__flag__", + "timeout": "1m", + "retry_on_conflict": 3, + "fields": "" + }, + data_autocomplete_rules: { + "script": { + // populated by a global rule + }, + "doc": {}, + "upsert": {}, + "scripted_upsert": {__one_of: [true, false]} + } + + }); + + api.addEndpointDescription('_put_script', { + methods: ['POST', 'PUT'], + patterns: [ + "_scripts/{lang}/{id}", + "_scripts/{lang}/{id}/_create" + ], + url_components: { + "lang": [ + "groovy", + "expressions" + ] + }, + data_autocomplete_rules: { + "script": "" + } + }); + + api.addEndpointDescription('_termvectors', { + methods: ['GET', 'POST'], + patterns: [ + "{index}/{type}/_termvectors" + ], + priority: 10, // collision with get doc + url_params: { + "fields": "", + "offsets": "__flag__", + "payloads": "__flag__", + "positions": "__flag__", + "term_statistics": "__flag__", + "field_statistics": "__flag__", + "routing": "", + "version": 1, + "version_type": ["external", "external_gt", "external_gte", "force", "internal"], + "parent": "", + "preference": "" + }, + data_autocomplete_rules: { + fields: [ + "{field}" + ], + offsets: {__one_of: [false, true]}, + payloads: {__one_of: [false, true]}, + positions: {__one_of: [false, true]}, + term_statistics: {__one_of: [true, false]}, + field_statistics: {__one_of: [false, true]}, + per_field_analyzer: { + __template: {"FIELD": ""}, + "{field}": "" + }, + routing: "", + version: 1, + version_type: ["external", "external_gt", "external_gte", "force", "internal"], + doc: {}, + filter: { // TODO: Exclude from global filter rules + "max_num_terms": 1, + "min_term_freq": 1, + "max_term_freq": 1, + "min_doc_freq": 1, + "max_doc_freq": 1, + "min_word_length": 1, + "max_word_length": 1 + } + } + }); + api.addEndpointDescription('_termvectors_id', { + methods: ['GET', 'POST'], + patterns: [ + "{index}/{type}/{id}/_termvectors" + ], + url_params: { + "fields": "", + "offsets": "__flag__", + "payloads": "__flag__", + "positions": "__flag__", + "term_statistics": "__flag__", + "field_statistics": "__flag__", + "routing": "", + "version": 1, + "version_type": ["external", "external_gt", "external_gte", "force", "internal"], + "parent": "", + "preference": "", + "dfs": "__flag__" + }, + data_autocomplete_rules: { + fields: [ + "{field}" + ], + offsets: {__one_of: [false, true]}, + payloads: {__one_of: [false, true]}, + positions: {__one_of: [false, true]}, + term_statistics: {__one_of: [true, false]}, + field_statistics: {__one_of: [false, true]}, + dfs: {__one_of: [true, false]}, + per_field_analyzer: { + __template: {"FIELD": ""}, + "{field}": "" + }, + routing: "", + version: 1, + version_type: ["external", "external_gt", "external_gte", "force", "internal"], + filter: { // TODO: Exclude from global filter rules + "max_num_terms": 1, + "min_term_freq": 1, + "max_term_freq": 1, + "min_doc_freq": 1, + "max_doc_freq": 1, + "min_word_length": 1, + "max_word_length": 1 + } + } + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/field_stats.js b/src/plugins/console/api_server/es_5_0/field_stats.js new file mode 100644 index 0000000000000..58c35e6ed0eb3 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/field_stats.js @@ -0,0 +1,47 @@ +module.exports = function (api) { + api.addEndpointDescription('_field_stats', { + methods: ['GET', 'POST'], + patterns: [ + "_field_stats", + "{indices}/_field_stats" + ], + url_params: { + fields: [], + level: ["cluster", "indices"], + ignore_unavailable: ["true", "false"], + allow_no_indices: [false, true], + expand_wildcards: ["open", "closed", "none", "all"] + }, + data_autocomplete_rules: { + fields: [ + "{field}", + ], + index_constraints: { + "{field}": { + min_value: { + gt: "MIN", + gte: "MAX", + lt: "MIN", + lte: "MAX" + }, + max_value: { + gt: "MIN", + gte: "MAX", + lt: "MIN", + lte: "MAX" + } + }, + __template: { + "FIELD": { + min_value: { + gt: "MIN" + }, + max_value: { + lt: "MAX" + } + } + } + } + } + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/filter.js b/src/plugins/console/api_server/es_5_0/filter.js new file mode 100644 index 0000000000000..877c0495fc40a --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/filter.js @@ -0,0 +1,336 @@ +var filters = {}; + +filters.and = { + __template: { + filters: [ + {} + ] + }, + filters: [ + { + __scope_link: '.' + } + ], +}; + + +filters.bool = { + __scope_link: 'GLOBAL.query' +}; + + +filters.exists = { + __template: { + 'field': 'FIELD_NAME' + }, + 'field': '{field}' +}; + + +filters.ids = { + __template: { + 'values': ['ID'] + }, + 'type': '{type}', + 'values': [''] +}; + + +filters.limit = { + __template: { + value: 100 + }, + value: 100 +}; + + +filters.type = { + __template: { + value: 'TYPE' + }, + value: '{type}' +}; + + +filters.geo_bounding_box = { + __template: { + 'FIELD': { + 'top_left': { + 'lat': 40.73, + 'lon': -74.1 + }, + 'bottom_right': { + 'lat': 40.717, + 'lon': -73.99 + } + } + }, + + '{field}': { + top_left: { + lat: 40.73, + lon: -74.1 + }, + bottom_right: { + lat: 40.73, + lon: -74.1 + } + }, + type: { + __one_of: ['memory', 'indexed'] + }, +}; + + +filters.geo_distance = { + __template: { + distance: 100, + distance_unit: 'km', + 'FIELD': { + lat: 40.73, + lon: -74.1 + } + }, + distance: 100, + distance_unit: { + __one_of: ['km', 'miles'] + }, + distance_type: { + __one_of: ['arc', 'plane'] + }, + optimize_bbox: { + __one_of: ['memory', 'indexed', 'none'] + }, + '{field}': { + lat: 40.73, + lon: -74.1 + }, +}; + + +filters.geo_distance_range = { + __template: { + from: 100, + to: 200, + distance_unit: 'km', + 'FIELD': { + lat: 40.73, + lon: -74.1 + } + }, + from: 100, + to: 200, + + distance_unit: { + __one_of: ['km', 'miles'] + }, + distance_type: { + __one_of: ['arc', 'plane'] + }, + include_lower: { + __one_of: [true, false] + }, + include_upper: { + __one_of: [true, false] + }, + + '{field}': { + lat: 40.73, + lon: -74.1 + } +}; + + +filters.geo_polygon = { + __template: { + 'FIELD': { + 'points': [ + { + lat: 40.73, + lon: -74.1 + }, + { + lat: 40.83, + lon: -75.1 + } + ] + } + }, + '{field}': { + points: [ + { + lat: 40.73, + lon: -74.1 + } + ] + } +}; + + +filters.geo_shape = { + __template: { + 'FIELD': { + shape: { + type: 'envelope', + coordinates: [ + [-45, 45], + [45, -45] + ] + }, + 'relation': 'within' + } + }, + '{field}': { + shape: { + type: '', + coordinates: [] + }, + indexed_shape: { + id: '', + index: '{index}', + type: '{type}', + shape_field_name: 'shape' + }, + relation: { + __one_of: ['within', 'intersects', 'disjoint'] + } + } +}; + + +filters.has_child = { + __template: { + type: 'TYPE', + filter: {} + }, + type: '{type}', + query: {}, + filter: {}, + _scope: '', + min_children: 1, + max_children: 10 +}; + + +filters.has_parent = { + __template: { + parent_type: 'TYPE', + filter: {} + }, + parent_type: '{type}', + query: {}, + filter: {}, + _scope: '' +}; + + +filters.m = filters.missing = { + __template: { + field: 'FIELD' + }, + existence: { + __one_of: [true, false] + }, + null_value: { + __one_of: [true, false] + }, + field: '{field}' +}; + + +filters.not = { + __template: { + filter: {} + }, + filter: {} +}; + + +filters.range = { + __template: { + 'FIELD': { + gte: 10, + lte: 20 + } + }, + "{field}": { + gte: 1, + gt: 1, + lte: 20, + lt: 20, + time_zone: "+1:00", + "format": "dd/MM/yyyy||yyyy", + execution: {__one_of: ["index", "fielddata"]} + } +}; + + +filters.or = { + __template: { + filters: [ + {} + ] + }, + filters: [ + { + __scope_link: '.' + } + ] +}; + + +filters.prefix = { + __template: { + 'FIELD': 'VALUE' + }, + '{field}': '' +}; + + +filters.query = { + // global query +}; + +filters.script = { + __template: { + script: {} + }, + script: { + // populated by a global rule + } +}; + + +filters.term = { + __template: { + 'FIELD': 'VALUE' + }, + '{field}': '' +}; + + +filters.terms = { + __template: { + 'FIELD': ['VALUE1', 'VALUE2'] + }, + field: ['{field}'], + execution: { + __one_of: ['plain', 'bool', 'and', 'or', 'bool_nocache', 'and_nocache', 'or_nocache'] + } +}; + + +filters.nested = { + __template: { + path: 'path_to_nested_doc', + query: {} + }, + query: {}, + path: '', + _name: '' +}; + +module.exports = function (api) { + api.addGlobalAutocompleteRules('filter', filters); +}; + diff --git a/src/plugins/console/api_server/es_5_0/globals.js b/src/plugins/console/api_server/es_5_0/globals.js new file mode 100644 index 0000000000000..e8cd849226151 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/globals.js @@ -0,0 +1,24 @@ +module.exports = function (api) { + api.addGlobalAutocompleteRules('highlight', { + pre_tags: {}, + post_tags: {}, + tags_schema: {}, + fields: { + '{field}': { + fragment_size: 20, + number_of_fragments: 3 + } + } + }); + + api.addGlobalAutocompleteRules('script', { + __template: { + inline: "SCRIPT" + }, + inline: "SCRIPT", + file: "FILE_SCRIPT_NAME", + id: "SCRIPT_ID", + lang: "", + params: {} + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/indices.js b/src/plugins/console/api_server/es_5_0/indices.js new file mode 100644 index 0000000000000..50e68697d0e50 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/indices.js @@ -0,0 +1,208 @@ +module.exports = function (api) { + api.addEndpointDescription('_refresh', { + methods: ['POST'], + patterns: [ + "_refresh", + "{indices}/_refresh" + ], + }); + + api.addEndpointDescription('_flush', { + methods: ['POST'], + patterns: [ + "_flush", + "{indices}/_flush" + ], + url_params: { + wait_if_ongoing: [true, false], + force: [true, false] + } + }); + + api.addEndpointDescription('_flush_synced', { + methods: ['POST'], + patterns: [ + "_flush/synced", + "{indices}/_flush/synced" + ] + }); + + api.addEndpointDescription('_stats', { + patterns: [ + "_stats", + "_stats/{metrics}", + "{indices}/_stats", + "{indices}/_stats/{metrics}", + ], + url_components: { + "metrics": [ + "docs", + "store", + "indexing", + "search", + "get", + "merge", + "refresh", + "flush", + "warmer", + "filter_cache", + "percolate", + "segments", + "fielddata", + "completion", + "translog", + "query_cache", + "commit", + "_all" + ] + }, + url_params: { + "fields": [], + "types": [], + "completion_fields": [], + "fielddata_fields": [], + "level": ["cluster", "indices", "shards"] + } + + }); + + api.addEndpointDescription('_segments', { + patterns: [ + "{indices}/_segments", + "_segments" + ] + }); + + api.addEndpointDescription('_recovery', { + patterns: [ + "{indices}/_recovery", + "_recovery" + ], + url_params: { + detailed: "__flag__", + active_only: "__flag__", + human: "__flag__" + } + }); + + api.addEndpointDescription('_analyze', { + methods: ['GET', 'POST'], + patterns: [ + "{indices}/_analyze", + "_analyze" + ], + url_params: { + "analyzer": "", + "char_filters": [], + "field": "", + "filters": [], + "text": "", + "tokenizer": "" + } + }); + + api.addEndpointDescription('_validate_query', { + methods: ['GET', 'POST'], + patterns: [ + "{indices}/_validate/query", + "_validate/query" + ], + url_params: { + explain: "__flag__", + rewrite: "__flag__" + }, + data_autocomplete_rules: { + query: { + // populated by a global rule + } + } + }); + + api.addEndpointDescription('_shard_stores', { + methods: ['GET'], + patterns: [ + "{indices}/_shard_stores", + "_shard_stores" + ], + url_params: { + status: ["green", "yellow", "red", "all"] + } + }); + + api.addEndpointDescription('__create_index__', { + methods: ['PUT'], + patterns: [ + "{index}" + ], + data_autocomplete_rules: { + mappings: { + __scope_link: '_put_mapping' + }, + settings: { + __scope_link: '_put_settings' + }, + aliases: { + __template: { + "NAME": {} + } + } + } + }); + + api.addEndpointDescription('__delete_indices__', { + methods: ['DELETE'], + patterns: [ + "{indices}" + ] + }); + + api.addEndpointDescription('_get_index_settings', { + methods: ['GET',], + patterns: [ + "{indices}/_settings", + ], + url_params: { + flat_settings: "__flag__" + } + }); + + api.addEndpointDescription('_get_index', { + methods: ['GET',], + patterns: [ + "{indices}", + "{indices}/{feature}" + ], + url_components: { + "feature": [ + "_mappings", + "_aliases" + ] + } + }); + + api.addEndpointDescription('_cache/clear', { + patterns: [ + "_cache/clear", + "{indices}/_cache/clear" + ] + }); + + api.addEndpointDescription('_upgrade', { + methods: ["POST"], + patterns: [ + "_upgrade", + "{indices}/_upgrade" + ], + url_params: { + wait_for_completion: "__flag__" + } + }); + + api.addEndpointDescription('_upgrade_status', { + methods: ["GET"], + patterns: [ + "_upgrade", + "{indices}/_upgrade" + ] + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/mappings.js b/src/plugins/console/api_server/es_5_0/mappings.js new file mode 100644 index 0000000000000..054c62917ceb9 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/mappings.js @@ -0,0 +1,218 @@ +let _ = require("lodash"); + +var BOOLEAN = { + __one_of: [true, false] +}; + +module.exports = function (api) { + api.addEndpointDescription('_get_mapping', { + methods: ['GET'], + priority: 10, // collides with get doc by id + patterns: [ + "{indices}/_mapping", + "{indices}/_mapping/{types}", + "{indices}/{types}/_mapping", + "_mapping" + ] + }); + api.addEndpointDescription('_get_field_mapping', { + methods: ['GET'], + priority: 10, // collides with get doc by id + patterns: [ + "{indices}/_mapping/field/{fields}", + "{indices}/_mapping/{type}/field/{fields}" + ], + url_params: { + "include_defaults": "__flag__" + } + }); + api.addEndpointDescription('_delete_mapping', { + methods: ['DELETE'], + priority: 10, // collides with get doc by id + patterns: [ + "{indices}/_mapping", + "{indices}/_mapping/{types}", + "{indices}/{types}/_mapping", + "_mapping" + ] + }); + api.addEndpointDescription('_put_type_mapping', { + methods: ['PUT', 'POST'], + patterns: [ + "{indices}/{type}/_mapping", + "{indices}/_mapping/{type}" + ], + priority: 10, // collides with put doc by id + data_autocomplete_rules: { + __template: { + properties: { + 'FIELD': {} + } + }, + '_source': { + 'enabled': BOOLEAN + }, + '_all': { + 'enabled': BOOLEAN + }, + '_field_names': { + 'index': BOOLEAN + }, + '_routing': { + 'required': BOOLEAN, + }, + '_index': { + 'enabled': BOOLEAN + }, + '_parent': { + __template: { + 'type': '' + }, + 'type': '{type}' + }, + '_timestamp': { + 'enabled': BOOLEAN, + 'format': 'YYYY-MM-dd', + 'default': "" + }, + 'dynamic_date_formats': ['yyyy-MM-dd'], + 'date_detection': BOOLEAN, + 'numeric_detection': BOOLEAN, + 'properties': { + '*': { + type: { + __one_of: ['text', 'keyword', 'float', 'double', 'byte', 'short', 'integer', 'long', 'date', 'boolean', + 'binary', 'object', 'nested', "geo_point", "geo_shape" + ] + }, + + // strings + store: BOOLEAN, + index: BOOLEAN, + term_vector: { + __one_of: ['no', 'yes', 'with_offsets', 'with_positions', 'with_positions_offsets'] + }, + boost: 1.0, + null_value: '', + + norms: BOOLEAN, + + index_options: { + __one_of: ['docs', 'freqs', 'positions'] + }, + analyzer: 'standard', + search_analyzer: 'standard', + include_in_all: { + __one_of: [false, true] + }, + ignore_above: 10, + position_increment_gap: 0, + + // numeric + precision_step: 4, + ignore_malformed: BOOLEAN, + + // geo_point + lat_lon: { + __one_of: [true, false] + }, + geohash: { + __one_of: [true, false] + }, + geohash_precision: '1m', + geohash_prefix: { + __one_of: [true, false] + }, + validate: { + __one_of: [true, false] + }, + validate_lat: { + __one_of: [true, false] + }, + validate_lon: { + __one_of: [true, false] + }, + normalize: { + __one_of: [true, false] + }, + normalize_lat: { + __one_of: [true, false] + }, + normalize_lon: { + __one_of: [true, false] + }, + + // geo_shape + tree: { + __one_of: ['geohash', 'quadtree'] + }, + precision: '5km', + tree_levels: 12, + distance_error_pct: 0.025, + orientation: 'ccw', + + // dates + format: { + __one_of: _.flatten([_.map(['date', 'date_time', 'date_time_no_millis', + 'ordinal_date', 'ordinal_date_time', 'ordinal_date_time_no_millis', + 'time', 'time_no_millis', 't_time', 't_time_no_millis', + 'week_date', 'week_date_time', 'week_date_time_no_millis'], function (s) { + return ['basic_' + s, 'strict_' + s]; + }), + [ + 'date', 'date_hour', 'date_hour_minute', 'date_hour_minute_second', 'date_hour_minute_second_fraction', + 'date_hour_minute_second_millis', 'date_optional_time', 'date_time', 'date_time_no_millis', + 'hour', 'hour_minute', 'hour_minute_second', 'hour_minute_second_fraction', 'hour_minute_second_millis', + 'ordinal_date', 'ordinal_date_time', 'ordinal_date_time_no_millis', 'time', 'time_no_millis', + 't_time', 't_time_no_millis', 'week_date', 'week_date_time', 'weekDateTimeNoMillis', 'week_year', + 'weekyearWeek', 'weekyearWeekDay', 'year', 'year_month', 'year_month_day', 'epoch_millis', 'epoch_second' + ]]) + }, + + fielddata: { + filter: { + regex: '', + frequency: { + min: 0.001, + max: 0.1, + min_segment_size: 500 + } + } + }, + similarity: { + __one_of: ['default', 'BM25'] + }, + + // objects + properties: { + __scope_link: '_put_mapping.{type}.properties' + }, + + // multi_field + fields: { + '*': { + __scope_link: '_put_mapping.type.properties.field' + } + }, + copy_to: {__one_of: ['{field}', ['{field}']]}, + + // nested + include_in_parent: BOOLEAN, + include_in_root: BOOLEAN + } + } + } + + }); + api.addEndpointDescription('_put_mapping', { + methods: ['PUT'], + patterns: [ + "{indices}/_mapping" + ], + data_autocomplete_rules: { + '{type}': { + __scope_link: '_put_type_mapping' + } + } + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/nodes.js b/src/plugins/console/api_server/es_5_0/nodes.js new file mode 100644 index 0000000000000..a3c4799436c2a --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/nodes.js @@ -0,0 +1,76 @@ +module.exports = function (api) { + api.addEndpointDescription('_nodes/hot_threads', { + methods: ['GET'], + patterns: [ + "_nodes/hot_threads", + "_nodes/{nodes}/hot_threads" + ] + }); + api.addEndpointDescription('_nodes/info', { + patterns: [ + "_nodes", + "_nodes/{metrics}", + "_nodes/{nodes}", + "_nodes/{nodes}/{metrics}", + "_nodes/{nodes}/info/{metrics}" + ], + url_components: { + "metrics": [ + "settings", + "os", + "process", + "jvm", + "thread_pool", + "network", + "transport", + "http", + "plugins", + "_all" + ] + } + }); + api.addEndpointDescription('_nodes/stats', { + patterns: [ + "_nodes/stats", + "_nodes/stats/{metrics}", + "_nodes/stats/{metrics}/{index_metric}", + "_nodes/{nodes}/stats", + "_nodes/{nodes}/stats/{metrics}", + "_nodes/{nodes}/stats/{metrics}/{index_metric}" + ], + url_components: { + "metrics": [ + "os", + "jvm", + "thread_pool", + "network", + "fs", + "transport", + "http", + "indices", + "process", + "breaker", + "_all" + ], + "index_metric": [ + "store", + "indexing", + "get", + "search", + "merge", + "flush", + "refresh", + "filter_cache", + "fielddata", + "docs", + "warmer", + "percolate", + "completion", + "segments", + "translog", + "query_cache", + "_all" + ] + } + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/percolator.js b/src/plugins/console/api_server/es_5_0/percolator.js new file mode 100644 index 0000000000000..7f100f34511a8 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/percolator.js @@ -0,0 +1,90 @@ +module.exports = function (api) { + api.addEndpointDescription('_put_percolator', { + priority: 10, // to override doc + methods: ['PUT', 'POST'], + patterns: [ + "{index}/.percolator/{id}" + ], + url_params: { + "version": 1, + "version_type": ["external", "internal"], + "op_type": ["create"], + "routing": "", + "parent": "", + "timestamp": "", + "ttl": "5m", + "consistency": ["qurom", "one", "all"], + "refresh": "__flag__", + "timeout": "1m" + }, + data_autocomplete_rules: { + query: {} + } + }); + api.addEndpointDescription('_percolate', { + methods: ['GET', 'POST'], + priority: 10, // to override doc + patterns: [ + "{indices}/{type}/_percolate" + ], + url_params: { + preference: ["_primary", "_primary_first", "_local", "_only_node:xyz", "_prefer_node:xyz", "_shards:2,3"], + routing: "", + ignore_unavailable: ["true", "false"], + percolate_format: ["ids"] + }, + data_autocomplete_rules: { + doc: {}, + query: {}, + filter: {}, + size: 10, + track_scores: {__one_of: [true, false]}, + sort: "_score", + aggs: {}, + highlight: {} + } + }); + api.addEndpointDescription('_percolate_id', { + methods: ['GET', 'POST'], + patterns: [ + "{indices}/{type}/{id}/_percolate" + ], + url_params: { + routing: "", + ignore_unavailable: ["true", "false"], + percolate_format: ["ids"], + percolate_index: "{index}", + percolate_type: "{type}", + percolate_routing: "", + percolate_preference: ["_primary", "_primary_first", "_local", "_only_node:xyz", "_prefer_node:xyz", "_shards:2,3"], + version: 1, + version_type: ["external", "internal"] + }, + data_autocomplete_rules: { + query: {}, + filter: {}, + size: 10, + track_scores: {__one_of: [true, false]}, + sort: "_score", + aggs: {}, + highlight: {} + } + }); + api.addEndpointDescription('_percolate_count', { + methods: ['GET', 'POST'], + patterns: [ + "{indices}/{type}/_percolate/count" + ], + url_params: { + preference: ["_primary", "_primary_first", "_local", "_only_node:xyz", "_prefer_node:xyz", "_shards:2,3"], + routing: "", + ignore_unavailable: ["true", "false"], + percolate_format: ["ids"] + }, + data_autocomplete_rules: { + doc: {}, + query: {}, + filter: {} + } + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/query.js b/src/plugins/console/api_server/es_5_0/query.js new file mode 100644 index 0000000000000..99e35f3a8110b --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/query.js @@ -0,0 +1,618 @@ +let _ = require("lodash"); + +var SPAN_QUERIES = { + // TODO add one_of for objects + span_first: { + __scope_link: '.span_first' + }, + span_near: { + __scope_link: '.span_near' + }, + span_or: { + __scope_link: '.span_or' + }, + span_not: { + __scope_link: '.span_not' + }, + span_term: { + __scope_link: '.span_term' + }, + span_containing: { + __scope_link: '.span_containing' + }, + span_within: { + __scope_link: '.span_within' + } +}; + +var DECAY_FUNC_DESC = { + __template: { + "FIELD": { + "origin": "", + "scale": "" + } + }, + "{field}": { + "origin": "", + "scale": "", + "offset": "", + "decay": 0.5 + } + }, + SCORING_FUNCS = { + "script_score": { + __template: { + "script": "_score * doc['f'].value" + }, + "script": { + //populated by a global rule + } + }, + "boost_factor": 2.0, + "random_score": { + "seed": 314159265359 + }, + "linear": DECAY_FUNC_DESC, + "exp": DECAY_FUNC_DESC, + "gauss": DECAY_FUNC_DESC, + "field_value_factor": { + __template: { + "field": "" + }, + "field": "{field}", + "factor": 1.2, + "modifier": { + __one_of: ["none", "log", "log1p", "log2p", "ln", "ln1p", "ln2p", "square", "sqrt", "reciprocal"] + } + } + }; + +module.exports = function (api) { + api.addGlobalAutocompleteRules('query', { + match: { + __template: { + 'FIELD': 'TEXT' + }, + '{field}': { + 'query': '', + 'operator': { + __one_of: ['and', 'or'] + }, + 'type': { + __one_of: ['phrase', 'phrase_prefix', 'boolean'] + }, + 'max_expansions': 10, + 'analyzer': '', + 'fuzziness': 1.0, + 'prefix_length': 1 + } + }, + match_phrase: { + __template: { + 'FIELD': 'PHRASE' + }, + '{field}': { + query: '', + analyzer: '' + } + }, + match_phrase_prefix: { + __template: { + 'FIELD': 'PREFIX' + }, + '{field}': { + query: '', + analyzer: '', + max_expansions: 10, + prefix_length: 1, + fuzziness: 0.1 + } + }, + multi_match: { + __template: { + 'query': '', + 'fields': [] + }, + query: '', + fields: ['{field}'], + use_dis_max: { + __template: true, + __one_of: [true, false] + }, + tie_breaker: 0.0, + type: {__one_of: ['best_fields', 'most_fields', 'cross_fields', 'phrase', 'phrase_prefix']} + }, + bool: { + must: [ + { + __scope_link: '.' + } + ], + must_not: [ + { + __scope_link: '.' + } + ], + should: [ + { + __scope_link: '.' + } + ], + filter: { + __scope_link: 'GLOBAL.filter' + }, + minimum_number_should_match: 1, + boost: 1.0 + }, + boosting: { + positive: { + __scope_link: '.' + }, + negative: { + __scope_link: '.' + }, + negative_boost: 0.2 + }, + ids: { + type: '', + values: [] + }, + constant_score: { + __template: { + filter: {}, + boost: 1.2 + }, + query: {}, + filter: {}, + boost: 1.2 + }, + dis_max: { + __template: { + tie_breaker: 0.7, + boost: 1.2, + queries: [] + }, + tie_breaker: 0.7, + boost: 1.2, + queries: [ + { + __scope_link: '.' + } + ] + }, + field: { + '{field}': { + query: '', + boost: 2.0, + enable_position_increments: { + __template: false, + __one_of: [true, false] + } + } + }, + fuzzy: { + '{field}': { + 'value': '', + 'boost': 1.0, + 'fuzziness': 0.5, + 'prefix_length': 0 + } + }, + has_child: { + __template: { + type: 'TYPE', + query: {} + }, + 'type': '{type}', + 'score_mode': { + __one_of: ['none', 'max', 'sum', 'avg'] + }, + '_scope': '', + 'query': {}, + 'min_children': 1, + 'max_children': 10 + }, + has_parent: { + __template: { + parent_type: 'TYPE', + query: {} + }, + 'parent_type': '{type}', + 'score_mode': { + __one_of: ['none', 'score'] + }, + '_scope': '', + 'query': {} + }, + match_all: {}, + more_like_this: { + __template: { + 'fields': ['FIELD'], + 'like_text': 'text like this one', + 'min_term_freq': 1, + 'max_query_terms': 12 + }, + fields: ['{field}'], + like_text: '', + percent_terms_to_match: 0.3, + min_term_freq: 2, + max_query_terms: 25, + stop_words: [''], + min_doc_freq: 5, + max_doc_freq: 100, + min_word_len: 0, + max_word_len: 0, + boost_terms: 1, + boost: 1.0, + analyzer: '', + docs: [{ + _index: "{index}", + _type: "{type}", + _id: "" + }], + ids: [""] + }, + mlt: { + __template: { + 'fields': ['FIELD'], + 'like_text': 'text like this one', + 'min_term_freq': 1, + 'max_query_terms': 12 + }, + __scope_link: ".more_like_this" + }, + prefix: { + __template: { + 'FIELD': { + 'value': '' + } + }, + '{field}': { + value: '', + boost: 1.0 + } + }, + query_string: { + __template: { + 'default_field': 'FIELD', + 'query': 'this AND that OR thus' + }, + query: '', + default_field: '{field}', + fields: ['{field}'], + default_operator: { + __one_of: ['OR', 'AND'] + }, + analyzer: '', + allow_leading_wildcard: { + __one_of: [true, false] + }, + lowercase_expanded_terms: { + __one_of: [true, false] + }, + enable_position_increments: { + __one_of: [true, false] + }, + fuzzy_max_expansions: 50, + fuzziness: 0.5, + fuzzy_prefix_length: 0, + phrase_slop: 0, + boost: 1.0, + analyze_wildcard: { + __one_of: [false, true] + }, + auto_generate_phrase_queries: { + __one_of: [false, true] + }, + minimum_should_match: '20%', + lenient: { + __one_of: [false, true] + }, + use_dis_max: { + __one_of: [true, false] + }, + tie_breaker: 0, + time_zone: "+1:00" + }, + simple_query_string: { + __template: { + query: "", + fields: [] + }, + query: "", + fields: ["{field}"], + default_operator: {__one_of: ["OR", "AND"]}, + analyzer: "", + flags: "OR|AND|PREFIX", + lowercase_expanded_terms: {__one_of: [true, false]}, + locale: "ROOT", + lenient: {__one_of: [true, false]} + }, + range: { + __template: { + 'FIELD': { + gte: 10, + lte: 20 + } + }, + '{field}': { + __template: { + gte: 10, + lte: 20 + }, + gte: 10, + gt: 10, + lte: 20, + lt: 20, + time_zone: "+1:00", + boost: 1.0, + "format": "dd/MM/yyyy||yyyy" + + } + }, + span_first: { + __template: { + 'match': { + 'span_term': { + 'FIELD': 'VALUE' + } + }, + 'end': 3 + }, + match: SPAN_QUERIES + }, + span_near: { + __template: { + 'clauses': [ + { + span_term: { + 'FIELD': { + 'value': 'VALUE' + } + } + } + ], + slop: 12, + in_order: false + }, + clauses: [ + SPAN_QUERIES + ], + slop: 12, + in_order: { + __one_of: [false, true] + }, + collect_payloads: { + __one_of: [false, true] + } + }, + span_term: { + __template: { + 'FIELD': { + 'value': 'VALUE' + } + }, + '{field}': { + value: '', + boost: 2.0 + } + }, + span_not: { + __template: { + include: { + span_term: { + 'FIELD': { + 'value': 'VALUE' + } + } + }, + exclude: { + span_term: { + 'FIELD': { + 'value': 'VALUE' + } + } + } + }, + include: SPAN_QUERIES, + exclude: SPAN_QUERIES + }, + span_or: { + __template: { + clauses: [ + { + span_term: { + 'FIELD': { + 'value': 'VALUE' + } + } + } + ] + }, + clauses: [ + SPAN_QUERIES + ] + }, + span_containing: { + __template: { + little: { + span_term: { + 'FIELD': { + 'value': 'VALUE' + } + } + }, + big: { + span_near: { + 'clauses': [ + { + span_term: { + 'FIELD': { + 'value': 'VALUE' + } + } + }, + { + span_term: { + 'FIELD': { + 'value': 'VALUE' + } + } + } + ], + "slop": 5, + "in_order": false + } + } + }, + little: SPAN_QUERIES, + big: SPAN_QUERIES + }, + span_within: { + __template: { + little: { + span_term: { + 'FIELD': { + 'value': 'VALUE' + } + } + }, + big: { + span_near: { + 'clauses': [ + { + span_term: { + 'FIELD': { + 'value': 'VALUE' + } + } + }, + { + span_term: { + 'FIELD': { + 'value': 'VALUE' + } + } + } + ], + "slop": 5, + "in_order": false + } + } + }, + little: SPAN_QUERIES, + big: SPAN_QUERIES + }, + term: { + __template: { + 'FIELD': { + value: 'VALUE' + } + }, + '{field}': { + value: '', + boost: 2.0 + } + }, + terms: { + __template: { + 'FIELD': ['VALUE1', 'VALUE2'] + }, + '{field}': [''] + }, + wildcard: { + __template: { + 'FIELD': { + value: 'VALUE' + } + }, + '{field}': { + value: '', + boost: 2.0 + } + }, + nested: { + __template: { + path: 'path_to_nested_doc', + query: {} + }, + path: '', + query: {}, + score_mode: { + __one_of: ['avg', 'total', 'max', 'none'] + } + }, + custom_filters_score: { + __template: { + query: {}, + filters: [ + { + filter: {} + } + ] + }, + query: {}, + filters: [ + { + filter: {}, + boost: 2.0, + script: { + //populated by a global rule + } + } + ], + score_mode: { + __one_of: ['first', 'min', 'max', 'total', 'avg', 'multiply'] + }, + max_boost: 2.0, + params: {}, + lang: '' + }, + indices: { + __template: { + indices: ['INDEX1', 'INDEX2'], + query: {} + }, + indices: ['{index}'], + query: {}, + no_match_query: { + __scope_link: '.' + } + }, + geo_shape: { + __template: { + location: {}, + relation: 'within' + }, + __scope_link: '.filter.geo_shape' + }, + // js hint gets confused here + /* jshint -W015 */ + function_score: _.defaults({ + __template: { + query: {}, + functions: [ + {} + ] + }, + query: {}, + functions: [ + _.defaults( + { + filter: {}, + weight: 1.0 + }, + SCORING_FUNCS + ) + ], + boost: 1.0, + boost_mode: {__one_of: ["multiply", "replace", "sum", "avg", "max", "min"]}, + score_mode: {__one_of: ["multiply", "sum", "first", "avg", "max", "min"]}, + max_boost: 10, + min_score: 1.0 + }, + SCORING_FUNCS + ) + + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/search.js b/src/plugins/console/api_server/es_5_0/search.js new file mode 100644 index 0000000000000..f6f0fc117a152 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/search.js @@ -0,0 +1,255 @@ +module.exports = function (api) { + api.addEndpointDescription('_search', { + methods: ['GET', 'POST'], + priority: 10, // collides with get doc by id + patterns: [ + "{indices}/{types}/_search", + "{indices}/_search", + "_search" + ], + url_params: { + q: "", + df: "", + analyzer: "", + default_operator: ["AND", "OR"], + explain: "__flag__", + _source: "", + _source_include: "", + _source_exclude: "", + fields: [], + sort: "", + track_scores: "__flag__", + timeout: 1, + from: 0, + size: 10, + search_type: ["dfs_query_then_fetch", "dfs_query_and_fetch", "query_then_fetch", "query_and_fetch"], + terminate_after: 10, + lowercase_expanded_terms: ["true", "false"], + analyze_wildcard: "__flag__", + preference: ["_primary", "_primary_first", "_local", "_only_node:xyz", "_prefer_node:xyz", "_shards:2,3"], + scroll: "5m", + scroll_id: "", + routing: "", + request_cache: ["true", "false"] + }, + data_autocomplete_rules: { + query: { + // populated by a global rule + }, + aggs: { + __template: { + "NAME": { + "AGG_TYPE": {} + } + } + }, + + post_filter: { + __scope_link: 'GLOBAL.filter' + }, + size: { + __template: 20 + }, + from: 0, + sort: { + __template: [ + { + 'FIELD': { + 'order': 'desc' + } + } + ], + __any_of: [ + { + '{field}': { + 'order': { + __one_of: ['desc', 'asc'] + }, + missing: { + __one_of: ['_last', '_first'] + }, + mode: { + __one_of: ['min', 'max', 'avg', 'sum'] + }, + nested_path: "", + nested_filter: { + __scope_link: "GLOBAL.filter" + } + } + }, + '{field}', + '_score', + { + '_geo_distance': { + __template: { + "FIELD": { + lat: 40, + lon: -70 + }, + order: "asc" + }, + "{field}": { + __one_of: [ + { + __template: { + lat: 40, + lon: -70 + }, + lat: 40, + lon: -70 + }, + [ + { + __template: { + lat: 40, + lon: -70 + }, + lat: 40, + lon: -70 + } + ], + [""], + "" + ] + }, + distance_type: {__one_of: ["sloppy_arc", "arc", "plane"]}, + sort_mode: {__one_of: ["min", "max", "avg"]}, + order: {__one_of: ["asc", "desc"]}, + unit: "km" + } + } + ] + }, + fields: ['{field}'], + fielddata_fields: ["{field}"], + script_fields: { + __template: { + 'FIELD': { + 'script': { + // populated by a global rule + } + } + }, + '*': { + __scope_link: 'GLOBAL.script' + } + }, + partial_fields: { + __template: { + 'NAME': { + include: [] + } + }, + '*': { + include: [], + exclude: [] + } + }, + highlight: { + // populated by a global rule + }, + _source: { + __one_of: [ + "{field}", + ["{field}"], + { + "include": { + __one_of: [ + "{field}", + ["{field}"] + ] + }, + "exclude": { + __one_of: [ + "{field}", + ["{field}"] + ] + } + } + ] + }, + explain: { + __one_of: [true, false] + }, + stats: [''], + timeout: "1s", + version: {__one_of: [true, false]} + } + }); + + api.addEndpointDescription('_search_template', { + methods: ['GET'], + patterns: [ + "{indices}/{types}/_search/template", + "{indices}/_search/template", + "_search/template" + ], + data_autocomplete_rules: { + "template": { + __one_of: [ + {__scope_link: "_search"}, + {__scope_link: "GLOBAL.script"} + ] + }, + "params": {} + } + }); + + api.addEndpointDescription('_render_search_template', { + methods: ['GET'], + patterns: [ + "_render/template" + ], + data_autocomplete_rules: { + __one_of: [ + {"inline": {__scope_link: "_search"}}, + {__scope_link: "GLOBAL.script"} + ], + "params": {} + } + }); + + api.addEndpointDescription('_render_search_template_with_id', { + methods: ['GET'], + patterns: [ + "_render/template/{id}" + ], + data_autocomplete_rules: { + "params": {} + } + }); + + api.addEndpointDescription('_get_delete_search_template', { + methods: ['GET', 'DELETE'], + patterns: [ + "_search/template/{id}" + ] + }); + + api.addEndpointDescription('_put_search_template', { + methods: ['PUT'], + patterns: [ + "_search/template/{id}" + ], + data_autocomplete_rules: { + "template": { + __scope_link: "_search" + } + } + }); + + api.addEndpointDescription('_search_shards', { + methods: ['GET'], + priority: 10, // collides with get doc by id + patterns: [ + "{indices}/{types}/_search_shards", + "{indices}/_search_shards", + "_search_shards" + ], + url_params: { + preference: ["_primary", "_primary_first", "_local", "_only_node:xyz", "_prefer_node:xyz", "_shards:2,3"], + routing: "", + local: "__flag__" + } + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/settings.js b/src/plugins/console/api_server/es_5_0/settings.js new file mode 100644 index 0000000000000..1cfdcad763083 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/settings.js @@ -0,0 +1,86 @@ +module.exports = function (api) { + + api.addEndpointDescription('_get_settings', { + patterns: [ + "{indices}/_settings", + "_settings" + ], + url_params: { + flat_settings: "__flag__" + } + }); + api.addEndpointDescription('_put_settings', { + methods: ['PUT'], + patterns: [ + "{indices}/_settings", + "_settings" + ], + data_autocomplete_rules: { + refresh_interval: '1s', + number_of_shards: 5, + number_of_replicas: 1, + 'blocks.read_only': { + __one_of: [false, true] + }, + 'blocks.read': { + __one_of: [true, false] + }, + 'blocks.write': { + __one_of: [true, false] + }, + 'blocks.metadata': { + __one_of: [true, false] + }, + term_index_interval: 32, + term_index_divisor: 1, + 'translog.flush_threshold_ops': 5000, + 'translog.flush_threshold_size': '200mb', + 'translog.flush_threshold_period': '30m', + 'translog.disable_flush': { + __one_of: [true, false] + }, + 'cache.filter.max_size': '2gb', + 'cache.filter.expire': '2h', + 'gateway.snapshot_interval': '10s', + routing: { + allocation: { + include: { + tag: '' + }, + exclude: { + tag: '' + }, + require: { + tag: '' + }, + total_shards_per_node: -1 + } + }, + 'recovery.initial_shards': { + __one_of: ['quorum', 'quorum-1', 'half', 'full', 'full-1'] + }, + 'ttl.disable_purge': { + __one_of: [true, false] + }, + analysis: { + analyzer: {}, + tokenizer: {}, + filter: {}, + char_filter: {} + }, + 'cache.query.enable': { + __one_of: [true, false] + }, + shadow_replicas: { + __one_of: [true, false] + }, + shared_filesystem: { + __one_of: [true, false] + }, + data_path: 'path', + codec: { + __one_of: ['default', 'best_compression', 'lucene_default'] + } + } + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/snapshot_restore.js b/src/plugins/console/api_server/es_5_0/snapshot_restore.js new file mode 100644 index 0000000000000..4e681ea23cbd6 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/snapshot_restore.js @@ -0,0 +1,153 @@ +module.exports = function (api) { + api.addEndpointDescription('restore_snapshot', { + methods: ['POST'], + patterns: [ + '_snapshot/{id}/{id}/_restore' + ], + url_params: { + wait_for_completion: "__flag__" + }, + data_autocomplete_rules: { + indices: "*", + ignore_unavailable: {__one_of: [true, false]}, + include_global_state: false, + rename_pattern: "index_(.+)", + rename_replacement: "restored_index_$1" + } + }); + + + api.addEndpointDescription('single_snapshot', { + methods: ['GET', 'DELETE'], + patterns: [ + '_snapshot/{id}/{id}' + ] + }); + + api.addEndpointDescription('all_snapshots', { + methods: ['GET'], + patterns: [ + '_snapshot/{id}/_all' + ] + }); + + api.addEndpointDescription('put_snapshot', { + methods: ['PUT'], + patterns: [ + '_snapshot/{id}/{id}' + ], + url_params: { + wait_for_completion: "__flag__" + }, + data_autocomplete_rules: { + indices: "*", + ignore_unavailable: {__one_of: [true, false]}, + include_global_state: {__one_of: [true, false]}, + partial: {__one_of: [true, false]} + } + }); + + api.addEndpointDescription('_snapshot_status', { + methods: ['GET'], + patterns: [ + '_snapshot/_status', + '_snapshot/{id}/_status', + '_snapshot/{id}/{ids}/_status' + ] + }); + + + function getRepositoryType(context, editor) { + var iter = editor.iterForCurrentLoc(); + // for now just iterate back to the first "type" key + var t = iter.getCurrentToken(); + var type; + while (t && t.type.indexOf("url") < 0) { + if (t.type === 'variable' && t.value === '"type"') { + t = editor.parser.nextNonEmptyToken(iter); + if (!t || t.type !== "punctuation.colon") { + // weird place to be in, but safe choice.. + break; + } + t = editor.parser.nextNonEmptyToken(iter); + if (t && t.type === "string") { + type = t.value.replace(/"/g, ''); + } + break; + } + t = editor.parser.prevNonEmptyToken(iter); + } + return type; + } + + api.addEndpointDescription('put_repository', { + methods: ['PUT'], + patterns: [ + '_snapshot/{id}' + ], + data_autocomplete_rules: { + __template: {"type": ""}, + + "type": { + __one_of: ["fs", "url", "s3", "hdfs"] + }, + "settings": { + __one_of: [{ + //fs + __condition: { + lines_regex: String.raw`type["']\s*:\s*["']fs` + }, + __template: { + location: "path" + }, + location: "path", + compress: {__one_of: [true, false]}, + concurrent_streams: 5, + chunk_size: "10m", + max_restore_bytes_per_sec: "20mb", + max_snapshot_bytes_per_sec: "20mb" + }, + {// url + __condition: { + lines_regex: String.raw`type["']\s*:\s*["']url` + }, + __template: { + url: "" + }, + url: "", + concurrent_streams: 5 + }, + { //s3 + __condition: { + lines_regex: String.raw`type["']\s*:\s*["']s3` + }, + __template: { + bucket: "" + }, + bucket: "", + region: "", + base_path: "", + concurrent_streams: 5, + chunk_size: "10m", + compress: {__one_of: [true, false]} + }, + {// hdfs + __condition: { + lines_regex: String.raw`type["']\s*:\s*["']hdfs` + }, + __template: { + path: "" + }, + uri: "", + path: "some/path", + load_defaults: {__one_of: [true, false]}, + conf_location: "cfg.xml", + concurrent_streams: 5, + compress: {__one_of: [true, false]}, + chunk_size: "10m" + } + ] + } + } + }); +}; diff --git a/src/plugins/console/api_server/es_5_0/templates.js b/src/plugins/console/api_server/es_5_0/templates.js new file mode 100644 index 0000000000000..635256c3f6985 --- /dev/null +++ b/src/plugins/console/api_server/es_5_0/templates.js @@ -0,0 +1,27 @@ +module.exports = function (api) { + api.addEndpointDescription('_delete_template', { + methods: ['DELETE'], + patterns: [ + "_template/{id}", + ] + }); + api.addEndpointDescription('_get_template', { + methods: ['GET'], + patterns: [ + "_template/{id}", + "_template", + ] + }); + api.addEndpointDescription('_put_template', { + methods: ['PUT'], + patterns: [ + "_template/{id}", + ], + data_autocomplete_rules: { + template: 'index*', + warmers: {__scope_link: '_warmer'}, + mappings: {__scope_link: '_put_mapping'}, + settings: {__scope_link: '_put_settings'} + } + }); +}; diff --git a/src/plugins/console/public/src/kb.js b/src/plugins/console/public/src/kb.js index 97d3dd7b7625c..ea6f1e0a45db0 100644 --- a/src/plugins/console/public/src/kb.js +++ b/src/plugins/console/public/src/kb.js @@ -239,21 +239,19 @@ function setActiveApi(api) { } es.addServerChangeListener(function () { - var version = es.getVersion(), api; - if (!version || version.length == 0) { - api = "es_1_0"; - } - else if (version[0] === "1") { - api = "es_1_0"; - } - else if (version[0] === "2") { - api = "es_2_0"; - } - else if (version[0] === "3") { - api = "es_2_0"; // TODO: change :) - } - else { - api = "es_1_0"; + var version = es.getVersion() || []; + var api; + + switch (version[0]) { + case '5': + api = 'es_5_0'; + break; + case '2': + api = 'es_2_0'; + break; + case '1': + default: + api = 'es_1_0'; } if (api) {