lots of changes, should have committed earlier

This commit is contained in:
Spencer Alger
2013-12-02 18:30:30 -07:00
parent 477f1aff84
commit 2b5f6cd80d
45 changed files with 2498 additions and 1935 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
dist
docs
npm-debug.log
node_modules
scripts/scratch*

View File

@ -60,9 +60,9 @@ bower install elasticsearch-jquery
```
## Docs
- [Configuration](docs/configuration.md)
- [Examples](docs/examples.md)
- [API](docs/api.md)
- [Replacing Core Components](docs/replacing_core_components.md)
- [Errors](docs/errors.md)
- [Customize Logging](docs/customize_logging.md)
- [Quick Start](http://spenceralger.github.io/elasticsearch-js/index.html#quick-start)
- [API](http://spenceralger.github.io/elasticsearch-js/api.html)
- [Configuration](http://spenceralger.github.io/elasticsearch-js/index.html#configuration)
- [Extending Core Components](http://spenceralger.github.io/elasticsearch-js/index.html#extending)
- [Logging](http://spenceralger.github.io/elasticsearch-js/index.html#logging)
- [Contributing](http://spenceralger.github.io/elasticsearch-js/index.html#contributing)

View File

@ -1,988 +0,0 @@
# API
## Table Of Contents
- [Generic Params](#generic-params)
- [Methods](#methods)
- [bulk](#bulk)
- [clearScroll](#clearscroll)
- [cluster.getSettings](#clustergetsettings)
- [cluster.health](#clusterhealth)
- [cluster.nodeHotThreads](#clusternodehotthreads)
- [cluster.nodeInfo](#clusternodeinfo)
- [cluster.nodeShutdown](#clusternodeshutdown)
- [cluster.nodeStats](#clusternodestats)
- [cluster.putSettings](#clusterputsettings)
- [cluster.reroute](#clusterreroute)
- [cluster.state](#clusterstate)
- [count](#count)
- [create](#create)
- [delete](#delete)
- [deleteByQuery](#deletebyquery)
- [exists](#exists)
- [explain](#explain)
- [get](#get)
- [getSource](#getsource)
- [index](#index)
- [indices.analyze](#indicesanalyze)
- [indices.clearCache](#indicesclearcache)
- [indices.close](#indicesclose)
- [indices.create](#indicescreate)
- [indices.delete](#indicesdelete)
- [indices.deleteAlias](#indicesdeletealias)
- [indices.deleteMapping](#indicesdeletemapping)
- [indices.deleteTemplate](#indicesdeletetemplate)
- [indices.deleteWarmer](#indicesdeletewarmer)
- [indices.exists](#indicesexists)
- [indices.existsAlias](#indicesexistsalias)
- [indices.existsType](#indicesexiststype)
- [indices.flush](#indicesflush)
- [indices.getAlias](#indicesgetalias)
- [indices.getAliases](#indicesgetaliases)
- [indices.getFieldMapping](#indicesgetfieldmapping)
- [indices.getMapping](#indicesgetmapping)
- [indices.getSettings](#indicesgetsettings)
- [indices.getTemplate](#indicesgettemplate)
- [indices.getWarmer](#indicesgetwarmer)
- [indices.open](#indicesopen)
- [indices.optimize](#indicesoptimize)
- [indices.putAlias](#indicesputalias)
- [indices.putMapping](#indicesputmapping)
- [indices.putSettings](#indicesputsettings)
- [indices.putTemplate](#indicesputtemplate)
- [indices.putWarmer](#indicesputwarmer)
- [indices.refresh](#indicesrefresh)
- [indices.segments](#indicessegments)
- [indices.snapshotIndex](#indicessnapshotindex)
- [indices.stats](#indicesstats)
- [indices.status](#indicesstatus)
- [indices.updateAliases](#indicesupdatealiases)
- [indices.validateQuery](#indicesvalidatequery)
- [info](#info)
- [mget](#mget)
- [mlt](#mlt)
- [msearch](#msearch)
- [percolate](#percolate)
- [scroll](#scroll)
- [search](#search)
- [suggest](#suggest)
- [update](#update)
## Generic Params
Several parameters can be passed to any API method, and will control the way that those requests are carried out. These parameters are not listed in each method's param list.
| Name | Type | Description |
| ---- | ---- | ----------- |
| `[timeout=10000]` | Number | The number of milliseconds this request has to complete. It defaults to the timeout specified at the client level, which defaults to 10 seconds. |
| `ignore` | Number or Number[] | Don't treat these HTTP status codes as "errors". Example use cases could be `ignore: 404` or `ignore: [404]` |
## Methods
### bulk()
http://elasticsearch.org/guide/reference/api/bulk/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`consistency` | String | Explicit write consistency setting for the operation|
|`refresh` | Boolean | Refresh the index after performing the operation|
|`[replication=sync]` | String | Explicitely set the replication type|
|`type` | String | Default document type for items which don't provide one|
|`timeout` | Date or Number | Explicit operation timeout|
|`index` | String | Default index for items which don't provide one|
### clearScroll()
http://www.elasticsearch.org/guide/reference/api/search/scroll/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`scrollId` | String or String[] or Boolean | A comma-separated list of scroll IDs to clear|
### cluster.getSettings()
http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/
-- none --
### cluster.health()
http://elasticsearch.org/guide/reference/api/admin-cluster-health/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`[level=cluster]` | String | Specify the level of detail for returned information|
|`local` | Boolean | Return local information, do not retrieve the state from master node (default: false)|
|`masterTimeout` | Date or Number | Explicit operation timeout for connection to master node|
|`timeout` | Date or Number | Explicit operation timeout|
|`waitForActiveShards` | Number | Wait until the specified number of shards is active|
|`waitForNodes` | String | Wait until the specified number of nodes is available|
|`waitForRelocatingShards` | Number | Wait until the specified number of relocating shards is finished|
|`waitForStatus` | String | Wait until cluster is in a specific state|
|`index` | String | Limit the information returned to a specific index|
### cluster.nodeHotThreads()
http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-hot-threads/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`interval` | Date or Number | The interval for the second sampling of threads|
|`snapshots` | Number | Number of samples of thread stacktrace (default: 10)|
|`threads` | Number | Specify the number of threads to provide information for (default: 3)|
|`type` | String | The type to sample (default: cpu)|
|`nodeId` | String or String[] or Boolean | A comma-separated 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|
### cluster.nodeInfo()
http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`all` | Boolean | Return all available information|
|`clear` | Boolean | Reset the default settings|
|`http` | Boolean | Return information about HTTP|
|`jvm` | Boolean | Return information about the JVM|
|`network` | Boolean | Return information about network|
|`os` | Boolean | Return information about the operating system|
|`plugin` | Boolean | Return information about plugins|
|`process` | Boolean | Return information about the Elasticsearch process|
|`settings` | Boolean | Return information about node settings|
|`threadPool` | Boolean | Return information about the thread pool|
|`timeout` | Date or Number | Explicit operation timeout|
|`transport` | Boolean | Return information about transport|
|`nodeId` | String or String[] or Boolean | A comma-separated 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|
### cluster.nodeShutdown()
http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`delay` | Date or Number | Set the delay for the operation (default: 1s)|
|`exit` | Boolean | Exit the JVM as well (default: true)|
|`nodeId` | String or String[] or Boolean | A comma-separated list of node IDs or names to perform the operation on; use `_local` to perform the operation on the node you're connected to, leave empty to perform the operation on all nodes|
### cluster.nodeStats()
http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`all` | Boolean | Return all available information|
|`clear` | Boolean | Reset the default level of detail|
|`fields` | String or String[] or Boolean | A comma-separated list of fields to return detailed information for, when returning the `indices` metric family (supports wildcards)|
|`fs` | Boolean | Return information about the filesystem|
|`http` | Boolean | Return information about HTTP|
|`indices` | Boolean | Return information about indices|
|`jvm` | Boolean | Return information about the JVM|
|`network` | Boolean | Return information about network|
|`os` | Boolean | Return information about the operating system|
|`process` | Boolean | Return information about the Elasticsearch process|
|`threadPool` | Boolean | Return information about the thread pool|
|`transport` | Boolean | Return information about transport|
|`metricFamily` | String | Limit the information returned to a certain metric family|
|`metric` | String | Limit the information returned for `indices` family to a specific metric|
|`nodeId` | String or String[] or Boolean | A comma-separated 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|
### cluster.putSettings()
http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/
-- none --
### cluster.reroute()
http://elasticsearch.org/guide/reference/api/admin-cluster-reroute/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`dryRun` | Boolean | Simulate the operation only and return the resulting state|
|`filterMetadata` | Boolean | Don't return cluster state metadata (default: false)|
### cluster.state()
http://elasticsearch.org/guide/reference/api/admin-cluster-state/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`filterBlocks` | Boolean | Do not return information about blocks|
|`filterIndexTemplates` | Boolean | Do not return information about index templates|
|`filterIndices` | String or String[] or Boolean | Limit returned metadata information to specific indices|
|`filterMetadata` | Boolean | Do not return information about indices metadata|
|`filterNodes` | Boolean | Do not return information about nodes|
|`filterRoutingTable` | Boolean | Do not return information about shard allocation (`routing_table` and `routing_nodes`)|
|`local` | Boolean | Return local information, do not retrieve the state from master node (default: false)|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
### count()
http://elasticsearch.org/guide/reference/api/count/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`minScore` | Number | Include only documents with a specific `_score` value in the result|
|`preference` | String | Specify the node or shard the operation should be performed on (default: random)|
|`routing` | String | Specific routing value|
|`source` | String | The URL-encoded query definition (instead of using the request body)|
|`index` | String or String[] or Boolean | A comma-separated list of indices to restrict the results|
|`type` | String or String[] or Boolean | A comma-separated list of types to restrict the results|
### create()
http://elasticsearch.org/guide/reference/api/index_/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`consistency` | String | Explicit write consistency setting for the operation|
|`id` | String | Document ID|
|`parent` | String | ID of the parent document|
|`percolate` | String | Percolator queries to execute while indexing the document|
|`refresh` | Boolean | Refresh the index after performing the operation|
|`[replication=sync]` | String | Specific replication type|
|`routing` | String | Specific routing value|
|`timeout` | Date or Number | Explicit operation timeout|
|`timestamp` | Date or Number | Explicit timestamp for the document|
|`ttl` | Duration | Expiration time for the document|
|`version` | Number | Explicit version number for concurrency control|
|`versionType` | String | Specific version type|
|`index` | String | The name of the index|
|`type` | String | The type of the document|
### delete()
http://elasticsearch.org/guide/reference/api/delete/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`consistency` | String | Specific write consistency setting for the operation|
|`parent` | String | ID of parent document|
|`refresh` | Boolean | Refresh the index after performing the operation|
|`[replication=sync]` | String | Specific replication type|
|`routing` | String | Specific routing value|
|`timeout` | Date or Number | Explicit operation timeout|
|`version` | Number | Explicit version number for concurrency control|
|`versionType` | String | Specific version type|
|`id` | String | The document ID|
|`index` | String | The name of the index|
|`type` | String | The type of the document|
### deleteByQuery()
http://www.elasticsearch.org/guide/reference/api/delete-by-query/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`analyzer` | String | The analyzer to use for the query string|
|`consistency` | String | Specific write consistency setting for the operation|
|`[defaultOperator=OR]` | String | The default operator for query string query (AND or OR)|
|`df` | String | The field to use as default where no field prefix is given in the query string|
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`[replication=sync]` | String | Specific replication type|
|`q` | String | Query in the Lucene query string syntax|
|`routing` | String | Specific routing value|
|`source` | String | The URL-encoded query definition (instead of using the request body)|
|`timeout` | Date or Number | Explicit operation timeout|
|`index` | String or String[] or Boolean | A comma-separated list of indices to restrict the operation; use `_all` to perform the operation on all indices|
|`type` | String or String[] or Boolean | A comma-separated list of types to restrict the operation|
### exists()
http://elasticsearch.org/guide/reference/api/get/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`parent` | String | The ID of the parent document|
|`preference` | String | Specify the node or shard the operation should be performed on (default: random)|
|`realtime` | Boolean | Specify whether to perform the operation in realtime or search mode|
|`refresh` | Boolean | Refresh the shard containing the document before performing the operation|
|`routing` | String | Specific routing value|
|`id` | String | The document ID|
|`index` | String | The name of the index|
|`[type=_all]` | String | The type of the document (use `_all` to fetch the first document matching the ID across all types)|
### explain()
http://elasticsearch.org/guide/reference/api/explain/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`analyzeWildcard` | Boolean | Specify whether wildcards and prefix queries in the query string query should be analyzed (default: false)|
|`analyzer` | String | The analyzer for the query string query|
|`[defaultOperator=OR]` | String | The default operator for query string query (AND or OR)|
|`df` | String | The default field for query string query (default: _all)|
|`fields` | String or String[] or Boolean | A comma-separated list of fields to return in the response|
|`lenient` | Boolean | Specify whether format-based query failures (such as providing text to a numeric field) should be ignored|
|`lowercaseExpandedTerms` | Boolean | Specify whether query terms should be lowercased|
|`parent` | String | The ID of the parent document|
|`preference` | String | Specify the node or shard the operation should be performed on (default: random)|
|`q` | String | Query in the Lucene query string syntax|
|`routing` | String | Specific routing value|
|`source` | String or String[] or Boolean | True or false to return the _source field or not, or a list of fields to return|
|`sourceExclude` | String or String[] or Boolean | A list of fields to exclude from the returned _source field|
|`sourceInclude` | String or String[] or Boolean | A list of fields to extract and return from the _source field|
|`id` | String | The document ID|
|`index` | String | The name of the index|
|`type` | String | The type of the document|
### get()
http://elasticsearch.org/guide/reference/api/get/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`fields` | String or String[] or Boolean | A comma-separated list of fields to return in the response|
|`parent` | String | The ID of the parent document|
|`preference` | String | Specify the node or shard the operation should be performed on (default: random)|
|`realtime` | Boolean | Specify whether to perform the operation in realtime or search mode|
|`refresh` | Boolean | Refresh the shard containing the document before performing the operation|
|`routing` | String | Specific routing value|
|`source` | String or String[] or Boolean | True or false to return the _source field or not, or a list of fields to return|
|`sourceExclude` | String or String[] or Boolean | A list of fields to exclude from the returned _source field|
|`sourceInclude` | String or String[] or Boolean | A list of fields to extract and return from the _source field|
|`id` | String | The document ID|
|`index` | String | The name of the index|
|`[type=_all]` | String | The type of the document (use `_all` to fetch the first document matching the ID across all types)|
### getSource()
http://elasticsearch.org/guide/reference/api/get/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`exclude` | String or String[] or Boolean | A list of fields to exclude from the returned _source field|
|`include` | String or String[] or Boolean | A list of fields to extract and return from the _source field|
|`parent` | String | The ID of the parent document|
|`preference` | String | Specify the node or shard the operation should be performed on (default: random)|
|`realtime` | Boolean | Specify whether to perform the operation in realtime or search mode|
|`refresh` | Boolean | Refresh the shard containing the document before performing the operation|
|`routing` | String | Specific routing value|
|`id` | String | The document ID|
|`index` | String | The name of the index|
|`[type=_all]` | String | The type of the document; use `_all` to fetch the first document matching the ID across all types|
### index()
http://elasticsearch.org/guide/reference/api/index_/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`consistency` | String | Explicit write consistency setting for the operation|
|`[opType=index]` | String | Explicit operation type|
|`parent` | String | ID of the parent document|
|`percolate` | String | Percolator queries to execute while indexing the document|
|`refresh` | Boolean | Refresh the index after performing the operation|
|`[replication=sync]` | String | Specific replication type|
|`routing` | String | Specific routing value|
|`timeout` | Date or Number | Explicit operation timeout|
|`timestamp` | Date or Number | Explicit timestamp for the document|
|`ttl` | Duration | Expiration time for the document|
|`version` | Number | Explicit version number for concurrency control|
|`versionType` | String | Specific version type|
|`id` | String | Document ID|
|`index` | String | The name of the index|
|`type` | String | The type of the document|
### indices.analyze()
http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`analyzer` | String | The name of the analyzer to use|
|`field` | String | Use the analyzer configured for this field (instead of passing the analyzer name)|
|`filters` | String or String[] or Boolean | A comma-separated list of filters to use for the analysis|
|`index` | String | The name of the index to scope the operation|
|`preferLocal` | Boolean | With `true`, specify that a local shard should be used if available, with `false`, use a random shard (default: true)|
|`text` | String | The text on which the analysis should be performed (when request body is not used)|
|`tokenizer` | String | The name of the tokenizer to use for the analysis|
|`[format=detailed]` | String | Format of the output|
### indices.clearCache()
http://www.elasticsearch.org/guide/reference/api/admin-indices-clearcache/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`fieldData` | Boolean | Clear field data|
|`fielddata` | Boolean | Clear field data|
|`fields` | String or String[] or Boolean | A comma-separated list of fields to clear when using the `field_data` parameter (default: all)|
|`filter` | Boolean | Clear filter caches|
|`filterCache` | Boolean | Clear filter caches|
|`filterKeys` | Boolean | A comma-separated list of keys to clear when using the `filter_cache` parameter (default: all)|
|`id` | Boolean | Clear ID caches for parent/child|
|`idCache` | Boolean | Clear ID caches for parent/child|
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`index` | String or String[] or Boolean | A comma-separated list of index name to limit the operation|
|`recycler` | Boolean | Clear the recycler cache|
### indices.close()
http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`timeout` | Date or Number | Explicit operation timeout|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String | The name of the index|
### indices.create()
http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`timeout` | Date or Number | Explicit operation timeout|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String | The name of the index|
### indices.delete()
http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-index/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`timeout` | Date or Number | Explicit operation timeout|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String or String[] or Boolean | A comma-separated list of indices to delete; use `_all` or empty string to delete all indices|
### indices.deleteAlias()
http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`timeout` | Date or Number | Explicit timestamp for the document|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String | The name of the index with an alias|
|`name` | String | The name of the alias to be deleted|
### indices.deleteMapping()
http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-mapping/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` for all indices|
|`type` | String | The name of the document type to delete|
### indices.deleteTemplate()
http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`timeout` | Date or Number | Explicit operation timeout|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`name` | String | The name of the template|
### indices.deleteWarmer()
http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String or String[] or Boolean | A comma-separated list of index names to register warmer for; use `_all` or empty string to perform the operation on all indices|
|`name` | String | The name of the warmer (supports wildcards); leave empty to delete all warmers|
|`type` | String or String[] or Boolean | A comma-separated list of document types to register warmer for; use `_all` or empty string to perform the operation on all types|
### indices.exists()
http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`index` | String or String[] or Boolean | A comma-separated list of indices to check|
### indices.existsAlias()
http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`index` | String or String[] or Boolean | A comma-separated list of index names to filter aliases|
|`name` | String or String[] or Boolean | A comma-separated list of alias names to return|
### indices.existsType()
http://www.elasticsearch.org/guide/reference/api/admin-indices-types-exists/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` to check the types across all indices|
|`type` | String or String[] or Boolean | A comma-separated list of document types to check|
### indices.flush()
http://www.elasticsearch.org/guide/reference/api/admin-indices-flush/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`force` | Boolean | TODO: ?|
|`full` | Boolean | TODO: ?|
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`refresh` | Boolean | Refresh the index after performing the operation|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` or empty string for all indices|
### indices.getAlias()
http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`index` | String or String[] or Boolean | A comma-separated list of index names to filter aliases|
|`name` | String or String[] or Boolean | A comma-separated list of alias names to return|
### indices.getAliases()
http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`timeout` | Date or Number | Explicit operation timeout|
|`index` | String or String[] or Boolean | A comma-separated list of index names to filter aliases|
### indices.getFieldMapping()
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html
| Name | Type | Description |
| ---- | ---- | ----------- |
|`includeDefaults` | Boolean | Whether the default mapping values should be returned as well|
|`index` | String or String[] or Boolean | A comma-separated list of index names|
|`type` | String or String[] or Boolean | A comma-separated list of document types|
|`field` | String or String[] or Boolean | A comma-separated list of fields|
### indices.getMapping()
http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`index` | String or String[] or Boolean | A comma-separated list of index names|
|`type` | String or String[] or Boolean | A comma-separated list of document types|
### indices.getSettings()
http://www.elasticsearch.org/guide/reference/api/admin-indices-get-settings/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices|
### indices.getTemplate()
http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`name` | String | The name of the template|
### indices.getWarmer()
http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`index` | String or String[] or Boolean | A comma-separated list of index names to restrict the operation; use `_all` to perform the operation on all indices|
|`name` | String | The name of the warmer (supports wildcards); leave empty to get all warmers|
|`type` | String or String[] or Boolean | A comma-separated list of document types to restrict the operation; leave empty to perform the operation on all types|
### indices.open()
http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`timeout` | Date or Number | Explicit operation timeout|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String | The name of the index|
### indices.optimize()
http://www.elasticsearch.org/guide/reference/api/admin-indices-optimize/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`flush` | Boolean | Specify whether the index should be flushed after performing the operation (default: true)|
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`maxNumSegments` | Number | The number of segments the index should be merged into (default: dynamic)|
|`onlyExpungeDeletes` | Boolean | Specify whether the operation should only expunge deleted documents|
|`operationThreading` | * | TODO: ?|
|`refresh` | Boolean | Specify whether the index should be refreshed after performing the operation (default: true)|
|`waitForMerge` | Boolean | Specify whether the request should block until the merge process is finished (default: true)|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices|
### indices.putAlias()
http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`timeout` | Date or Number | Explicit timestamp for the document|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String | The name of the index with an alias|
|`name` | String | The name of the alias to be created or updated|
### indices.putMapping()
http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`ignoreConflicts` | Boolean | Specify whether to ignore conflicts while updating the mapping (default: false)|
|`timeout` | Date or Number | Explicit operation timeout|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` to perform the operation on all indices|
|`type` | String | The name of the document type|
### indices.putSettings()
http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices|
### indices.putTemplate()
http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`order` | Number | The order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers)|
|`timeout` | Date or Number | Explicit operation timeout|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`name` | String | The name of the template|
### indices.putWarmer()
http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String or String[] or Boolean | A comma-separated list of index names to register the warmer for; use `_all` or empty string to perform the operation on all indices|
|`name` | String | The name of the warmer|
|`type` | String or String[] or Boolean | A comma-separated list of document types to register the warmer for; leave empty to perform the operation on all types|
### indices.refresh()
http://www.elasticsearch.org/guide/reference/api/admin-indices-refresh/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`operationThreading` | * | TODO: ?|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices|
### indices.segments()
http://elasticsearch.org/guide/reference/api/admin-indices-segments/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`operationThreading` | * | TODO: ?|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices|
### indices.snapshotIndex()
http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` or empty string for all indices|
### indices.stats()
http://elasticsearch.org/guide/reference/api/admin-indices-stats/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`all` | Boolean | Return all available information|
|`clear` | Boolean | Reset the default level of detail|
|`completion` | Boolean | Return information about completion suggester stats|
|`completionFields` | String or String[] or Boolean | A comma-separated list of fields for `completion` metric (supports wildcards)|
|`docs` | Boolean | Return information about indexed and deleted documents|
|`fielddata` | Boolean | Return information about field data|
|`fielddataFields` | String or String[] or Boolean | A comma-separated list of fields for `fielddata` metric (supports wildcards)|
|`fields` | String or String[] or Boolean | A comma-separated list of fields to return detailed information for, when returning the `search` statistics|
|`filterCache` | Boolean | Return information about filter cache|
|`flush` | Boolean | Return information about flush operations|
|`get` | Boolean | Return information about get operations|
|`groups` | Boolean | A comma-separated list of search groups for `search` statistics|
|`idCache` | Boolean | Return information about ID cache|
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`indexing` | Boolean | Return information about indexing operations|
|`merge` | Boolean | Return information about merge operations|
|`refresh` | Boolean | Return information about refresh operations|
|`search` | Boolean | Return information about search operations; use the `groups` parameter to include information for specific search groups|
|`store` | Boolean | Return information about the size of the index|
|`warmer` | Boolean | Return information about warmers|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices|
|`indexingTypes` | String or String[] or Boolean | A comma-separated list of document types to include in the `indexing` statistics|
|`metricFamily` | String | Limit the information returned to a specific metric|
|`searchGroups` | String or String[] or Boolean | A comma-separated list of search groups to include in the `search` statistics|
### indices.status()
http://elasticsearch.org/guide/reference/api/admin-indices-status/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`operationThreading` | * | TODO: ?|
|`recovery` | Boolean | Return information about shard recovery|
|`snapshot` | Boolean | TODO: ?|
|`index` | String or String[] or Boolean | A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices|
### indices.updateAliases()
http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`timeout` | Date or Number | Request timeout|
|`masterTimeout` | Date or Number | Specify timeout for connection to master|
|`index` | String or String[] or Boolean | A comma-separated list of index names to filter aliases|
### indices.validateQuery()
http://www.elasticsearch.org/guide/reference/api/validate/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`explain` | Boolean | Return detailed information about the error|
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`operationThreading` | * | TODO: ?|
|`source` | String | The URL-encoded query definition (instead of using the request body)|
|`q` | String | Query in the Lucene query string syntax|
|`index` | String or String[] or Boolean | A comma-separated list of index names to restrict the operation; use `_all` or empty string to perform the operation on all indices|
|`type` | String or String[] or Boolean | A comma-separated list of document types to restrict the operation; leave empty to perform the operation on all types|
### info()
http://elasticsearch.org/guide/
-- none --
### mget()
http://elasticsearch.org/guide/reference/api/multi-get/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`fields` | String or String[] or Boolean | A comma-separated list of fields to return in the response|
|`preference` | String | Specify the node or shard the operation should be performed on (default: random)|
|`realtime` | Boolean | Specify whether to perform the operation in realtime or search mode|
|`refresh` | Boolean | Refresh the shard containing the document before performing the operation|
|`source` | String or String[] or Boolean | True or false to return the _source field or not, or a list of fields to return|
|`sourceExclude` | String or String[] or Boolean | A list of fields to exclude from the returned _source field|
|`sourceInclude` | String or String[] or Boolean | A list of fields to extract and return from the _source field|
|`index` | String | The name of the index|
|`type` | String | The type of the document|
### mlt()
http://elasticsearch.org/guide/reference/api/more-like-this/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`boostTerms` | Number | The boost factor|
|`maxDocFreq` | Number | The word occurrence frequency as count: words with higher occurrence in the corpus will be ignored|
|`maxQueryTerms` | Number | The maximum query terms to be included in the generated query|
|`maxWordLen` | Number | The minimum length of the word: longer words will be ignored|
|`minDocFreq` | Number | The word occurrence frequency as count: words with lower occurrence in the corpus will be ignored|
|`minTermFreq` | Number | The term frequency as percent: terms with lower occurence in the source document will be ignored|
|`minWordLen` | Number | The minimum length of the word: shorter words will be ignored|
|`mltFields` | String or String[] or Boolean | Specific fields to perform the query against|
|`percentTermsToMatch` | Number | How many terms have to match in order to consider the document a match (default: 0.3)|
|`routing` | String | Specific routing value|
|`searchFrom` | Number | The offset from which to return results|
|`searchIndices` | String or String[] or Boolean | A comma-separated list of indices to perform the query against (default: the index containing the document)|
|`searchQueryHint` | String | The search query hint|
|`searchScroll` | String | A scroll search request definition|
|`searchSize` | Number | The number of documents to return (default: 10)|
|`searchSource` | String | A specific search request definition (instead of using the request body)|
|`searchType` | String | Specific search type (eg. `dfs_then_fetch`, `count`, etc)|
|`searchTypes` | String or String[] or Boolean | A comma-separated list of types to perform the query against (default: the same type as the document)|
|`stopWords` | String or String[] or Boolean | A list of stop words to be ignored|
|`id` | String | The document ID|
|`index` | String | The name of the index|
|`type` | String | The type of the document (use `_all` to fetch the first document matching the ID across all types)|
### msearch()
http://www.elasticsearch.org/guide/reference/api/multi-search/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`searchType` | String | Search operation type|
|`index` | String or String[] or Boolean | A comma-separated list of index names to use as default|
|`type` | String or String[] or Boolean | A comma-separated list of document types to use as default|
### percolate()
http://elasticsearch.org/guide/reference/api/percolate/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`preferLocal` | Boolean | With `true`, specify that a local shard should be used if available, with `false`, use a random shard (default: true)|
|`index` | String | The name of the index with a registered percolator query|
|`type` | String | The document type|
### scroll()
http://www.elasticsearch.org/guide/reference/api/search/scroll/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`scroll` | Duration | Specify how long a consistent view of the index should be maintained for scrolled search|
|`scrollId` | String | The scroll ID|
### search()
http://www.elasticsearch.org/guide/reference/api/search/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`analyzer` | String | The analyzer to use for the query string|
|`analyzeWildcard` | Boolean | Specify whether wildcard and prefix queries should be analyzed (default: false)|
|`[defaultOperator=OR]` | String | The default operator for query string query (AND or OR)|
|`df` | String | The field to use as default where no field prefix is given in the query string|
|`explain` | Boolean | Specify whether to return detailed information about score computation as part of a hit|
|`fields` | String or String[] or Boolean | A comma-separated list of fields to return as part of a hit|
|`from` | Number | Starting offset (default: 0)|
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`indicesBoost` | String or String[] or Boolean | Comma-separated list of index boosts|
|`lenient` | Boolean | Specify whether format-based query failures (such as providing text to a numeric field) should be ignored|
|`lowercaseExpandedTerms` | Boolean | Specify whether query terms should be lowercased|
|`preference` | String | Specify the node or shard the operation should be performed on (default: random)|
|`q` | String | Query in the Lucene query string syntax|
|`routing` | String or String[] or Boolean | A comma-separated list of specific routing values|
|`scroll` | Duration | Specify how long a consistent view of the index should be maintained for scrolled search|
|`searchType` | String | Search operation type|
|`size` | Number | Number of hits to return (default: 10)|
|`sort` | String or String[] or Boolean | A comma-separated list of <field>:<direction> pairs|
|`source` | String or String[] or Boolean | True or false to return the _source field or not, or a list of fields to return|
|`sourceExclude` | String or String[] or Boolean | A list of fields to exclude from the returned _source field|
|`sourceInclude` | String or String[] or Boolean | A list of fields to extract and return from the _source field|
|`stats` | String or String[] or Boolean | Specific 'tag' of the request for logging and statistical purposes|
|`suggestField` | String | Specify which field to use for suggestions|
|`[suggestMode=missing]` | String | Specify suggest mode|
|`suggestSize` | Number | How many suggestions to return in response|
|`suggestText` | Text | The source text for which the suggestions should be returned|
|`timeout` | Date or Number | Explicit operation timeout|
|`version` | Boolean | Specify whether to return document version as part of a hit|
|`[index=_all]` | String or String[] or Boolean | A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices|
|`type` | String or String[] or Boolean | A comma-separated list of document types to search; leave empty to perform the operation on all types|
### suggest()
http://elasticsearch.org/guide/reference/api/search/suggest/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`[ignoreIndices=none]` | String | When performed on multiple indices, allows to ignore `missing` ones|
|`preference` | String | Specify the node or shard the operation should be performed on (default: random)|
|`routing` | String | Specific routing value|
|`source` | String | The URL-encoded request definition (instead of using request body)|
|`index` | String or String[] or Boolean | A comma-separated list of index names to restrict the operation; use `_all` or empty string to perform the operation on all indices|
### update()
http://elasticsearch.org/guide/reference/api/update/
| Name | Type | Description |
| ---- | ---- | ----------- |
|`consistency` | String | Explicit write consistency setting for the operation|
|`fields` | String or String[] or Boolean | A comma-separated list of fields to return in the response|
|`lang` | String | The script language (default: mvel)|
|`parent` | String | ID of the parent document|
|`percolate` | String | Perform percolation during the operation; use specific registered query name, attribute, or wildcard|
|`refresh` | Boolean | Refresh the index after performing the operation|
|`[replication=sync]` | String | Specific replication type|
|`retryOnConflict` | Number | Specify how many times should the operation be retried when a conflict occurs (default: 0)|
|`routing` | String | Specific routing value|
|`script` | * | The URL-encoded script definition (instead of using request body)|
|`timeout` | Date or Number | Explicit operation timeout|
|`timestamp` | Date or Number | Explicit timestamp for the document|
|`ttl` | Duration | Expiration time for the document|
|`version` | Number | Explicit version number for concurrency control|
|`versionType` | String | Specific version type|
|`id` | String | Document ID|
|`index` | String | The name of the index|
|`type` | String | The type of the document|

View File

@ -1,117 +0,0 @@
The `Client` constructor accepts a single object as it's argument, and the following keys can be used to configure that client instance:
```js
var elasticsearch = require('elasticsearch');
var es = new elasticsearch.Client({
...
});
```
### hosts
Type: `String`, `String[]` or `Object[]`
Default:
```js
hosts: [
{
host: 'localhost', port: '9200', protocol: 'http'
}
]
```
Specify the list of hosts that this client will connect to. If sniffing is enabled, or you call sniff, this list will be used as seeds for discovery of the rest of the cluster.
### log
Type: `String`, `String[]`, `Object`, `Object[]`, or `Constructor`
Default:
```js
log: {
type: 'stdio',
levels: ['error', 'warning']
}
```
Unless a constructor is specified, this sets the output settings for the bundled logger. See [setting up logging](docs/setting_up_logging.md) for more information.
### connectionClass
Type: `String`, `Constructor`
Default:
- Node: `'http'`
- Browser: `'xhr'`
- Angular Build: `'angular'`
- jQuery Build: `'jquery'`
Defines the class that will be used to create connections. If you are looking to implement a protocol besides HTTP you will probably start by writing a Connection class and specifying it here.
### selector
Type: `String`, `Function`
Default: `'roundRobin'`
Options:
- `'roundRobin'`
- `'random'`
This function will be used to select a connection from the ConnectionPool. It should received a single argument, the list of "active" connections, and return the connection to use. Use this selector to implement special logic for your client such as preferring nodes in a certain rack or data-center.
To make this function asynchronous, accept a second argument which will be the callback to use. The callback should be called Node-style, with a possible error like `cb(err, selectedConnection)`.
### sniffOnStart
Type: `Boolean`
Default: `false`
Should the client attempt to detect the rest of the cluster when it is first instantiated?
### sniffAfterRequests
Type: `Number` or `false`
Default: `false`
After `n` requests, perform a sniff operation and ensure our list of nodes is up to date.
### sniffOnConnectionFail
Type: `Boolean`
Default: `false`
Should the client immediately sniff for a more current list of nodes when a connection dies? (see [node death](#node-death))
### maxRetries
Type: `Number`
Defailt: `3`
How many times should the client try to connect to other nodes before returning a [ConnectionFault](docs/error.md#connectionfault) error. (see [node death](#node-death))
### timeout
Type: `Number`
Default: 10000
How many milliseconds can the connection take before the request is aborted and retried. (TODO: timeout errors shouldn't cause a retry).
### deadTimeout
Type: `Number`
Default: 30000
How many milliseconds should a dead connection/node sit and wait before it is ping-ed? (see [node death](#node-death))
### maxSockets
Type: `Number`
Default: 10
How many sockets should a connection keep to it's corresponding Elasticsearch node? These sockets are currently kept alive ***forever*** (not like nodes current "keep alive" sockets).
### nodesToHostCallback
Type: `Function`
Default: simple, not much going on [here](src/lib/client_config.js#L65).
This function will receive a list of nodes received during a sniff. The list of nodes should be transformed into an array of objects which will each be used to create [Host](src/lib/host.js) objects. (TODO: allow this function to be async).

View File

@ -1,3 +0,0 @@
# Customize Logging
TODO: what are loggers, how to use bunyan/winston

View File

@ -1,39 +0,0 @@
# Errors
These are the standard Error types which may be passed back from the client. To access the constructors access the errors module via `require('elasticsearch').errors`.
## ConnectionFault
The connection was unable to initiate or complete a request with the Elasticsearch node.
## NoConnections
All of the connections in the ConnectionPool are dead.
## RequestTimeout
The request timed-out.
## Serialization
The response received from Elasticsearch could not be deserilaized.
## 503 or ServiceUnavailable
Elasticsearch responded with a 503 status.
## 500 or InternalServerError
Elasticsearch responded with a 500 status.
## 412 or PreconditionFailed
Elasticsearch responded with a 412 status.
## 409 or Conflict
Elasticsearch responded with a 409 status.
## 403 or Forbidden
Elasticsearch responded with a 403 status.
## 404 or NotFound
Elasticsearch responded with a 404 status.
## 400 or BadRequest
Elasticsearch responded with a 400 status.
## Generic
Elasticsearch responded with a status that does not map to it's own error type.

View File

@ -1,52 +0,0 @@
### Examples
#### create the client
```js
var es = new elasticsearch.Client({
hosts: [
'localhost:9200'
],
log: 'trace',
sniffOnStart: true
});
```
#### call an endpoint
```js
es.cluster.nodeInfo({
clear: true,
jvm: true,
os: ture
}, function (err, resp, status) {
// do your thing
})
```
#### skip the callback to get a promise back
```js
es.search({
q: 'pants'
}).then(function (resp) {
// use resp.body and resp.status
}, function (err) {
// freak out!
})
```
#### abort a request
```js
var req = es.search({
q: 'robots'
}, function (err, body, status) {
clearTimeout(timeout);
// do something
});
var timeout = setTimeout(function () {
req.abort();
}, 200);
```
#### or just use the timeout param
```js
es.search({
q: '*',
timeout: 200
}).then(function (resp) {
// Iterate all the hits
})
```

View File

@ -1,11 +0,0 @@
# Replacing Core Components
TODO: detail the components that are replaceable
## API
## Connection
## ConnectionPool
## Log

1218
log Normal file

File diff suppressed because it is too large Load Diff

View File

@ -44,21 +44,19 @@
"when": "~2.6.0",
"lodash": "~2.3.0",
"agentkeepalive": "~0.1",
"chalk": "~0.3.0",
"inherits": "~2.0.1"
"chalk": "~0.3.0"
},
"scripts": {
"test": "node scripts/run_tests.js",
"coverage": "mocha test/unit/test_*.js --require blanket -R html-cov > coverage.html && open -a \"Google Chrome\" ./coverage.html",
"build": "grunt",
"generate": "node scripts/generate/js_api && node scripts/generate/yaml_tests",
"export_client": "node scripts/export_client.js",
"blanket": {
"pattern": "src"
}
},
"testling": {
"harness": "mocha",
"files": "test/unit/test_!(http_connection|stdio_logger).js"
"files": "test/unit/test_!(http_connector|stdio_logger).js"
}
}

View File

@ -14,7 +14,7 @@ var argv = require('optimist')
o: 'outputDir',
v: 'verbose'
})
.parse(JSON.parse(process.env.npm_config_argv).original);
.argv;
switch (argv.buildName) {
case 'jquery':

96
scripts/export_docs.js Normal file
View File

@ -0,0 +1,96 @@
var path = require('path');
var fs = require('fs');
var format = require('util').format;
var cp = require('child_process');
var argv = require('optimist')
.default({
outputDir: '.',
verbose: false
})
.alias({
o: 'outputDir',
v: 'verbose'
})
.argv;
var steps = [
[runInModule, 'node', [path.join(__dirname, './generate/js_api'), '--force']],
[
copy,
path.join(__dirname, '../docs/_methods.jade'),
path.join(argv.outputDir, '_methods.jade')
],
[
copy,
path.join(__dirname, '../docs/_method_list.jade'),
path.join(argv.outputDir, '_method_list.jade')
]
];
(function next() {
var step = steps.shift();
if (step) {
var fn = step.shift();
step.push(next);
fn.apply(null, step);
} else {
console.log('Done');
process.exit();
}
})();
function log() {
var out = format.apply(console, arguments);
if (argv.verbose) {
out = '\n' + out + '\n';
}
console.log(out);
}
function runInModule(cmd, args, exitCb) {
log('running', cmd, args.join(' '));
var proc = cp.spawn(cmd, args, {
stdio: argv.verbose ? 'inherit' : 'ignore'
});
proc.on('error', function (err) {
console.error('Error! --', err.message);
process.exit(1);
});
proc.on('exit', function (status) {
if (status) {
console.error('Error! --', cmd, 'exit status was', status);
process.exit(1);
} else {
exitCb();
}
});
}
function copy(from, to, done) {
log('copying', from, 'to', to);
var read = fs.createReadStream(from);
var write = fs.createWriteStream(to);
read.pipe(write);
read.on('error', function (err) {
console.error('unable to read: ' + from);
console.error(err.message);
process.exit(1);
});
write.on('error', function (err) {
console.error('unable to write to: ' + to);
console.error(err.message);
process.exit(1);
});
write.on('finish', function () {
done();
});
}

View File

@ -198,24 +198,43 @@ function transformFile(entry) {
/**
* un-comment to print out the default method for any action that has multiple options
*/
// module.exports = new EventEmitter();
module.exports = new EventEmitter();
// module.exports.on('ready', function (actions) {
// var longestName = 0;
// var lines = [];
// var reports = {
// multi_methods: [],
// get_with_body: []
// };
// actions.forEach(function (action) {
// var name;
// // console.log(action);
// if (action._methods.length > 1) {
// var name = action.name + ' (' + action._methods.join('/') + ')';
// name = action.name + ' (' + action._methods.join('/') + ')';
// longestName = Math.max(name.length, longestName);
// lines.push([name, action.spec.method || 'GET', action.docUrl]);
// reports.multi_methods.push([name, action.spec.method || 'GET', action.docUrl]);
// }
// if (action._methods.length === 1 && action._methods[0] === 'GET' && action.body) {
// name = action.name + ' (' + action._methods.join('/') + ')';
// longestName = Math.max(name.length, longestName);
// reports.get_with_body.push([name, action.spec.method || 'GET', action.docUrl]);
// }
// });
// lines.forEach(function (line) {
// var name = line[0];
// var def = line[1];
// var docUrl = line[2];
// var spacing = (new Array(longestName - name.length + 1)).join(' ');
// console.log(name + spacing + ' [' + def + (def.length === 3 ? ' ' : '') + '] -> ' + docUrl);
// Object.keys(reports).forEach(function (key) {
// console.log('\n' + key);
// if (reports[key].length) {
// reports[key].forEach(function (line) {
// var name = line[0];
// var def = line[1];
// var docUrl = line[2];
// var spacing = (new Array(longestName - name.length + 1)).join(' ');
// console.log(name + spacing + ' [' + def + (def.length === 3 ? ' ' : '') + '] -> ' + docUrl);
// });
// } else {
// console.log('--nada--');
// }
// console.log('\n');
// });
// });

View File

@ -5,7 +5,7 @@ var clean = require('../../clean');
var restSpecUpdated = require('../../rest_spec_updated');
var outputPath = _.joinPath(__dirname, '../../../src/lib/api.js');
var docOutputPath = _.joinPath(__dirname, '../../../docs/api.md');
var docOutputDir = _.joinPath(__dirname, '../../../docs/');
function download() {
require('./actions').on('ready', function (actions) {
@ -32,14 +32,22 @@ function download() {
namespaces: _.unique(namespaces.sort(), true)
}));
fs.writeFileSync(docOutputPath, templates.apiDocs({
if (!fs.existsSync(docOutputDir)) {
fs.mkdirSync(docOutputDir);
}
fs.writeFileSync(docOutputDir + '_method_list.jade', templates.apiMethodList({
actions: actions
}));
fs.writeFileSync(docOutputDir + '_methods.jade', templates.apiMethods({
actions: actions
}));
});
}
restSpecUpdated(function (err, updated) {
if (process.env.FORCE_GEN || process.env.npm_config_force || err || updated) {
if (err || updated) {
download();
}
});

View File

@ -1,62 +0,0 @@
# API
## Table Of Contents
- [Generic Params](#generic-params)
- [Methods](#methods)<%
function esc(str) {
return str.replace(/\|/g, '&#124;');
}
var _paramWithDefault = paramWithDefault;
paramWithDefault = function (name, _default) {
return esc(_paramWithDefault(name, _default));
};
var _paramType = paramType;
paramType = function (type) {
return esc(_paramType(type));
};
_.each(actions, function (action) {%>
- [<%= action.name %>](#<%= action.name.toLowerCase().replace(/[^\w ]/g, '').replace(/ /g, '-') %>)<%
})
%>
## Generic Params
Several parameters can be passed to any API method, and will control the way that those requests are carried out. These parameters are not listed in each method's param list.
| Name | Type | Description |
| ---- | ---- | ----------- |
| `[timeout=10000]` | Number | The number of milliseconds this request has to complete. It defaults to the timeout specified at the client level, which defaults to 10 seconds. |
| `ignore` | Number or Number[] | Don't treat these HTTP status codes as "errors". Example use cases could be `ignore: 404` or `ignore: [404]` |
## Methods<%
_.each(actions, function (action) {
%>
### <%= action.name %>()
<%= action.docUrl %><%
if (_.size(action.allParams)) { %>
| Name | Type | Description |
| ---- | ---- | ----------- |
<%
_.each(action.allParams, function(param, paramName) {
%>|`<%= paramWithDefault(paramName, param.default) %>` | <%= paramType(param.type) %> | <%= esc(param.description || '') %>|
<% })
} else {%>
-- none --
<%
}
}); %>

View File

@ -0,0 +1,32 @@
<%
function esc(str) {
return str.replace(/\|/g, '&#124;');
}
var topActions = [];
var names = {};
_.each(actions, function (action) {
if (action.name.indexOf('.') > -1) {
var space = _.studlyCase(action.name.split('.').slice(0, -1).join('.'));
if (!names[space]) {
names[space] = [];
}
names[space].push(action);
} else {
topActions.push(action);
}
}); %>
ul<%
_.each(topActions, function (action) {%>
li: a(href="api.html#<%= action.name.toLowerCase().replace(/[^\w]+/g, '-') %>") <%= action.name %><%
});
_.each(Object.keys(names).sort(), function (namespace) {%>
h3 <%= namespace %>
ul<%
_.each(names[namespace], function (action) {%>
li: a(href="api.html#<%= action.name.toLowerCase().replace(/[^\w]+/g, '-') %>") <%= action.name.replace(/^.*\./, '') %><%
})
})
%>

View File

@ -0,0 +1,40 @@
<%
_.each(actions, function (action) {
var actionId = action.name.toLowerCase().replace(/[^\w]+/g, '-');
%>
h3#<%= actionId %>.fn
span.name <%= action.name %>
span.args (params, [callback])
a.perma(href="api.html#<%= actionId %>", title="Permalink")
a.esdoc(href="<%= action.docUrl %>", title="Endpoint Docs")
//
h4 Spec:
pre
code <%= JSON.stringify(action, null, ' ').split('\n').map(function (line, i) {
return (i > 0 ? ' | ' : '') + line;
}).join('\n') %>
h4 Params:
ul.params.api
<% _.each(action.allParams, function (param, paramName) { %>
li
code.name <%= paramWithDefault(paramName, param.default) %>
<%=
_.map(
('<span class="types">' + paramType(param.type) + '</span> ' + (param.description || '')).split('\n'),
function (line) {
return '| ' + line + '\n';
}
).join('\n')
%>
<% }); %>
li <a href="#api-conventions-params">the usual</a>
h4 Method: <code><%= action.spec.method || 'GET' %></code>
h4 Returns:
p: a(href="#api-conventions-return") the usual<%
});
%>

View File

@ -52,13 +52,13 @@ var templateGlobals = {
paramType: function (type) {
switch (type && type.toLowerCase ? type.toLowerCase() : 'any') {
case 'time':
return 'Date or Number';
return 'Date, Number';
case 'any':
return '*';
return 'Anything';
case 'enum':
return 'String';
case 'list':
return 'String or String[] or Boolean';
return 'String, String[], Boolean';
default:
return _.ucfirst(type);
}
@ -91,5 +91,6 @@ templates.text = templates.string;
module.exports = {
apiFile: templates.api_file,
apiDocs: templates.api_docs
apiMethodList: templates.api_method_list,
apiMethods: templates.api_methods
};

View File

@ -8,7 +8,7 @@ var argv = require('optimist')
default: 14000
},
days: {
alias: 'c',
alias: 'd',
type: 'number',
required: true
},
@ -22,22 +22,21 @@ var argv = require('optimist')
// Error.stackTraceLimit = Infinity;
// process.exit();
var count = parseInt(argv._[0] || 14000, 10),
days = parseInt(argv._[1] || 7, 10);
var es = require('../../../src/elasticsearch'),
_ = require('../../../src/lib/utils'),
async = require('async'),
moment = require('moment'),
makeSamples = require('./samples').make,
startingMoment = moment().startOf('day').subtract('days', days),
endingMoment = moment().endOf('day').add('days', days),
clientConfig = {
log: {
level: 'trace',
type: 'stdio'
}
};
var es = require('../../../src/elasticsearch');
var _ = require('../../../src/lib/utils');
var async = require('async');
var path = require('path');
var moment = require('moment');
var makeSamples = require('./samples').make;
var startingMoment = moment().startOf('day').subtract('days', argv.days);
var endingMoment = moment().endOf('day').add('days', argv.days);
var clientConfig = {
log: {
level: 'trace',
type: 'file',
path: path.join(__dirname, '../../../log')
}
};
if (argv.host) {
clientConfig.hosts = argv.host;
@ -47,13 +46,13 @@ if (argv.host) {
var client = new es.Client(clientConfig);
console.log('Generating', count, 'events across ±', days, 'days');
console.log('Generating', argv.count, 'events across ±', argv.days, 'days');
fillIndecies(function () {
var actions = [],
samples = makeSamples(startingMoment, endingMoment);
var actions = [];
var samples = makeSamples(startingMoment, endingMoment);
async.times(count, function (i, done) {
async.times(argv.count, function (i, done) {
// random date, plus less random time
var date = moment(samples.randomMsInDayRange())
.utc()
@ -84,7 +83,6 @@ fillIndecies(function () {
event['@message'] = event.ip + ' - - [' + date.toISOString() + '] "GET ' + event.request + ' HTTP/1.1" ' +
event.response + ' ' + event.bytes + ' "-" "' + event.agent + '"';
event.src = JSON.stringify(event, null, ' ');
actions.push({
index: {
@ -95,7 +93,7 @@ fillIndecies(function () {
});
actions.push(event);
if (actions.length === 3000 || i === count - 1) {
if (actions.length === 3000 || i === argv.count - 1) {
console.info('writing', actions.length / 2, 'documents');
client.bulk({
body: actions
@ -109,6 +107,7 @@ fillIndecies(function () {
throw err;
} else {
console.log('Done!');
process.exit();
}
});
});

View File

@ -1,250 +0,0 @@
module.exports = {
'CN': 1330044000,
'IN': 1173108018,
'US': 610232863,
'ID': 242968342,
'BR': 201103330,
'PK': 184404791,
'BD': 156118464,
'NG': 154000000,
'RU': 140702000,
'JP': 127288000,
'MX': 112468855,
'PH': 99900177,
'VN': 89571130,
'ET': 88013491,
'DE': 81802257,
'EG': 80471869,
'TR': 77804122,
'IR': 76923300,
'CD': 70916439,
'TH': 67089500,
'FR': 64768389,
'GB': 62348447,
'IT': 60340328,
'MM': 53414374,
'ZA': 49000000,
'KR': 48422644,
'ES': 46505963,
'UA': 45415596,
'CO': 44205293,
'TZ': 41892895,
'AR': 41343201,
'KE': 40046566,
'PL': 38500000,
'SD': 35000000,
'DZ': 34586184,
'CA': 33679000,
'UG': 33398682,
'MA': 31627428,
'PE': 29907003,
'IQ': 29671605,
'AF': 29121286,
'NP': 28951852,
'MY': 28274729,
'UZ': 27865738,
'VE': 27223228,
'SA': 25731776,
'GH': 24339838,
'YE': 23495361,
'KP': 22912177,
'TW': 22894384,
'SY': 22198110,
'MZ': 22061451,
'RO': 21959278,
'AU': 21515754,
'LK': 21513990,
'MG': 21281844,
'CI': 21058798,
'CM': 19294149,
'CL': 16746491,
'NL': 16645000,
'BF': 16241811,
'NE': 15878271,
'MW': 15447500,
'KZ': 15340000,
'EC': 14790608,
'KH': 14453680,
'ML': 13796354,
'GT': 13550440,
'ZM': 13460305,
'AO': 13068161,
'SN': 12323252,
'ZW': 11651858,
'CU': 11423000,
'RW': 11055976,
'GR': 11000000,
'CS': 10829175,
'PT': 10676000,
'TN': 10589025,
'TD': 10543464,
'CZ': 10476000,
'BE': 10403000,
'GN': 10324025,
'SO': 10112453,
'BO': 9947418,
'HU': 9930000,
'BI': 9863117,
'DO': 9823821,
'BY': 9685000,
'HT': 9648924,
'BJ': 9056010,
'SE': 9045000,
'AZ': 8303512,
'SS': 8260490,
'AT': 8205000,
'HN': 7989415,
'CH': 7581000,
'TJ': 7487489,
'IL': 7353985,
'RS': 7344847,
'BG': 7148785,
'HK': 6898686,
'TG': 6587239,
'LY': 6461454,
'JO': 6407085,
'PY': 6375830,
'LA': 6368162,
'PG': 6064515,
'SV': 6052064,
'NI': 5995928,
'ER': 5792984,
'KG': 5508626,
'DK': 5484000,
'SK': 5455000,
'SL': 5245695,
'FI': 5244000,
'NO': 5009150,
'AE': 4975593,
'TM': 4940916,
'CF': 4844927,
'SG': 4701069,
'GE': 4630000,
'IE': 4622917,
'BA': 4590000,
'CR': 4516220,
'HR': 4491000,
'MD': 4324000,
'NZ': 4252277,
'LB': 4125247,
'PR': 3916632,
'PS': 3800000,
'LR': 3685076,
'LT': 3565000,
'UY': 3477000,
'PA': 3410676,
'MR': 3205060,
'MN': 3086918,
'CG': 3039126,
'AL': 2986952,
'AM': 2968000,
'OM': 2967717,
'JM': 2847232,
'KW': 2789132,
'LV': 2217969,
'NA': 2128471,
'MK': 2061000,
'BW': 2029307,
'SI': 2007000,
'LS': 1919552,
'XK': 1800000,
'GM': 1593256,
'GW': 1565126,
'GA': 1545255,
'SZ': 1354051,
'MU': 1294104,
'EE': 1291170,
'TT': 1228691,
'TL': 1154625,
'CY': 1102677,
'GQ': 1014999,
'FJ': 875983,
'QA': 840926,
'RE': 776948,
'KM': 773407,
'GY': 748486,
'DJ': 740528,
'BH': 738004,
'BT': 699847,
'ME': 666730,
'SB': 559198,
'CV': 508659,
'LU': 497538,
'SR': 492829,
'MO': 449198,
'GP': 443000,
'MQ': 432900,
'MT': 403000,
'MV': 395650,
'BN': 395027,
'BZ': 314522,
'IS': 308910,
'BS': 301790,
'BB': 285653,
'EH': 273008,
'PF': 270485,
'VU': 221552,
'NC': 216494,
'GF': 195506,
'WS': 192001,
'ST': 175808,
'LC': 160922,
'GU': 159358,
'YT': 159042,
'CW': 141766,
'AN': 136197,
'TO': 122580,
'VI': 108708,
'GD': 107818,
'FM': 107708,
'VC': 104217,
'KI': 92533,
'JE': 90812,
'SC': 88340,
'AG': 86754,
'AD': 84000,
'IM': 75049,
'DM': 72813,
'AW': 71566,
'MH': 65859,
'BM': 65365,
'GG': 65228,
'AS': 57881,
'GL': 56375,
'MP': 53883,
'KN': 49898,
'FO': 48228,
'KY': 44270,
'SX': 37429,
'MF': 35925,
'LI': 35000,
'MC': 32965,
'SM': 31477,
'GI': 27884,
'AX': 26711,
'VG': 21730,
'CK': 21388,
'TC': 20556,
'PW': 19907,
'BQ': 18012,
'WF': 16025,
'AI': 13254,
'TV': 10472,
'NR': 10065,
'MS': 9341,
'BL': 8450,
'SH': 7460,
'PM': 7012,
'IO': 4000,
'FK': 2638,
'SJ': 2550,
'NU': 2166,
'NF': 1828,
'CX': 1500,
'TK': 1466,
'VA': 921,
'CC': 628,
'TF': 140,
'PN': 46,
'GS': 30
};

View File

@ -0,0 +1,250 @@
{
"CN": 1330044000,
"IN": 1173108018,
"US": 610232863,
"ID": 242968342,
"BR": 201103330,
"PK": 184404791,
"BD": 156118464,
"NG": 154000000,
"RU": 140702000,
"JP": 127288000,
"MX": 112468855,
"PH": 99900177,
"VN": 89571130,
"ET": 88013491,
"DE": 81802257,
"EG": 80471869,
"TR": 77804122,
"IR": 76923300,
"CD": 70916439,
"TH": 67089500,
"FR": 64768389,
"GB": 62348447,
"IT": 60340328,
"MM": 53414374,
"ZA": 49000000,
"KR": 48422644,
"ES": 46505963,
"UA": 45415596,
"CO": 44205293,
"TZ": 41892895,
"AR": 41343201,
"KE": 40046566,
"PL": 38500000,
"SD": 35000000,
"DZ": 34586184,
"CA": 33679000,
"UG": 33398682,
"MA": 31627428,
"PE": 29907003,
"IQ": 29671605,
"AF": 29121286,
"NP": 28951852,
"MY": 28274729,
"UZ": 27865738,
"VE": 27223228,
"SA": 25731776,
"GH": 24339838,
"YE": 23495361,
"KP": 22912177,
"TW": 22894384,
"SY": 22198110,
"MZ": 22061451,
"RO": 21959278,
"AU": 21515754,
"LK": 21513990,
"MG": 21281844,
"CI": 21058798,
"CM": 19294149,
"CL": 16746491,
"NL": 16645000,
"BF": 16241811,
"NE": 15878271,
"MW": 15447500,
"KZ": 15340000,
"EC": 14790608,
"KH": 14453680,
"ML": 13796354,
"GT": 13550440,
"ZM": 13460305,
"AO": 13068161,
"SN": 12323252,
"ZW": 11651858,
"CU": 11423000,
"RW": 11055976,
"GR": 11000000,
"CS": 10829175,
"PT": 10676000,
"TN": 10589025,
"TD": 10543464,
"CZ": 10476000,
"BE": 10403000,
"GN": 10324025,
"SO": 10112453,
"BO": 9947418,
"HU": 9930000,
"BI": 9863117,
"DO": 9823821,
"BY": 9685000,
"HT": 9648924,
"BJ": 9056010,
"SE": 9045000,
"AZ": 8303512,
"SS": 8260490,
"AT": 8205000,
"HN": 7989415,
"CH": 7581000,
"TJ": 7487489,
"IL": 7353985,
"RS": 7344847,
"BG": 7148785,
"HK": 6898686,
"TG": 6587239,
"LY": 6461454,
"JO": 6407085,
"PY": 6375830,
"LA": 6368162,
"PG": 6064515,
"SV": 6052064,
"NI": 5995928,
"ER": 5792984,
"KG": 5508626,
"DK": 5484000,
"SK": 5455000,
"SL": 5245695,
"FI": 5244000,
"NO": 5009150,
"AE": 4975593,
"TM": 4940916,
"CF": 4844927,
"SG": 4701069,
"GE": 4630000,
"IE": 4622917,
"BA": 4590000,
"CR": 4516220,
"HR": 4491000,
"MD": 4324000,
"NZ": 4252277,
"LB": 4125247,
"PR": 3916632,
"PS": 3800000,
"LR": 3685076,
"LT": 3565000,
"UY": 3477000,
"PA": 3410676,
"MR": 3205060,
"MN": 3086918,
"CG": 3039126,
"AL": 2986952,
"AM": 2968000,
"OM": 2967717,
"JM": 2847232,
"KW": 2789132,
"LV": 2217969,
"NA": 2128471,
"MK": 2061000,
"BW": 2029307,
"SI": 2007000,
"LS": 1919552,
"XK": 1800000,
"GM": 1593256,
"GW": 1565126,
"GA": 1545255,
"SZ": 1354051,
"MU": 1294104,
"EE": 1291170,
"TT": 1228691,
"TL": 1154625,
"CY": 1102677,
"GQ": 1014999,
"FJ": 875983,
"QA": 840926,
"RE": 776948,
"KM": 773407,
"GY": 748486,
"DJ": 740528,
"BH": 738004,
"BT": 699847,
"ME": 666730,
"SB": 559198,
"CV": 508659,
"LU": 497538,
"SR": 492829,
"MO": 449198,
"GP": 443000,
"MQ": 432900,
"MT": 403000,
"MV": 395650,
"BN": 395027,
"BZ": 314522,
"IS": 308910,
"BS": 301790,
"BB": 285653,
"EH": 273008,
"PF": 270485,
"VU": 221552,
"NC": 216494,
"GF": 195506,
"WS": 192001,
"ST": 175808,
"LC": 160922,
"GU": 159358,
"YT": 159042,
"CW": 141766,
"AN": 136197,
"TO": 122580,
"VI": 108708,
"GD": 107818,
"FM": 107708,
"VC": 104217,
"KI": 92533,
"JE": 90812,
"SC": 88340,
"AG": 86754,
"AD": 84000,
"IM": 75049,
"DM": 72813,
"AW": 71566,
"MH": 65859,
"BM": 65365,
"GG": 65228,
"AS": 57881,
"GL": 56375,
"MP": 53883,
"KN": 49898,
"FO": 48228,
"KY": 44270,
"SX": 37429,
"MF": 35925,
"LI": 35000,
"MC": 32965,
"SM": 31477,
"GI": 27884,
"AX": 26711,
"VG": 21730,
"CK": 21388,
"TC": 20556,
"PW": 19907,
"BQ": 18012,
"WF": 16025,
"AI": 13254,
"TV": 10472,
"NR": 10065,
"MS": 9341,
"BL": 8450,
"SH": 7460,
"PM": 7012,
"IO": 4000,
"FK": 2638,
"SJ": 2550,
"NU": 2166,
"NF": 1828,
"CX": 1500,
"TK": 1466,
"VA": 921,
"CC": 628,
"TF": 140,
"PN": 46,
"GS": 30
}

View File

@ -8,8 +8,11 @@ module.exports = WeightedList;
var _ = require('../../../../src/lib/utils');
function WeightedList(list) {
WeightedList.callSuper(this, arguments);
Array.call(this);
_.forEach(list, _.bindKey(this, 'push'));
console.log(this);
}
_.inherits(WeightedList, Array);

View File

@ -32,7 +32,7 @@ function download() {
restSpecUpdated(function (err, updated) {
if (process.env.FORCE_GEN || process.env.npm_config_force || err || updated) {
if (err || updated) {
download();
}
});

View File

@ -7,6 +7,7 @@ var request = {
}
};
var fs = require('fs');
var _ = require('lodash');
var lastRestSpecUpdateFile = __dirname + '/last_rest_spec_update.sha';
var lastRestSpecUpdate;
@ -16,46 +17,61 @@ if (fs.existsSync(lastRestSpecUpdateFile)) {
lastRestSpecUpdate = fs.readFileSync(lastRestSpecUpdateFile, 'utf8');
}
var req = https.get(request, function (incoming) {
if (incoming.statusCode !== 200) {
req.abort();
console.error('request for last commit failed', incoming.statusCode, incoming.headers);
return;
}
var req = null;
var force = false;
var body = '';
if (process.env.npm_config_force ||
process.env.FORCE_GEN ||
_.contains(process.argv, '-f') ||
_.contains(process.argv, '--force')
) {
force = true;
}
incoming.on('data', onData);
incoming.on('end', onEnd);
function onData(chunk) {
body += chunk;
}
function onEnd() {
incoming.removeListener('data', onData);
incoming.removeListener('end', onEnd);
var _req = req;
req = null;
var resp;
try {
resp = JSON.parse(body);
} catch (e) {
console.log('unable to parse response from github');
_req.emit('ready');
if (force) {
updated = true;
} else {
req = https.get(request, function (incoming) {
if (incoming.statusCode !== 200) {
req.abort();
console.error('request for last commit failed', incoming.statusCode, incoming.headers);
return;
}
if (lastRestSpecUpdate === resp.sha) {
updated = false;
} else {
updated = true;
fs.writeFileSync(lastRestSpecUpdateFile, resp.sha);
var body = '';
incoming.on('data', onData);
incoming.on('end', onEnd);
function onData(chunk) {
body += chunk;
}
_req.emit('ready');
}
});
function onEnd() {
incoming.removeListener('data', onData);
incoming.removeListener('end', onEnd);
var _req = req;
req = null;
var resp;
try {
resp = JSON.parse(body);
} catch (e) {
console.log('unable to parse response from github');
_req.emit('ready');
return;
}
if (lastRestSpecUpdate === resp.sha) {
updated = false;
} else {
updated = true;
fs.writeFileSync(lastRestSpecUpdateFile, resp.sha);
}
_req.emit('ready');
}
});
}
module.exports = function (cb) {
function done() {

View File

@ -5,69 +5,84 @@ var open = require('open');
var fs = require('fs');
var path = require('path');
var async = require('async');
var chalk = require('chalk');
var yamlTestSourceFile = path.join(__dirname, '../../test/integration/yaml_suite/index.js');
var yamlTestBundleFile = path.join(__dirname, '../../test/browser_integration/yaml_tests.js');
var yamlTestBundleFile = path.join(__dirname, '../../test/integration/browser_yaml_suite/yaml_tests.js');
var clientEntryFile = path.join(__dirname, '../../src/elasticsearch.js');
var browsers = _.transform({
var browserAppNames = _.transform({
safari: {
darwin: 'Safari'
},
chrome: {
darwin: 'Google Chrome',
win32: 'Google Chrome',
executable: 'google-chrome'
linux: 'google-chrome'
},
chromium: {
executable: 'chromium-browser',
linux: 'chromium-browser',
},
firefox: {
darwin: 'Firefox',
win32: 'Firefox',
executable: 'firefox'
linux: 'firefox'
},
opera: {
darwin: 'Opera',
win32: 'Opera',
executable: 'opera'
linux: 'opera'
}
}, function (browsers, config, name) {
}, function (browserAppNames, config, name) {
if (config[process.platform]) {
browsers[name] = config[process.platform];
browserAppNames[name] = config[process.platform];
return;
}
if (process.platform !== 'darwin' && process.platform !== 'win32' && config.executable) {
browsers[name] = config.executable;
if (process.platform !== 'darwin' && process.platform !== 'win32' && config.linux) {
browserAppNames[name] = config.executable;
return;
}
}, {});
var argv = require('optimist')
.default('browser', 'chrome')
.default('force_gen', false)
.boolean('force_gen')
.alias('f', 'force_gen')
.default('host', 'localhost')
.default('port', 9200)
.default({
browsers: '*',
forceGen: false,
host: 'localhost',
port: 9200
})
.boolean('forceGen')
.alias({
f: 'forceGen',
b: 'browsers',
h: 'host',
p: 'port'
})
.argv;
var browserAppName;
server.browsers = [];
if (argv.browsers === '*') {
server.browsers = _.keys(browserAppNames);
} else {
argv.browsers.split(',').forEach(function (browser) {
server.browsers.push(browser);
});
}
var badKeys = _.difference(server.browsers, _.keys(browserAppNames));
if (badKeys.length) {
console.error('Invalid keys: ' + badKeys.join(', '));
process.exit();
} else {
console.log('opening browser suite in', server.browsers);
}
async.series([
function (done) {
if (browsers.hasOwnProperty(argv.browser)) {
browserAppName = browsers[argv.browser];
done();
} else {
done('--browser must be set to one of ' + _.keys(browsers).join(', ') + ' on this platform');
}
},
function (done) {
fs.exists('dist', function (yes) {
if (!argv.force_gen && yes) {
if (!argv.forceGen && yes) {
done();
return;
}
@ -82,7 +97,7 @@ async.series([
},
function (done) {
fs.exists(yamlTestBundleFile, function (yes) {
if (!argv.force_gen && yes) {
if (!argv.forceGen && yes) {
done();
return;
}
@ -131,13 +146,32 @@ async.series([
var port = server.address().port;
console.log('server listening on port', port);
open('http://localhost:' + port + '?es_hostname=' + encodeURIComponent(argv.host) +
'&es_port=' + encodeURIComponent(argv.port) +
'&browser=' + encodeURIComponent(argv.browser), browserAppName);
async.eachSeries(_.clone(server.browsers), function (browser, done) {
open('http://localhost:' + port +
'?es_hostname=' + encodeURIComponent(argv.host) +
'&es_port=' + encodeURIComponent(argv.port) +
'&browser=' + encodeURIComponent(browser), browserAppNames[browser]);
server.once('browser complete', function () {
done();
});
});
});
server.on('tests done', function (success) {
console.log('test completed', success ? 'successfully' : 'but failed');
server.on('tests done', function (report) {
var reports = [];
var success = true;
_.each(report, function (testSucceeded, browser) {
var msg = browser + ':' + (success ? '✔︎' : '⚑');
if (testSucceeded) {
msg = chalk.green(msg);
} else {
msg = chalk.red(msg);
success = false;
}
reports.push(' - ' + msg);
});
console.log('test completed!\n', reports.join('\n'));
process.exit(success ? 0 : 1);
});
}

View File

@ -5,6 +5,7 @@ var fs = require('fs');
var _ = require('lodash');
var chalk = require('chalk');
var makeJUnitXml = require('../make_j_unit_xml');
var docRoot = path.join(__dirname, '../../test/integration/browser_yaml_suite');
chalk.enabled = true;
var middleware = [];
@ -17,7 +18,7 @@ var server = http.createServer(function (req, resp) {
var parsedUrl = url.parse(req.url, true);
req.uri = parsedUrl.pathname;
req.query = parsedUrl.query;
req.filename = path.join(__dirname, '../../test/browser_integration/', req.uri);
req.filename = path.join(docRoot, req.uri);
var end = resp.end;
resp.end = function () {
@ -39,6 +40,11 @@ var server = http.createServer(function (req, resp) {
next();
});
server.browsers = [
// browsers will go here, and will be removed once they call tests-complete
// once gone, we will emit "tests done"
];
function rand(length) {
var str = '';
while (str.length < length) {
@ -50,7 +56,7 @@ function rand(length) {
function collectTestResults(req, resp) {
var body = '';
var browser = req.query.browser;
var logFilename = path.join(__dirname, '../../test-output-' + browser + '.xml');
var logFilename = 'test-output-' + browser + '.xml';
req.on('data', function (chunk) {
body += chunk;
@ -79,15 +85,33 @@ function collectTestResults(req, resp) {
if (err) {
console.log('unable to save test-output to', err.message);
console.trace();
server.emit('tests done', false);
browserComplete(browser);
} else {
console.log('test output written to', logFilename);
server.emit('tests done', !testDetails.stats.failures);
browserComplete(browser, true);
}
});
});
}
var report = {};
function browserComplete(browser, success) {
var i = server.browsers.indexOf(browser);
report[browser] = success;
server.emit('browser complete', browser, success);
if (i >= 0) {
server.browsers.splice(i, 1);
if (server.browsers.length) {
console.log('waiting for', server.browsers.length, 'browsers');
} else {
server.emit('tests done', report);
}
} else {
console.error('invalid browser', browser);
}
}
middleware.push(function (req, resp, next) {
// resolve filenames
@ -120,7 +144,7 @@ middleware.push(function (req, resp, next) {
resp.end();
} else {
if (stats.isDirectory()) {
req.filename = path.join(req.filename, '../../test/browser_integration/index.html');
req.filename = path.join(docRoot, 'index.html');
}
next();
}
@ -176,7 +200,7 @@ middleware.push(function (req, resp) {
es_hostname: 'localhost',
es_port: 9200,
browser: 'unknown',
ts: 'no'//rand(5)
ts: rand(5)
})));
} else {
resp.end(data);

View File

@ -9,13 +9,13 @@ var argv = require('optimist')
].join('\n'))
.default({
server: true,
browser: true,
unit: true,
integration: false,
host: 'localhost',
port: 9200,
'xml-output': true,
'check-upstream': false
'check-upstream': false,
'browsers': '*'
})
.describe({
host: 'hostname for elasticsearch instance used in integration tests',
@ -24,7 +24,7 @@ var argv = require('optimist')
.alias({
u: 'unit',
i: 'integration',
b: 'browser',
b: 'browsers',
s: 'server',
x: 'xml-output'
});
@ -46,7 +46,7 @@ var commands = [];
if (argv['just-browser']) {
argv.server = false;
argv.browser = true;
argv.browsers = '*';
}
if (argv['check-upstream']) {
@ -57,7 +57,7 @@ if (argv.unit) {
if (argv.server) {
commands.push(['mocha', 'test/unit/test_*.js', '--require=should']);
}
if (argv.browser) {
if (argv.browsers) {
commands.push(['testling', '.']);
}
}
@ -74,8 +74,13 @@ if (argv.integration) {
'--port', argv.port
].filter(Boolean));
}
if (argv.browser) {
commands.push(['node', 'scripts/run_browser_integration_suite/index.js']);
if (argv.browsers) {
commands.push([
'node',
'scripts/run_browser_integration_suite/index.js',
'--browsers',
argv.browsers
]);
}
}

View File

@ -1,8 +1,9 @@
var es = {
Client: require('./lib/client'),
errors: require('./lib/errors'),
ConnectionPool: require('./lib/connection_pool'),
Transport: require('./lib/transport')
Transport: require('./lib/transport'),
errors: require('./lib/errors')
};
module.exports = es;

View File

@ -13,7 +13,7 @@ api._namespaces = ['cluster', 'indices'];
* @param {Boolean} params.refresh - Refresh the index after performing the operation
* @param {String} [params.replication=sync] - Explicitely set the replication type
* @param {String} params.type - Default document type for items which don't provide one
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {String} params.index - Default index for items which don't provide one
*/
api.bulk = ca({
@ -77,7 +77,7 @@ api.bulk = ca({
* Perform a [clearScroll](http://www.elasticsearch.org/guide/reference/api/search/scroll/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String or String[] or Boolean} params.scrollId - A comma-separated list of scroll IDs to clear
* @param {String, String[], Boolean} params.scrollId - A comma-separated list of scroll IDs to clear
*/
api.clearScroll = ca({
url: {
@ -115,8 +115,8 @@ api.cluster.prototype.getSettings = ca({
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} [params.level=cluster] - Specify the level of detail for returned information
* @param {Boolean} params.local - Return local information, do not retrieve the state from master node (default: false)
* @param {Date or Number} params.masterTimeout - Explicit operation timeout for connection to master node
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.masterTimeout - Explicit operation timeout for connection to master node
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Number} params.waitForActiveShards - Wait until the specified number of shards is active
* @param {String} params.waitForNodes - Wait until the specified number of nodes is available
* @param {Number} params.waitForRelocatingShards - Wait until the specified number of relocating shards is finished
@ -187,11 +187,11 @@ api.cluster.prototype.health = ca({
* Perform a [cluster.nodeHotThreads](http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-hot-threads/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.interval - The interval for the second sampling of threads
* @param {Date, Number} params.interval - The interval for the second sampling of threads
* @param {Number} params.snapshots - Number of samples of thread stacktrace (default: 10)
* @param {Number} params.threads - Specify the number of threads to provide information for (default: 3)
* @param {String} params.type - The type to sample (default: cpu)
* @param {String or String[] or Boolean} params.nodeId - A comma-separated 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
* @param {String, String[], Boolean} params.nodeId - A comma-separated 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
*/
api.cluster.prototype.nodeHotThreads = ca({
params: {
@ -243,9 +243,9 @@ api.cluster.prototype.nodeHotThreads = ca({
* @param {Boolean} params.process - Return information about the Elasticsearch process
* @param {Boolean} params.settings - Return information about node settings
* @param {Boolean} params.threadPool - Return information about the thread pool
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Boolean} params.transport - Return information about transport
* @param {String or String[] or Boolean} params.nodeId - A comma-separated 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
* @param {String, String[], Boolean} params.nodeId - A comma-separated 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
*/
api.cluster.prototype.nodeInfo = ca({
params: {
@ -307,9 +307,9 @@ api.cluster.prototype.nodeInfo = ca({
* Perform a [cluster.nodeShutdown](http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.delay - Set the delay for the operation (default: 1s)
* @param {Date, Number} params.delay - Set the delay for the operation (default: 1s)
* @param {Boolean} params.exit - Exit the JVM as well (default: true)
* @param {String or String[] or Boolean} params.nodeId - A comma-separated list of node IDs or names to perform the operation on; use `_local` to perform the operation on the node you're connected to, leave empty to perform the operation on all nodes
* @param {String, String[], Boolean} params.nodeId - A comma-separated list of node IDs or names to perform the operation on; use `_local` to perform the operation on the node you're connected to, leave empty to perform the operation on all nodes
*/
api.cluster.prototype.nodeShutdown = ca({
params: {
@ -343,7 +343,7 @@ api.cluster.prototype.nodeShutdown = ca({
* @param {Object} params - An object with parameters used to carry out this action
* @param {Boolean} params.all - Return all available information
* @param {Boolean} params.clear - Reset the default level of detail
* @param {String or String[] or Boolean} params.fields - A comma-separated list of fields to return detailed information for, when returning the `indices` metric family (supports wildcards)
* @param {String, String[], Boolean} params.fields - A comma-separated list of fields to return detailed information for, when returning the `indices` metric family (supports wildcards)
* @param {Boolean} params.fs - Return information about the filesystem
* @param {Boolean} params.http - Return information about HTTP
* @param {Boolean} params.indices - Return information about indices
@ -355,7 +355,7 @@ api.cluster.prototype.nodeShutdown = ca({
* @param {Boolean} params.transport - Return information about transport
* @param {String} params.metricFamily - Limit the information returned to a certain metric family
* @param {String} params.metric - Limit the information returned for `indices` family to a specific metric
* @param {String or String[] or Boolean} params.nodeId - A comma-separated 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
* @param {String, String[], Boolean} params.nodeId - A comma-separated 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
*/
api.cluster.prototype.nodeStats = ca({
params: {
@ -457,12 +457,12 @@ api.cluster.prototype.reroute = ca({
* @param {Object} params - An object with parameters used to carry out this action
* @param {Boolean} params.filterBlocks - Do not return information about blocks
* @param {Boolean} params.filterIndexTemplates - Do not return information about index templates
* @param {String or String[] or Boolean} params.filterIndices - Limit returned metadata information to specific indices
* @param {String, String[], Boolean} params.filterIndices - Limit returned metadata information to specific indices
* @param {Boolean} params.filterMetadata - Do not return information about indices metadata
* @param {Boolean} params.filterNodes - Do not return information about nodes
* @param {Boolean} params.filterRoutingTable - Do not return information about shard allocation (`routing_table` and `routing_nodes`)
* @param {Boolean} params.local - Return local information, do not retrieve the state from master node (default: false)
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
*/
api.cluster.prototype.state = ca({
params: {
@ -513,8 +513,8 @@ api.cluster.prototype.state = ca({
* @param {String} params.preference - Specify the node or shard the operation should be performed on (default: random)
* @param {String} params.routing - Specific routing value
* @param {String} params.source - The URL-encoded query definition (instead of using the request body)
* @param {String or String[] or Boolean} params.index - A comma-separated list of indices to restrict the results
* @param {String or String[] or Boolean} params.type - A comma-separated list of types to restrict the results
* @param {String, String[], Boolean} params.index - A comma-separated list of indices to restrict the results
* @param {String, String[], Boolean} params.type - A comma-separated list of types to restrict the results
*/
api.count = ca({
params: {
@ -578,7 +578,7 @@ api.count = ca({
* @param {Boolean} params.refresh - Refresh the index after performing the operation
* @param {String} [params.replication=sync] - Specific replication type
* @param {String} params.routing - Specific routing value
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Number} params.version - Explicit version number for concurrency control
* @param {String} params.versionType - Specific version type
* @param {String} params.id - The document ID
@ -659,9 +659,9 @@ api['delete'] = ca({
* @param {String} params.q - Query in the Lucene query string syntax
* @param {String} params.routing - Specific routing value
* @param {String} params.source - The URL-encoded query definition (instead of using the request body)
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {String or String[] or Boolean} params.index - A comma-separated list of indices to restrict the operation; use `_all` to perform the operation on all indices
* @param {String or String[] or Boolean} params.type - A comma-separated list of types to restrict the operation
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {String, String[], Boolean} params.index - A comma-separated list of indices to restrict the operation; use `_all` to perform the operation on all indices
* @param {String, String[], Boolean} params.type - A comma-separated list of types to restrict the operation
*/
api.deleteByQuery = ca({
params: {
@ -805,16 +805,16 @@ api.exists = ca({
* @param {String} params.analyzer - The analyzer for the query string query
* @param {String} [params.defaultOperator=OR] - The default operator for query string query (AND or OR)
* @param {String} params.df - The default field for query string query (default: _all)
* @param {String or String[] or Boolean} params.fields - A comma-separated list of fields to return in the response
* @param {String, String[], Boolean} params.fields - A comma-separated list of fields to return in the response
* @param {Boolean} params.lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored
* @param {Boolean} params.lowercaseExpandedTerms - Specify whether query terms should be lowercased
* @param {String} params.parent - The ID of the parent document
* @param {String} params.preference - Specify the node or shard the operation should be performed on (default: random)
* @param {String} params.q - Query in the Lucene query string syntax
* @param {String} params.routing - Specific routing value
* @param {String or String[] or Boolean} params.source - True or false to return the _source field or not, or a list of fields to return
* @param {String or String[] or Boolean} params.sourceExclude - A list of fields to exclude from the returned _source field
* @param {String or String[] or Boolean} params.sourceInclude - A list of fields to extract and return from the _source field
* @param {String, String[], Boolean} params.source - True or false to return the _source field or not, or a list of fields to return
* @param {String, String[], Boolean} params.sourceExclude - A list of fields to exclude from the returned _source field
* @param {String, String[], Boolean} params.sourceInclude - A list of fields to extract and return from the _source field
* @param {String} params.id - The document ID
* @param {String} params.index - The name of the index
* @param {String} params.type - The type of the document
@ -898,15 +898,15 @@ api.explain = ca({
* Perform a [get](http://elasticsearch.org/guide/reference/api/get/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String or String[] or Boolean} params.fields - A comma-separated list of fields to return in the response
* @param {String, String[], Boolean} params.fields - A comma-separated list of fields to return in the response
* @param {String} params.parent - The ID of the parent document
* @param {String} params.preference - Specify the node or shard the operation should be performed on (default: random)
* @param {Boolean} params.realtime - Specify whether to perform the operation in realtime or search mode
* @param {Boolean} params.refresh - Refresh the shard containing the document before performing the operation
* @param {String} params.routing - Specific routing value
* @param {String or String[] or Boolean} params.source - True or false to return the _source field or not, or a list of fields to return
* @param {String or String[] or Boolean} params.sourceExclude - A list of fields to exclude from the returned _source field
* @param {String or String[] or Boolean} params.sourceInclude - A list of fields to extract and return from the _source field
* @param {String, String[], Boolean} params.source - True or false to return the _source field or not, or a list of fields to return
* @param {String, String[], Boolean} params.sourceExclude - A list of fields to exclude from the returned _source field
* @param {String, String[], Boolean} params.sourceInclude - A list of fields to extract and return from the _source field
* @param {String} params.id - The document ID
* @param {String} params.index - The name of the index
* @param {String} [params.type=_all] - The type of the document (use `_all` to fetch the first document matching the ID across all types)
@ -969,8 +969,8 @@ api.get = ca({
* Perform a [getSource](http://elasticsearch.org/guide/reference/api/get/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String or String[] or Boolean} params.exclude - A list of fields to exclude from the returned _source field
* @param {String or String[] or Boolean} params.include - A list of fields to extract and return from the _source field
* @param {String, String[], Boolean} params.exclude - A list of fields to exclude from the returned _source field
* @param {String, String[], Boolean} params.include - A list of fields to extract and return from the _source field
* @param {String} params.parent - The ID of the parent document
* @param {String} params.preference - Specify the node or shard the operation should be performed on (default: random)
* @param {Boolean} params.realtime - Specify whether to perform the operation in realtime or search mode
@ -1036,8 +1036,8 @@ api.getSource = ca({
* @param {Boolean} params.refresh - Refresh the index after performing the operation
* @param {String} [params.replication=sync] - Specific replication type
* @param {String} params.routing - Specific routing value
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date or Number} params.timestamp - Explicit timestamp for the document
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.timestamp - Explicit timestamp for the document
* @param {Duration} params.ttl - Expiration time for the document
* @param {Number} params.version - Explicit version number for concurrency control
* @param {String} params.versionType - Specific version type
@ -1146,7 +1146,7 @@ api.indices = function IndicesNS(transport) {
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} params.analyzer - The name of the analyzer to use
* @param {String} params.field - Use the analyzer configured for this field (instead of passing the analyzer name)
* @param {String or String[] or Boolean} params.filters - A comma-separated list of filters to use for the analysis
* @param {String, String[], Boolean} params.filters - A comma-separated list of filters to use for the analysis
* @param {String} params.index - The name of the index to scope the operation
* @param {Boolean} params.preferLocal - With `true`, specify that a local shard should be used if available, with `false`, use a random shard (default: true)
* @param {String} params.text - The text on which the analysis should be performed (when request body is not used)
@ -1209,14 +1209,14 @@ api.indices.prototype.analyze = ca({
* @param {Object} params - An object with parameters used to carry out this action
* @param {Boolean} params.fieldData - Clear field data
* @param {Boolean} params.fielddata - Clear field data
* @param {String or String[] or Boolean} params.fields - A comma-separated list of fields to clear when using the `field_data` parameter (default: all)
* @param {String, String[], Boolean} params.fields - A comma-separated list of fields to clear when using the `field_data` parameter (default: all)
* @param {Boolean} params.filter - Clear filter caches
* @param {Boolean} params.filterCache - Clear filter caches
* @param {Boolean} params.filterKeys - A comma-separated list of keys to clear when using the `filter_cache` parameter (default: all)
* @param {Boolean} params.id - Clear ID caches for parent/child
* @param {Boolean} params.idCache - Clear ID caches for parent/child
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {String or String[] or Boolean} params.index - A comma-separated list of index name to limit the operation
* @param {String, String[], Boolean} params.index - A comma-separated list of index name to limit the operation
* @param {Boolean} params.recycler - Clear the recycler cache
*/
api.indices.prototype.clearCache = ca({
@ -1286,8 +1286,8 @@ api.indices.prototype.clearCache = ca({
* Perform a [indices.close](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String} params.index - The name of the index
*/
api.indices.prototype.close = ca({
@ -1317,8 +1317,8 @@ api.indices.prototype.close = ca({
* Perform a [indices.create](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String} params.index - The name of the index
*/
api.indices.prototype.create = ca({
@ -1348,9 +1348,9 @@ api.indices.prototype.create = ca({
* Perform a [indices.delete](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-index/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {String or String[] or Boolean} params.index - A comma-separated list of indices to delete; use `_all` or empty string to delete all indices
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String, String[], Boolean} params.index - A comma-separated list of indices to delete; use `_all` or empty string to delete all indices
*/
api.indices.prototype['delete'] = ca({
params: {
@ -1383,8 +1383,8 @@ api.indices.prototype['delete'] = ca({
* Perform a [indices.deleteAlias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.timeout - Explicit timestamp for the document
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {Date, Number} params.timeout - Explicit timestamp for the document
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String} params.index - The name of the index with an alias
* @param {String} params.name - The name of the alias to be deleted
*/
@ -1418,8 +1418,8 @@ api.indices.prototype.deleteAlias = ca({
* Perform a [indices.deleteMapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-mapping/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` for all indices
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` for all indices
* @param {String} params.type - The name of the document type to delete
*/
api.indices.prototype.deleteMapping = ca({
@ -1449,8 +1449,8 @@ api.indices.prototype.deleteMapping = ca({
* Perform a [indices.deleteTemplate](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String} params.name - The name of the template
*/
api.indices.prototype.deleteTemplate = ca({
@ -1480,10 +1480,10 @@ api.indices.prototype.deleteTemplate = ca({
* Perform a [indices.deleteWarmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names to register warmer for; use `_all` or empty string to perform the operation on all indices
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to register warmer for; use `_all` or empty string to perform the operation on all indices
* @param {String} params.name - The name of the warmer (supports wildcards); leave empty to delete all warmers
* @param {String or String[] or Boolean} params.type - A comma-separated list of document types to register warmer for; use `_all` or empty string to perform the operation on all types
* @param {String, String[], Boolean} params.type - A comma-separated list of document types to register warmer for; use `_all` or empty string to perform the operation on all types
*/
api.indices.prototype.deleteWarmer = ca({
params: {
@ -1535,7 +1535,7 @@ api.indices.prototype.deleteWarmer = ca({
* Perform a [indices.exists](http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String or String[] or Boolean} params.index - A comma-separated list of indices to check
* @param {String, String[], Boolean} params.index - A comma-separated list of indices to check
*/
api.indices.prototype.exists = ca({
url: {
@ -1557,8 +1557,8 @@ api.indices.prototype.exists = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names to filter aliases
* @param {String or String[] or Boolean} params.name - A comma-separated list of alias names to return
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to filter aliases
* @param {String, String[], Boolean} params.name - A comma-separated list of alias names to return
*/
api.indices.prototype.existsAlias = ca({
params: {
@ -1603,8 +1603,8 @@ api.indices.prototype.existsAlias = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` to check the types across all indices
* @param {String or String[] or Boolean} params.type - A comma-separated list of document types to check
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` to check the types across all indices
* @param {String, String[], Boolean} params.type - A comma-separated list of document types to check
*/
api.indices.prototype.existsType = ca({
params: {
@ -1643,7 +1643,7 @@ api.indices.prototype.existsType = ca({
* @param {Boolean} params.full - TODO: ?
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {Boolean} params.refresh - Refresh the index after performing the operation
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` or empty string for all indices
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string for all indices
*/
api.indices.prototype.flush = ca({
params: {
@ -1688,8 +1688,8 @@ api.indices.prototype.flush = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names to filter aliases
* @param {String or String[] or Boolean} params.name - A comma-separated list of alias names to return
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to filter aliases
* @param {String, String[], Boolean} params.name - A comma-separated list of alias names to return
*/
api.indices.prototype.getAlias = ca({
params: {
@ -1731,8 +1731,8 @@ api.indices.prototype.getAlias = ca({
* Perform a [indices.getAliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names to filter aliases
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to filter aliases
*/
api.indices.prototype.getAliases = ca({
params: {
@ -1761,9 +1761,9 @@ api.indices.prototype.getAliases = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Boolean} params.includeDefaults - Whether the default mapping values should be returned as well
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names
* @param {String or String[] or Boolean} params.type - A comma-separated list of document types
* @param {String or String[] or Boolean} params.field - A comma-separated list of fields
* @param {String, String[], Boolean} params.index - A comma-separated list of index names
* @param {String, String[], Boolean} params.type - A comma-separated list of document types
* @param {String, String[], Boolean} params.field - A comma-separated list of fields
*/
api.indices.prototype.getFieldMapping = ca({
params: {
@ -1814,8 +1814,8 @@ api.indices.prototype.getFieldMapping = ca({
* Perform a [indices.getMapping](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names
* @param {String or String[] or Boolean} params.type - A comma-separated list of document types
* @param {String, String[], Boolean} params.index - A comma-separated list of index names
* @param {String, String[], Boolean} params.type - A comma-separated list of document types
*/
api.indices.prototype.getMapping = ca({
urls: [
@ -1849,7 +1849,7 @@ api.indices.prototype.getMapping = ca({
* Perform a [indices.getSettings](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-settings/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
*/
api.indices.prototype.getSettings = ca({
urls: [
@ -1895,9 +1895,9 @@ api.indices.prototype.getTemplate = ca({
* Perform a [indices.getWarmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names to restrict the operation; use `_all` to perform the operation on all indices
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to restrict the operation; use `_all` to perform the operation on all indices
* @param {String} params.name - The name of the warmer (supports wildcards); leave empty to get all warmers
* @param {String or String[] or Boolean} params.type - A comma-separated list of document types to restrict the operation; leave empty to perform the operation on all types
* @param {String, String[], Boolean} params.type - A comma-separated list of document types to restrict the operation; leave empty to perform the operation on all types
*/
api.indices.prototype.getWarmer = ca({
urls: [
@ -1942,8 +1942,8 @@ api.indices.prototype.getWarmer = ca({
* Perform a [indices.open](http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String} params.index - The name of the index
*/
api.indices.prototype.open = ca({
@ -1977,10 +1977,10 @@ api.indices.prototype.open = ca({
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {Number} params.maxNumSegments - The number of segments the index should be merged into (default: dynamic)
* @param {Boolean} params.onlyExpungeDeletes - Specify whether the operation should only expunge deleted documents
* @param {*} params.operationThreading - TODO: ?
* @param {Anything} params.operationThreading - TODO: ?
* @param {Boolean} params.refresh - Specify whether the index should be refreshed after performing the operation (default: true)
* @param {Boolean} params.waitForMerge - Specify whether the request should block until the merge process is finished (default: true)
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
*/
api.indices.prototype.optimize = ca({
params: {
@ -2036,8 +2036,8 @@ api.indices.prototype.optimize = ca({
* Perform a [indices.putAlias](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.timeout - Explicit timestamp for the document
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {Date, Number} params.timeout - Explicit timestamp for the document
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String} params.index - The name of the index with an alias
* @param {String} params.name - The name of the alias to be created or updated
*/
@ -2092,9 +2092,9 @@ api.indices.prototype.putAlias = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Boolean} params.ignoreConflicts - Specify whether to ignore conflicts while updating the mapping (default: false)
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` to perform the operation on all indices
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` to perform the operation on all indices
* @param {String} params.type - The name of the document type
*/
api.indices.prototype.putMapping = ca({
@ -2131,8 +2131,8 @@ api.indices.prototype.putMapping = ca({
* Perform a [indices.putSettings](http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
*/
api.indices.prototype.putSettings = ca({
params: {
@ -2163,8 +2163,8 @@ api.indices.prototype.putSettings = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Number} params.order - The order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers)
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String} params.name - The name of the template
*/
api.indices.prototype.putTemplate = ca({
@ -2197,10 +2197,10 @@ api.indices.prototype.putTemplate = ca({
* Perform a [indices.putWarmer](http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names to register the warmer for; use `_all` or empty string to perform the operation on all indices
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to register the warmer for; use `_all` or empty string to perform the operation on all indices
* @param {String} params.name - The name of the warmer
* @param {String or String[] or Boolean} params.type - A comma-separated list of document types to register the warmer for; leave empty to perform the operation on all types
* @param {String, String[], Boolean} params.type - A comma-separated list of document types to register the warmer for; leave empty to perform the operation on all types
*/
api.indices.prototype.putWarmer = ca({
params: {
@ -2245,8 +2245,8 @@ api.indices.prototype.putWarmer = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {*} params.operationThreading - TODO: ?
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
* @param {Anything} params.operationThreading - TODO: ?
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
*/
api.indices.prototype.refresh = ca({
params: {
@ -2285,8 +2285,8 @@ api.indices.prototype.refresh = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {*} params.operationThreading - TODO: ?
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
* @param {Anything} params.operationThreading - TODO: ?
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
*/
api.indices.prototype.segments = ca({
params: {
@ -2324,7 +2324,7 @@ api.indices.prototype.segments = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` or empty string for all indices
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string for all indices
*/
api.indices.prototype.snapshotIndex = ca({
params: {
@ -2362,11 +2362,11 @@ api.indices.prototype.snapshotIndex = ca({
* @param {Boolean} params.all - Return all available information
* @param {Boolean} params.clear - Reset the default level of detail
* @param {Boolean} params.completion - Return information about completion suggester stats
* @param {String or String[] or Boolean} params.completionFields - A comma-separated list of fields for `completion` metric (supports wildcards)
* @param {String, String[], Boolean} params.completionFields - A comma-separated list of fields for `completion` metric (supports wildcards)
* @param {Boolean} params.docs - Return information about indexed and deleted documents
* @param {Boolean} params.fielddata - Return information about field data
* @param {String or String[] or Boolean} params.fielddataFields - A comma-separated list of fields for `fielddata` metric (supports wildcards)
* @param {String or String[] or Boolean} params.fields - A comma-separated list of fields to return detailed information for, when returning the `search` statistics
* @param {String, String[], Boolean} params.fielddataFields - A comma-separated list of fields for `fielddata` metric (supports wildcards)
* @param {String, String[], Boolean} params.fields - A comma-separated list of fields to return detailed information for, when returning the `search` statistics
* @param {Boolean} params.filterCache - Return information about filter cache
* @param {Boolean} params.flush - Return information about flush operations
* @param {Boolean} params.get - Return information about get operations
@ -2379,10 +2379,10 @@ api.indices.prototype.snapshotIndex = ca({
* @param {Boolean} params.search - Return information about search operations; use the `groups` parameter to include information for specific search groups
* @param {Boolean} params.store - Return information about the size of the index
* @param {Boolean} params.warmer - Return information about warmers
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
* @param {String or String[] or Boolean} params.indexingTypes - A comma-separated list of document types to include in the `indexing` statistics
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
* @param {String, String[], Boolean} params.indexingTypes - A comma-separated list of document types to include in the `indexing` statistics
* @param {String} params.metricFamily - Limit the information returned to a specific metric
* @param {String or String[] or Boolean} params.searchGroups - A comma-separated list of search groups to include in the `search` statistics
* @param {String, String[], Boolean} params.searchGroups - A comma-separated list of search groups to include in the `search` statistics
*/
api.indices.prototype.stats = ca({
params: {
@ -2478,10 +2478,10 @@ api.indices.prototype.stats = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {*} params.operationThreading - TODO: ?
* @param {Anything} params.operationThreading - TODO: ?
* @param {Boolean} params.recovery - Return information about shard recovery
* @param {Boolean} params.snapshot - TODO: ?
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
* @param {String, String[], Boolean} params.index - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
*/
api.indices.prototype.status = ca({
params: {
@ -2524,9 +2524,9 @@ api.indices.prototype.status = ca({
* Perform a [indices.updateAliases](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {Date or Number} params.timeout - Request timeout
* @param {Date or Number} params.masterTimeout - Specify timeout for connection to master
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names to filter aliases
* @param {Date, Number} params.timeout - Request timeout
* @param {Date, Number} params.masterTimeout - Specify timeout for connection to master
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to filter aliases
*/
api.indices.prototype.updateAliases = ca({
params: {
@ -2551,11 +2551,11 @@ api.indices.prototype.updateAliases = ca({
* @param {Object} params - An object with parameters used to carry out this action
* @param {Boolean} params.explain - Return detailed information about the error
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {*} params.operationThreading - TODO: ?
* @param {Anything} params.operationThreading - TODO: ?
* @param {String} params.source - The URL-encoded query definition (instead of using the request body)
* @param {String} params.q - Query in the Lucene query string syntax
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names to restrict the operation; use `_all` or empty string to perform the operation on all indices
* @param {String or String[] or Boolean} params.type - A comma-separated list of document types to restrict the operation; leave empty to perform the operation on all types
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to restrict the operation; use `_all` or empty string to perform the operation on all indices
* @param {String, String[], Boolean} params.type - A comma-separated list of document types to restrict the operation; leave empty to perform the operation on all types
*/
api.indices.prototype.validateQuery = ca({
params: {
@ -2625,13 +2625,13 @@ api.info = ca({
* Perform a [mget](http://elasticsearch.org/guide/reference/api/multi-get/) request
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String or String[] or Boolean} params.fields - A comma-separated list of fields to return in the response
* @param {String, String[], Boolean} params.fields - A comma-separated list of fields to return in the response
* @param {String} params.preference - Specify the node or shard the operation should be performed on (default: random)
* @param {Boolean} params.realtime - Specify whether to perform the operation in realtime or search mode
* @param {Boolean} params.refresh - Refresh the shard containing the document before performing the operation
* @param {String or String[] or Boolean} params.source - True or false to return the _source field or not, or a list of fields to return
* @param {String or String[] or Boolean} params.sourceExclude - A list of fields to exclude from the returned _source field
* @param {String or String[] or Boolean} params.sourceInclude - A list of fields to extract and return from the _source field
* @param {String, String[], Boolean} params.source - True or false to return the _source field or not, or a list of fields to return
* @param {String, String[], Boolean} params.sourceExclude - A list of fields to exclude from the returned _source field
* @param {String, String[], Boolean} params.sourceInclude - A list of fields to extract and return from the _source field
* @param {String} params.index - The name of the index
* @param {String} params.type - The type of the document
*/
@ -2701,18 +2701,18 @@ api.mget = ca({
* @param {Number} params.minDocFreq - The word occurrence frequency as count: words with lower occurrence in the corpus will be ignored
* @param {Number} params.minTermFreq - The term frequency as percent: terms with lower occurence in the source document will be ignored
* @param {Number} params.minWordLen - The minimum length of the word: shorter words will be ignored
* @param {String or String[] or Boolean} params.mltFields - Specific fields to perform the query against
* @param {String, String[], Boolean} params.mltFields - Specific fields to perform the query against
* @param {Number} params.percentTermsToMatch - How many terms have to match in order to consider the document a match (default: 0.3)
* @param {String} params.routing - Specific routing value
* @param {Number} params.searchFrom - The offset from which to return results
* @param {String or String[] or Boolean} params.searchIndices - A comma-separated list of indices to perform the query against (default: the index containing the document)
* @param {String, String[], Boolean} params.searchIndices - A comma-separated list of indices to perform the query against (default: the index containing the document)
* @param {String} params.searchQueryHint - The search query hint
* @param {String} params.searchScroll - A scroll search request definition
* @param {Number} params.searchSize - The number of documents to return (default: 10)
* @param {String} params.searchSource - A specific search request definition (instead of using the request body)
* @param {String} params.searchType - Specific search type (eg. `dfs_then_fetch`, `count`, etc)
* @param {String or String[] or Boolean} params.searchTypes - A comma-separated list of types to perform the query against (default: the same type as the document)
* @param {String or String[] or Boolean} params.stopWords - A list of stop words to be ignored
* @param {String, String[], Boolean} params.searchTypes - A comma-separated list of types to perform the query against (default: the same type as the document)
* @param {String, String[], Boolean} params.stopWords - A list of stop words to be ignored
* @param {String} params.id - The document ID
* @param {String} params.index - The name of the index
* @param {String} params.type - The type of the document (use `_all` to fetch the first document matching the ID across all types)
@ -2819,8 +2819,8 @@ api.mlt = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} params.searchType - Search operation type
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names to use as default
* @param {String or String[] or Boolean} params.type - A comma-separated list of document types to use as default
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to use as default
* @param {String, String[], Boolean} params.type - A comma-separated list of document types to use as default
*/
api.msearch = ca({
params: {
@ -2940,31 +2940,31 @@ api.scroll = ca({
* @param {String} [params.defaultOperator=OR] - The default operator for query string query (AND or OR)
* @param {String} params.df - The field to use as default where no field prefix is given in the query string
* @param {Boolean} params.explain - Specify whether to return detailed information about score computation as part of a hit
* @param {String or String[] or Boolean} params.fields - A comma-separated list of fields to return as part of a hit
* @param {String, String[], Boolean} params.fields - A comma-separated list of fields to return as part of a hit
* @param {Number} params.from - Starting offset (default: 0)
* @param {String} [params.ignoreIndices=none] - When performed on multiple indices, allows to ignore `missing` ones
* @param {String or String[] or Boolean} params.indicesBoost - Comma-separated list of index boosts
* @param {String, String[], Boolean} params.indicesBoost - Comma-separated list of index boosts
* @param {Boolean} params.lenient - Specify whether format-based query failures (such as providing text to a numeric field) should be ignored
* @param {Boolean} params.lowercaseExpandedTerms - Specify whether query terms should be lowercased
* @param {String} params.preference - Specify the node or shard the operation should be performed on (default: random)
* @param {String} params.q - Query in the Lucene query string syntax
* @param {String or String[] or Boolean} params.routing - A comma-separated list of specific routing values
* @param {String, String[], Boolean} params.routing - A comma-separated list of specific routing values
* @param {Duration} params.scroll - Specify how long a consistent view of the index should be maintained for scrolled search
* @param {String} params.searchType - Search operation type
* @param {Number} params.size - Number of hits to return (default: 10)
* @param {String or String[] or Boolean} params.sort - A comma-separated list of <field>:<direction> pairs
* @param {String or String[] or Boolean} params.source - True or false to return the _source field or not, or a list of fields to return
* @param {String or String[] or Boolean} params.sourceExclude - A list of fields to exclude from the returned _source field
* @param {String or String[] or Boolean} params.sourceInclude - A list of fields to extract and return from the _source field
* @param {String or String[] or Boolean} params.stats - Specific 'tag' of the request for logging and statistical purposes
* @param {String, String[], Boolean} params.sort - A comma-separated list of <field>:<direction> pairs
* @param {String, String[], Boolean} params.source - True or false to return the _source field or not, or a list of fields to return
* @param {String, String[], Boolean} params.sourceExclude - A list of fields to exclude from the returned _source field
* @param {String, String[], Boolean} params.sourceInclude - A list of fields to extract and return from the _source field
* @param {String, String[], Boolean} params.stats - Specific 'tag' of the request for logging and statistical purposes
* @param {String} params.suggestField - Specify which field to use for suggestions
* @param {String} [params.suggestMode=missing] - Specify suggest mode
* @param {Number} params.suggestSize - How many suggestions to return in response
* @param {Text} params.suggestText - The source text for which the suggestions should be returned
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Boolean} params.version - Specify whether to return document version as part of a hit
* @param {String or String[] or Boolean} [params.index=_all] - A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices
* @param {String or String[] or Boolean} params.type - A comma-separated list of document types to search; leave empty to perform the operation on all types
* @param {String, String[], Boolean} [params.index=_all] - A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices
* @param {String, String[], Boolean} params.type - A comma-separated list of document types to search; leave empty to perform the operation on all types
*/
api.search = ca({
params: {
@ -3127,7 +3127,7 @@ api.search = ca({
* @param {String} params.preference - Specify the node or shard the operation should be performed on (default: random)
* @param {String} params.routing - Specific routing value
* @param {String} params.source - The URL-encoded request definition (instead of using request body)
* @param {String or String[] or Boolean} params.index - A comma-separated list of index names to restrict the operation; use `_all` or empty string to perform the operation on all indices
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to restrict the operation; use `_all` or empty string to perform the operation on all indices
*/
api.suggest = ca({
params: {
@ -3172,7 +3172,7 @@ api.suggest = ca({
*
* @param {Object} params - An object with parameters used to carry out this action
* @param {String} params.consistency - Explicit write consistency setting for the operation
* @param {String or String[] or Boolean} params.fields - A comma-separated list of fields to return in the response
* @param {String, String[], Boolean} params.fields - A comma-separated list of fields to return in the response
* @param {String} params.lang - The script language (default: mvel)
* @param {String} params.parent - ID of the parent document
* @param {String} params.percolate - Perform percolation during the operation; use specific registered query name, attribute, or wildcard
@ -3180,9 +3180,9 @@ api.suggest = ca({
* @param {String} [params.replication=sync] - Specific replication type
* @param {Number} params.retryOnConflict - Specify how many times should the operation be retried when a conflict occurs (default: 0)
* @param {String} params.routing - Specific routing value
* @param {*} params.script - The URL-encoded script definition (instead of using request body)
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date or Number} params.timestamp - Explicit timestamp for the document
* @param {Anything} params.script - The URL-encoded script definition (instead of using request body)
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.timestamp - Explicit timestamp for the document
* @param {Duration} params.ttl - Expiration time for the document
* @param {Number} params.version - Explicit version number for concurrency control
* @param {String} params.versionType - Specific version type
@ -3281,8 +3281,8 @@ api.update = ca({
* @param {Boolean} params.refresh - Refresh the index after performing the operation
* @param {String} [params.replication=sync] - Specific replication type
* @param {String} params.routing - Specific routing value
* @param {Date or Number} params.timeout - Explicit operation timeout
* @param {Date or Number} params.timestamp - Explicit timestamp for the document
* @param {Date, Number} params.timeout - Explicit operation timeout
* @param {Date, Number} params.timestamp - Explicit timestamp for the document
* @param {Duration} params.ttl - Expiration time for the document
* @param {Number} params.version - Explicit version number for concurrency control
* @param {String} params.versionType - Specific version type

View File

@ -59,7 +59,7 @@ Client.prototype.ping = ca({
url: {
fmt: '/'
},
timeout: 100
requestTimeout: 100
});
Client.prototype.close = function () {

View File

@ -176,12 +176,16 @@ ClientAction.resolveUrl = resolveUrl;
function exec(transport, spec, params, cb) {
var request = {
method: spec.method,
timeout: spec.timeout || 10000
method: spec.method
};
var query = {};
var i;
// pass the timeout from the spec
if (spec.requestTimeout) {
request.requestTimeout = spec.requestTimeout;
}
// verify that we have the body if needed
if (spec.needsBody && !params.body) {
throw new TypeError('A request body is required.');
@ -228,16 +232,16 @@ function exec(transport, spec, params, cb) {
if (params.hasOwnProperty(key) && params[key] != null) {
switch (key) {
case 'body':
request.body = params.body;
request.body = params[key];
break;
case 'ignore':
request.ignore = _.isArray(params.ignore) ? params.ignore : [params.ignore];
request.ignore = _.isArray(params[key]) ? params[key] : [params[key]];
break;
case 'timeout':
request.timeout = params.timeout;
case 'requestTimeout':
request.requestTimeout = params[key];
break;
case 'method':
request.method = _.toUpperString(params.method);
request.method = _.toUpperString(params[key]);
break;
default:
paramSpec = spec.params[key];

View File

@ -2,6 +2,13 @@ module.exports = ConnectionAbstract;
var _ = require('./utils');
var EventEmitter = require('events').EventEmitter;
var Log = require('./log');
var Host = require('./host');
var defaults = {
deadTimeout: 30000,
requestTimeout: 10000
};
/**
* Abstract class used for Connection classes
@ -9,16 +16,19 @@ var EventEmitter = require('events').EventEmitter;
* @constructor
*/
function ConnectionAbstract(host, config) {
config = _.defaults(config || {}, {
deadTimeout: 30000
});
EventEmitter.call(this);
config = _.defaults(config || {}, defaults);
this.deadTimeout = config.deadTimeout;
this.requestTimeout = config.requestTimeout;
this.requestCount = 0;
this.log = config.log || new Log();
if (!host) {
throw new TypeError('Missing host');
} else if (host.makeUrl) {
} else if (host instanceof Host) {
this.host = host;
} else {
throw new TypeError('Invalid host');
@ -35,7 +45,7 @@ _.inherits(ConnectionAbstract, EventEmitter);
* @param [params] {Object} - The parameters for the request
* @param params.path {String} - The path for which you are requesting
* @param params.method {String} - The HTTP method for the request (GET, HEAD, etc.)
* @param params.timeout {Integer} - The amount of time in milliseconds that this request should be allowed to run for.
* @param params.requestTimeout {Integer} - The amount of time in milliseconds that this request should be allowed to run for.
* @param cb {Function} - A callback to be called once with `cb(err, responseBody, responseStatus)`
*/
ConnectionAbstract.prototype.request = function () {
@ -50,7 +60,7 @@ ConnectionAbstract.prototype.ping = function (cb) {
return this.request({
path: '/',
method: 'HEAD',
timeout: 100
requestTimeout: 100
}, cb);
};

View File

@ -21,7 +21,7 @@ AngularConnector.prototype.request = function (params, cb) {
url: this.host.makeUrl(params),
data: params.body,
cache: false,
timeout: params.timeout !== Infinity ? params.timeout : 0
timeout: _.has(params, 'requestTimeout') ? this.requestTimeout : 10000
}).then(function (response) {
cb(null, response.data, response.status);
}, function (err) {

View File

@ -12,15 +12,12 @@ var handles = {
http: require('http'),
https: require('https')
};
var Log = require('../log');
var _ = require('../utils');
var errors = require('../errors');
var qs = require('querystring');
var KeepAliveAgent = require('agentkeepalive');
var ConnectionAbstract = require('../connection');
var log = _.bindKey(process.stdout, 'write');
/**
* Connector used to talk to an elasticsearch node via HTTP
*
@ -29,29 +26,31 @@ var log = _.bindKey(process.stdout, 'write');
* @param {Number} [config.maxSockets=10] - the maximum number of sockets that will be opened to this node
* @param {Number} [config.maxFreeSockets=10] - this maximum number of sockets that can sit idle to this node
* @param {Number} [config.maxKeepAliveTime=300000] - an idle timeout for the connections to this node. If your
* @param {Number} [config.timeout=10000] - an idle timeout for the connections to this node. If your
* maxSockets is much higher than your average concurrent usage, this timeout will cause sockets to close which
* can be interpreted as "bad" behavior for clients.
*/
function HttpConnector(host, config) {
config = _.defaults(config || {}, {
maxSockets: 10,
maxFreeSockets: 10,
maxKeepAliveTime: 3e5 // 5 minutes
});
ConnectionAbstract.call(this, host, config);
this.hand = handles[this.host.protocol];
if (!this.hand) {
throw new TypeError('Invalid protocol "' + this.host.protocol +
'", expected one of ' + _.keys(handles).join(', '));
}
config = _.defaults(config || {}, {
maxSockets: 10,
maxFreeSockets: this.hand.Agent.defaultMaxSockets,
maxKeepAliveTime: 3e5 // 5 minutes
});
this.agent = new KeepAliveAgent({
keepAlive: true,
maxSockets: config.maxSockets,
maxFreeSockets: config.maxFreeSockets || this.hand.Agent.defaultMaxSockets,
maxFreeSockets: config.maxFreeSockets,
keepAliveMsecs: config.keepAliveMsecs
});
this.log = config.log;
if (!_.isObject(this.log)) {
this.log = new Log();
}
}
_.inherits(HttpConnector, ConnectionAbstract);
@ -70,16 +69,13 @@ HttpConnector.prototype.makeReqParams = function (params) {
agent: this.agent
};
var query = this.host.query ? this.host.query : null;
var query = this.host.query ? _.clone(this.host.query) : {};
if (params.query) {
query = _.defaults({},
typeof params.query === 'string' ? qs.parse(params.query) : params.query,
query || {}
);
_.extend(query, typeof params.query === 'string' ? qs.parse(params.query) : params.query);
}
if (query) {
if (_.size(query)) {
reqParams.path = reqParams.path + '?' + qs.stringify(query);
}
@ -92,7 +88,7 @@ HttpConnector.prototype.request = function (params, cb) {
var request;
var response;
var status = 0;
var timeout = params.timeout || this.config.timeout;
var requestTimeout = _.has(params, 'requestTimeout') ? this.requestTimeout : 10000;
var log = this.log;
var reqParams = this.makeReqParams(params);
@ -132,17 +128,23 @@ HttpConnector.prototype.request = function (params, cb) {
request.on('error', cleanUp);
if (timeout !== Infinity) {
if (requestTimeout) {
// timeout for the entire request.
timeoutId = setTimeout(function () {
request.abort();
request.emit('error', new errors.RequestTimeout('Request timed out at ' + timeout + 'ms'));
}, timeout);
request.emit('error', new errors.RequestTimeout('Request timed out at ' + requestTimeout + 'ms'));
}, requestTimeout);
}
request.setNoDelay(true);
request.setSocketKeepAlive(true);
request.chunkedEncoding = false;
request.end(params.body);
if (params.body) {
request.setHeader('Content-Length', params.body.length);
request.end(params.body);
} else {
request.end();
}
this.requestCount++;
};

View File

@ -10,7 +10,21 @@ module.exports = JqueryConnector;
function JqueryConnector() {}
JqueryConnector.prototype.request = function (params, cb) {
jQuery.ajax(params).done(cb);
var ajax = {
data: params.body,
dataType: 'json',
headers: params.headers,
timeout: params.requestTimeout,
done: cb
};
if (params.auth) {
var auths = params.auth.split(':');
ajax.username = auths[0];
ajax.password = auths[1];
}
return jQuery.ajax(ajax);
};

View File

@ -50,10 +50,10 @@ if (!getXhr) {
XhrConnector.prototype.request = function (params, cb) {
var xhr = getXhr();
var timeout = params.timeout ? params.timeout : 10000;
var requestTimeout = _.has(params, 'requestTimeout') ? this.requestTimeout : 10000;
var timeoutId;
var url = this.host.makeUrl(params);
var log = this.config.log;
var log = this.log;
var async = params.async === false ? false : asyncDefault;
if (params.auth) {
@ -71,12 +71,12 @@ XhrConnector.prototype.request = function (params, cb) {
}
};
if (timeout !== Infinity) {
if (requestTimeout) {
timeoutId = setTimeout(function () {
xhr.onreadystatechange = _.noop;
xhr.abort();
cb(new TimeoutError());
}, timeout);
}, requestTimeout);
}
xhr.send(params.body || void 0);

View File

@ -10,18 +10,19 @@ var _ = require('./utils');
var startsWithProtocolRE = /^([a-z]+:)?\/\//;
// simple reference used when formatting as a url
var defaultPort = {
http: 80,
https: 443
};
var urlParseFields = [
'protocol', 'hostname', 'pathname', 'port', 'auth', 'query'
];
var simplify = ['host', 'path'];
// simple reference used when formatting as a url
// and defines when parsing from a string
Host.defaultPorts = {
http: 80,
https: 443
};
function Host(config) {
config = config || {};
@ -38,6 +39,17 @@ function Host(config) {
config = 'http://' + config;
}
config = _.pick(url.parse(config, false, true), urlParseFields);
// default logic for the port is to use 9200 for the default. When a string is specified though,
// we will use the default from the protocol of the string.
if (!config.port) {
var proto = config.protocol || 'http';
if (proto.charAt(proto.length - 1) === ':') {
proto = proto.substring(0, proto.length - 1);
}
if (Host.defaultPorts[proto]) {
config.port = Host.defaultPorts[proto];
}
}
}
if (_.isObject(config)) {
@ -68,15 +80,16 @@ function Host(config) {
}
// make sure that the port is a number
if (typeof this.port !== 'number') {
if (_.isNumeric(this.port)) {
this.port = parseInt(this.port, 10);
if (isNaN(this.port)) {
this.port = 9200;
}
} else {
this.port = 9200;
}
// make sure the path starts with a leading slash
if (this.path && this.path.charAt(0) !== '/') {
if (this.path === '/') {
this.path = '';
} else if (this.path && this.path.charAt(0) !== '/') {
this.path = '/' + (this.path || '');
}
@ -90,7 +103,7 @@ Host.prototype.makeUrl = function (params) {
params = params || {};
// build the port
var port = '';
if (this.port !== defaultPort[this.protocol]) {
if (this.port !== Host.defaultPorts[this.protocol]) {
// add an actual port
port = ':' + this.port;
}

View File

@ -143,8 +143,8 @@ LoggerAbstract.prototype.onDebug = _.handler(function (msg) {
* @param {String} msg - The message to be logged
* @return {undefined}
*/
LoggerAbstract.prototype.onTrace = _.handler(function (message) {
this.write('TRACE', message);
LoggerAbstract.prototype.onTrace = _.handler(function (message, curlCall) {
this.write('TRACE', message + '\n' + curlCall);
});

20
src/lib/nodes_to_host.js Normal file
View File

@ -0,0 +1,20 @@
var _ = require('./utils');
var extractHostPartsRE = /\[([^:]+):(\d+)\]/;
module.exports = function (nodes) {
var hosts = [];
_.each(nodes, function (node, id) {
var hostnameMatches = extractHostPartsRE.exec(node.http_address);
hosts.push({
host: hostnameMatches[1],
port: hostnameMatches[2],
_meta: {
id: id,
name: node.name,
hostname: node.hostname,
version: node.version
}
});
});
return hosts;
};

View File

@ -66,6 +66,10 @@ Transport.logs = {
main: require('./log')
};
Transport.nodesToHostCallbacks = {
main: require('./nodes_to_host')
};
/**
* Perform a request with the client's transport
*
@ -100,7 +104,7 @@ Transport.prototype.request = function (params, cb) {
}
params.req = {
timeout: params.timeout,
requestTimeout: params.requestTimeout,
method: params.method,
path: params.path,
query: params.query,

0
test/fixtures/large_response.json vendored Normal file
View File

View File

@ -79,7 +79,6 @@ describe('Client Action runner', function () {
(function () {
action({}, function () {});
}).should.throw('proxy function called');
});
it('provides the proper context', function (done) {
@ -630,34 +629,34 @@ describe('Client Action runner', function () {
});
});
describe('passing of timeout', function () {
it('passes the timeout', function (done) {
describe('passing requestTimeout', function () {
it('passes passes the spec value by default', function (done) {
var action = makeClientAction({
timeout: 100
requestTimeout: 100
});
action({}, function (err, params) {
params.timeout.should.be.exactly(100);
params.requestTimeout.should.be.exactly(100);
done();
});
});
it('passes the provided value for timeout', function (done) {
it('passes the provided value', function (done) {
var action = makeClientAction({
timeout: 100
requestTimeout: 100
});
action({ timeout: 3000 }, function (err, params) {
params.timeout.should.be.exactly(3000);
action({ requestTimeout: 3000 }, function (err, params) {
params.requestTimeout.should.be.exactly(3000);
done();
});
});
it('uses 10000 as the default timeout', function (done) {
it('passes nothing be default', function (done) {
var action = makeClientAction({});
action({}, function (err, params) {
params.timeout.should.be.exactly(10000);
should(params.requestTimeout).be.exactly(void 0);
done();
});
});
@ -787,7 +786,7 @@ describe('Client Action runner', function () {
b: '3w',
q: 'beep',
body: '{ "mmm": "json" }',
timeout: 1000,
requestTimeout: 1000,
method: 'head',
ignore: 201
},

View File

@ -10,7 +10,7 @@ describe('Host class', function () {
protocol: 'http',
host: 'localhost',
port: 9200,
path: '/',
path: '',
auth: null,
query: {}
});
@ -31,18 +31,35 @@ describe('Host class', function () {
host.headers.should.be.exactly(headers);
});
it('accepts a string for the entire url', function () {
var host = new Host('john:dude@pizza.com:420/pizza/cheese?shrooms=true');
describe('from a string', function () {
it('accepts a string for the entire url', function () {
var host = new Host('john:dude@pizza.com:420/pizza/cheese?shrooms=true');
host.should.eql({
protocol: 'http',
host: 'pizza.com',
port: 420,
path: '/pizza/cheese',
auth: 'john:dude',
query: {
shrooms: 'true'
}
host.should.eql({
protocol: 'http',
host: 'pizza.com',
port: 420,
path: '/pizza/cheese',
auth: 'john:dude',
query: {
shrooms: 'true'
}
});
});
it('uses the default port based on the protocol', function () {
var host;
host = new Host('https://google.com');
host.port.should.eql(443);
host = new Host('http://google.com');
host.port.should.eql(80);
Host.defaultPorts.trift = 9300;
host = new Host('thrift://google.com');
host.port.should.eql(9200);
delete Host.defaultPorts.trift;
});
});
@ -85,7 +102,7 @@ describe('Host class', function () {
protocol: 'http',
host: 'localhost',
port: 9200,
path: '/',
path: '',
auth: null,
query: {}
});
@ -123,12 +140,21 @@ describe('Host class', function () {
host.makeUrl({ path: '/this and that'})
.should.eql('http://localhost:9200/prefix//this and that');
});
});
describe('#toString', function () {
it('just calls makeUrl with no parameters', function () {
it('creates proper url without any params', function () {
var host = new Host({});
host.makeUrl().should.eql('http://localhost:9200/');
host = new Host({ host: 'john', port: 80 });
host.makeUrl().should.eql('http://john/');
host = new Host({ host: 'italy', path: '/pie' });
host.makeUrl().should.eql('http://italy:9200/pie');
});
});
describe('#toString', function () {
// just calls makeUrl without any params
});
});

View File

@ -1,58 +0,0 @@
describe('Http Connector', function () {
var Host = require('../../src/lib/host');
var HttpConnection = require('../../src/lib/connectors/http');
describe('#makeReqParams', function () {
it('properly reads the host object', function () {
var host = new Host('john:dude@pizza.com:9200/pizza/cheese?shrooms=true');
var con = new HttpConnection(host, {});
var reqParams = con.makeReqParams();
reqParams.should.eql({
method: 'GET',
protocol: 'http:',
auth: 'john:dude',
hostname: 'pizza.com',
port: 9200,
path: '/pizza/cheese?shrooms=true',
headers: host.headers,
agent: con.agent
});
});
it('accepts merges a query object with the hosts\'', function () {
var con = new HttpConnection(new Host({
query: {
user_id: 123
}
}));
var reqParams = con.makeReqParams({
query: {
jvm: 'yes'
}
});
reqParams.should.include({
path: '/?jvm=yes&user_id=123'
});
});
// it('works with an empty query', function () {
// var reqParams = con.makeReqParams();
// reqParams.should.include({
// method: 'GET',
// path: '/'
// });
// Object.keys(reqParams).should.not.include([
// 'host', 'pathname', 'query'
// ]);
// });
});
});

View File

@ -0,0 +1,306 @@
describe('Http Connector', function () {
var should = require('should');
var Host = require('../../src/lib/host');
var HttpConnection = require('../../src/lib/connectors/http');
var ConnectionAbstract = require('../../src/lib/connection');
describe('Constructor', function () {
it('creates an object that extends ConnectionAbstract', function () {
var con = new HttpConnection(new Host());
con.should.be.an.instanceOf(ConnectionAbstract);
});
it('sets certain defaults', function () {
var con = new HttpConnection(new Host());
con.hand.should.be.exactly(require('http'));
// con.requestTimeout
// maxSockets
// maxFreeSockets
// maxKeepAliveTime
// requestTimeout
});
it('expects one the host to have a protocol of http or https', function () {
(function () {
var con = new HttpConnection(new Host('thrifty://es.com/stuff'));
}).should.throw(/invalid protocol/i);
});
});
describe('#makeReqParams', function () {
it('properly reads the host object', function () {
var host = new Host('john:dude@pizza.com:9200/pizza/cheese?shrooms=true');
var con = new HttpConnection(host, {});
var reqParams = con.makeReqParams();
reqParams.should.eql({
method: 'GET',
protocol: 'http:',
auth: 'john:dude',
hostname: 'pizza.com',
port: 9200,
path: '/pizza/cheese?shrooms=true',
headers: host.headers,
agent: con.agent
});
});
it('merges a query object with the hosts\'', function () {
var con = new HttpConnection(new Host({
query: {
user_id: 123
}
}));
var reqParams = con.makeReqParams({
query: {
jvm: 'yes'
}
});
reqParams.should.include({
path: '?user_id=123&jvm=yes'
});
});
it('merges the path prefex', function () {
var con = new HttpConnection(new Host('https://google.com/path/prefix/for/user/1'));
var reqParams = con.makeReqParams({
method: 'GET',
path: '/items',
query: {
q: 'pizza'
}
});
reqParams.should.eql({
method: 'GET',
protocol: 'https:',
auth: null,
hostname: 'google.com',
port: 443,
path: '/path/prefix/for/user/1/items?q=pizza',
headers: undefined,
agent: con.agent
});
});
it('merges the query', function () {
var con = new HttpConnection(new Host('http://google.com/pref-x?userId=12345&token=42069'));
var reqParams = con.makeReqParams({
method: 'PUT',
path: '/stuff',
query: {
q: 'pizza'
}
});
reqParams.should.eql({
method: 'PUT',
protocol: 'http:',
auth: null,
hostname: 'google.com',
port: 80,
path: '/pref-x/stuff?userId=12345&token=42069&q=pizza',
headers: undefined,
agent: con.agent
});
});
it('Works well with minimum params', function () {
var con = new HttpConnection(new Host('http://google.com'));
var reqParams = con.makeReqParams({
method: 'PUT',
path: '/stuff'
});
reqParams.should.eql({
method: 'PUT',
protocol: 'http:',
auth: null,
hostname: 'google.com',
port: 80,
path: '/stuff',
headers: undefined,
agent: con.agent
});
});
});
describe('#request', function () {
var http = require('http');
var https = require('https');
var sinon = require('sinon');
var util = require('util');
function FakeRequest() {
sinon.stub(this, 'end');
sinon.stub(this, 'write');
this.log = sinon.stub(this.log);
}
util.inherits(FakeRequest, http.ClientRequest);
function reqMethodStub(params, cb) {
var req = new FakeRequest();
process.nextTick(function () {
// causes the request to quit and callback
req.emit('error');
});
return req;
}
beforeEach(function () {
sinon.stub(http, 'request', reqMethodStub);
sinon.stub(https, 'request', reqMethodStub);
});
afterEach(function () {
http.request.restore();
https.request.restore();
});
it('calls http based on the host', function (done) {
var con = new HttpConnection(new Host('http://google.com'));
con.request({}, function () {
http.request.callCount.should.eql(1);
https.request.callCount.should.eql(0);
done();
});
});
it('calls https based on the host', function (done) {
var con = new HttpConnection(new Host('https://google.com'));
con.request({}, function () {
http.request.callCount.should.eql(0);
https.request.callCount.should.eql(1);
done();
});
});
it('logs error events, and sets the connection to dead when an error occurs', function (done) {
var con = new HttpConnection(new Host('http://google.com'));
sinon.stub(con.log);
http.request.restore();
sinon.stub(http, 'request', function (params, cb) {
var req = new FakeRequest();
process.nextTick(function () {
// causes the request to quit and callback
req.emit('error', new Error('actual error'));
});
return req;
});
con.request({}, function (err) {
// error should have been sent to the
err.message.should.eql('actual error');
// logged the error and the trace log
con.log.error.callCount.should.eql(1);
con.log.trace.callCount.should.eql(1);
con.log.info.callCount.should.eql(0);
con.log.warning.callCount.should.eql(0);
con.log.debug.callCount.should.eql(0);
// set status to dead
con.status.should.eql('dead');
done();
});
});
it('logs error events, and sets the connection to dead', function (done) {
var con = new HttpConnection(new Host('http://google.com'));
sinon.stub(con.log);
http.request.restore();
sinon.stub(http, 'request', function (params, cb) {
var req = new FakeRequest();
process.nextTick(function () {
// causes the request to quit and callback
req.emit('error', new Error('actual error'));
});
return req;
});
con.request({}, function (err) {
// error should have been sent to the
err.message.should.eql('actual error');
// logged the error
con.log.error.callCount.should.eql(1);
con.log.error.lastCall.args[0].message.should.eql('actual error');
// set status to dead
con.status.should.eql('dead');
done();
});
});
});
describe('Request Implementation', function () {
var server;
var nock = require('nock');
nock.disableNetConnect();
var host = new Host('http://esjs.com:9200');
beforeEach(function () {
server = nock('http://esjs.com:9200');
});
afterEach(function () {
server.done();
nock.restore();
});
it('collects the whole request body', function (done) {
var con = new HttpConnection(host);
var body = '{ "USER": "doc" }';
server
.get('/users/1')
.reply(200, body);
con.request({
method: 'GET',
path: '/users/1'
}, function (err, resp, status) {
should(err).not.exist;
resp.should.eql(body);
status.should.eql(200);
done();
});
});
it('Catches network errors and passes back the error', function () {
var con = new HttpConnection(host);
var body = '{ "USER": "doc" }';
server
.get('/users/1')
.reply(200, {
});
con.request({
method: 'GET',
path: '/users/1'
}, function (err, resp, status) {
should(err).not.exist;
resp.should.eql(body);
status.should.eql(200);
done();
});
});
});
});