Skip to content

Commit

Permalink
fix: Rename {bob => esb}
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-suhas committed Jan 8, 2018
1 parent 88fedd1 commit 894d7f8
Show file tree
Hide file tree
Showing 129 changed files with 999 additions and 999 deletions.
74 changes: 37 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ npm install elastic-builder --save
## Usage

```js
const bob = require('elastic-builder'); // the builder
const esb = require('elastic-builder'); // the builder

const requestBody = bob.requestBodySearch()
.query(bob.matchQuery('message', 'this is a test'));
const requestBody = esb.requestBodySearch()
.query(esb.matchQuery('message', 'this is a test'));

// OR

const requestBody = new bob.RequestBodySearch().query(
new bob.MatchQuery('message', 'this is a test')
const requestBody = new esb.RequestBodySearch().query(
new esb.MatchQuery('message', 'this is a test')
);

requestBody.toJSON(); // or print to console - bob.prettyPrint(requestBody)
requestBody.toJSON(); // or print to console - esb.prettyPrint(requestBody)
{
"query": {
"match": {
Expand All @@ -77,8 +77,8 @@ Try it out on the command line using the node REPL:
```
# Start the repl
node ./node_modules/elastic-builder/repl.js
# The builder is available in the context variable bob
elastic-builder > bob.prettyPrint(bob.requestBodySearch().query(bob.matchQuery('message', 'this is a test')));
# The builder is available in the context variable esb
elastic-builder > esb.prettyPrint(esb.requestBodySearch().query(esb.matchQuery('message', 'this is a test')));
```

## Motivation
Expand Down Expand Up @@ -111,7 +111,7 @@ The library has a few helper recipes:
* [Filter query][es-filter-query]

```js
const qry = bob.cookMissingQuery('user');
const qry = esb.cookMissingQuery('user');

qry.toJSON();
{
Expand Down Expand Up @@ -140,15 +140,15 @@ request][create-pull-request] :smile:.
'use strict';

const elasticsearch = require('elasticsearch');
const bob = require('elastic-builder');
const esb = require('elastic-builder');

const client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});

const requestBody = bob.requestBodySearch()
.query(bob.matchQuery('body', 'elasticsearch'));
const requestBody = esb.requestBodySearch()
.query(esb.matchQuery('body', 'elasticsearch'));

client.search({
index: 'twitter',
Expand All @@ -165,10 +165,10 @@ client.search({

```js
// Bool query
const requestBody = bob.requestBodySearch().query(
bob.boolQuery()
.must(bob.matchQuery('last_name', 'smith'))
.filter(bob.rangeQuery('age').gt(30))
const requestBody = esb.requestBodySearch().query(
esb.boolQuery()
.must(esb.matchQuery('last_name', 'smith'))
.filter(esb.rangeQuery('age').gt(30))
);
requestBody.toJSON();
{
Expand All @@ -185,8 +185,8 @@ requestBody.toJSON();
}

// Multi Match Query
const requestBody = bob.requestBodySearch().query(
bob.multiMatchQuery(['title', 'body'], 'Quick brown fox')
const requestBody = esb.requestBodySearch().query(
esb.multiMatchQuery(['title', 'body'], 'Quick brown fox')
.type('best_fields')
.tieBreaker(0.3)
.minimumShouldMatch('30%')
Expand All @@ -203,9 +203,9 @@ requestBody.toJSON();
}

// Aggregation
const requestBody = bob.requestBodySearch()
const requestBody = esb.requestBodySearch()
.size(0)
.agg(bob.termsAggregation('popular_colors', 'color'));
.agg(esb.termsAggregation('popular_colors', 'color'));
requestBody.toJSON();
{
"size": 0,
Expand All @@ -217,12 +217,12 @@ requestBody.toJSON();
}

// Nested Aggregation
const requestBody = bob.requestBodySearch()
const requestBody = esb.requestBodySearch()
.size(0)
.agg(
bob.termsAggregation('colors', 'color')
.agg(bob.avgAggregation('avg_price', 'price'))
.agg(bob.termsAggregation('make', 'make'))
esb.termsAggregation('colors', 'color')
.agg(esb.avgAggregation('avg_price', 'price'))
.agg(esb.termsAggregation('make', 'make'))
);
requestBody.toJSON();
{
Expand All @@ -243,11 +243,11 @@ requestBody.toJSON();
}

// If you prefer using the `new` keyword
const agg = new bob.TermsAggregation('countries', 'artist.country')
const agg = new esb.TermsAggregation('countries', 'artist.country')
.order('rock>playback_stats.avg', 'desc')
.agg(
new bob.FilterAggregation('rock', new bob.TermQuery('genre', 'rock')).agg(
new bob.StatsAggregation('playback_stats', 'play_count')
new esb.FilterAggregation('rock', new esb.TermQuery('genre', 'rock')).agg(
new esb.StatsAggregation('playback_stats', 'play_count')
)
)
.toJSON();
Expand All @@ -274,16 +274,16 @@ agg.toJSON();
}

// Sort
const requestBody = bob.requestBodySearch()
.query(bob.boolQuery().filter(bob.termQuery('message', 'test')))
.sort(bob.sort('timestamp', 'desc'))
const requestBody = esb.requestBodySearch()
.query(esb.boolQuery().filter(esb.termQuery('message', 'test')))
.sort(esb.sort('timestamp', 'desc'))
.sorts([
bob.sort('channel', 'desc'),
bob.sort('categories', 'desc'),
esb.sort('channel', 'desc'),
esb.sort('categories', 'desc'),
// The order defaults to desc when sorting on the _score,
// and defaults to asc when sorting on anything else.
bob.sort('content'),
bob.sort('price').order('desc').mode('avg')
esb.sort('content'),
esb.sort('price').order('desc').mode('avg')
]);
requestBody.toJSON();
{
Expand All @@ -304,8 +304,8 @@ requestBody.toJSON();
}

// From / size
const requestBody = bob.requestBodySearch()
.query(bob.matchAllQuery())
const requestBody = esb.requestBodySearch()
.query(esb.matchAllQuery())
.size(5)
.from(10);
requestBody.toJSON();
Expand All @@ -324,7 +324,7 @@ For more examples, check out the [reference docs][api-docs].

```
$ node ./node_modules/elastic-builder/repl.js
elastic-builder > bob.multiMatchQuery().field('title').field('body').query('Quick brown fox').type('bwst_fields')
elastic-builder > esb.multiMatchQuery().field('title').field('body').query('Quick brown fox').type('bwst_fields')
See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
Got 'type' - bwst_fields
Error: The 'type' parameter should belong to Set {
Expand Down
12 changes: 6 additions & 6 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ There are two ways to use the classes for constructing queries:

```js
// Import the library
const bob = require('elastic-builder'); // the builder
const esb = require('elastic-builder'); // the builder

// Use `new` keyword for constructor instances of class
const requestBody = new bob.RequestBodySearch()
.query(new bob.MatchQuery('message', 'this is a test'));
const requestBody = new esb.RequestBodySearch()
.query(new esb.MatchQuery('message', 'this is a test'));

// Or use helper methods which construct the object without need for the `new` keyword
const requestBody = bob.requestBodySearch()
.query(bob.matchQuery('message', 'this is a test'));
const requestBody = esb.requestBodySearch()
.query(esb.matchQuery('message', 'this is a test'));

// Build the request body
requestBody.toJSON()
Expand All @@ -43,7 +43,7 @@ requestBody.toJSON()
But this is not required in node env 6 and above. You can directly use the `src` files:

```js
const bob = require('elastic-builder/src');
const esb = require('elastic-builder/src');
```

This module is heavily influenced by [elastic.js](https://github.com/fullscale/elastic.js)(not maintained anymore).
4 changes: 2 additions & 2 deletions repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

const repl = require('repl');

const bob = require('./lib');
const esb = require('./lib');

repl.start('elastic-builder > ').context.bob = bob;
repl.start('elastic-builder > ').context.esb = esb;
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ from `elastic-builder/src`. But now I have added the type definition so that adv

Starting from the base folder `src`, `index.js` simply pulls in all the concrete classes and re-exports
them under the same object so that you can access all queries and aggregations. It also adds
helper methods so that the class, for example `MatchQuery` can be instantiated with `bob.matchQuery()`
helper methods so that the class, for example `MatchQuery` can be instantiated with `esb.matchQuery()`
thereby avoiding the `new` keyword. This means there are 2 ways of doing the same thing. While this is not ideal,
the reason for doing so because the documentation, type definitions declare classes and
it might be confusing to access them using only functions. I am open to rethinking this approach.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const ES_REF_URL =
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-adjacency-matrix-aggregation.html)
*
* @example
* const agg = bob.adjacencyMatrixAggregation('interactions').filters({
* grpA: bob.termsQuery('accounts', ['hillary', 'sidney']),
* grpB: bob.termsQuery('accounts', ['donald', 'mitt']),
* grpC: bob.termsQuery('accounts', ['vladimir', 'nigel'])
* const agg = esb.adjacencyMatrixAggregation('interactions').filters({
* grpA: esb.termsQuery('accounts', ['hillary', 'sidney']),
* grpB: esb.termsQuery('accounts', ['donald', 'mitt']),
* grpC: esb.termsQuery('accounts', ['vladimir', 'nigel'])
* });
*
* @param {string} name The name which will be used to refer to this aggregation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class BucketAggregationBase extends Aggregation {
*
* @example
* // Generating the terms using a script
* const agg = bob.termsAggregation('genres').script(
* bob.script('file', 'my_script').params({ field: 'genre' })
* const agg = esb.termsAggregation('genres').script(
* esb.script('file', 'my_script').params({ field: 'genre' })
* );
*
* @example
* // Value script
* const agg = bob.termsAggregation('genres', 'genre').script(
* bob.script('inline', "'Genre: ' +_value").lang('painless')
* const agg = esb.termsAggregation('genres', 'genre').script(
* esb.script('inline', "'Genre: ' +_value").lang('painless')
* );
*
* @param {Script} script
Expand Down
8 changes: 4 additions & 4 deletions src/aggregations/bucket-aggregations/children-aggregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const ES_REF_URL =
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html)
*
* @example
* const reqBody = bob.requestBodySearch()
* const reqBody = esb.requestBodySearch()
* .agg(
* bob.termsAggregation('top-tags', 'tags.keyword')
* esb.termsAggregation('top-tags', 'tags.keyword')
* .size(10)
* .agg(
* bob.childrenAggregation('to-answers')
* esb.childrenAggregation('to-answers')
* .type('answer')
* .agg(
* bob.termsAggregation(
* esb.termsAggregation(
* 'top-names',
* 'owner.display_name.keyword'
* ).size(10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const HistogramAggregationBase = require('./histogram-aggregation-base');
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html#_scripts)
*
* @example
* const agg = bob.dateHistogramAggregation('sales_over_time', 'date', 'month');
* const agg = esb.dateHistogramAggregation('sales_over_time', 'date', 'month');
*
* @example
* const agg = bob.dateHistogramAggregation(
* const agg = esb.dateHistogramAggregation(
* 'sales_over_time',
* 'date',
* '1M'
Expand All @@ -38,7 +38,7 @@ class DateHistogramAggregation extends HistogramAggregationBase {
* Sets the date time zone
*
* @example
* const agg = bob.dateHistogramAggregation('by_day', 'date', 'day').timeZone(
* const agg = esb.dateHistogramAggregation('by_day', 'date', 'day').timeZone(
* '-01:00'
* );
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const RangeAggregationBase = require('./range-aggregation-base');
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html)
*
* @example
* const agg = bob.dateRangeAggregation('range', 'date')
* const agg = esb.dateRangeAggregation('range', 'date')
* .format('MM-yyy')
* .ranges([{ to: 'now-10M/M' }, { from: 'now-10M/M' }]);
*
Expand All @@ -35,7 +35,7 @@ class DateRangeAggregation extends RangeAggregationBase {
* bucketing should use a different time zone.
*
* @example
* const agg = bob.dateRangeAggregation('range', 'date')
* const agg = esb.dateRangeAggregation('range', 'date')
* .timeZone('CET')
* .ranges([
* { to: '2016/02/01' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ const invalidExecutionHintParam = invalidParam(
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-diversified-sampler-aggregation.html)
*
* @example
* const reqBody = bob.requestBodySearch()
* .query(bob.queryStringQuery('tags:elasticsearch'))
* const reqBody = esb.requestBodySearch()
* .query(esb.queryStringQuery('tags:elasticsearch'))
* .agg(
* bob.diversifiedSamplerAggregation('my_unbiased_sample', 'author')
* esb.diversifiedSamplerAggregation('my_unbiased_sample', 'author')
* .shardSize(200)
* .agg(
* bob.significantTermsAggregation(
* esb.significantTermsAggregation(
* 'keywords',
* 'tags'
* ).exclude(['elasticsearch'])
Expand All @@ -43,15 +43,15 @@ const invalidExecutionHintParam = invalidParam(
* // Use a script to produce a hash of the multiple values in a tags field
* // to ensure we don't have a sample that consists of the same repeated
* // combinations of tags
* const reqBody = bob.requestBodySearch()
* .query(bob.queryStringQuery('tags:kibana'))
* const reqBody = esb.requestBodySearch()
* .query(esb.queryStringQuery('tags:kibana'))
* .agg(
* bob.diversifiedSamplerAggregation('my_unbiased_sample')
* esb.diversifiedSamplerAggregation('my_unbiased_sample')
* .shardSize(200)
* .maxDocsPerValue(3)
* .script(bob.script('inline', "doc['tags'].values.hashCode()"))
* .script(esb.script('inline', "doc['tags'].values.hashCode()"))
* .agg(
* bob.significantTermsAggregation(
* esb.significantTermsAggregation(
* 'keywords',
* 'tags'
* ).exclude(['kibana'])
Expand Down
8 changes: 4 additions & 4 deletions src/aggregations/bucket-aggregations/filter-aggregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const ES_REF_URL =
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html)
*
* @example
* const reqBody = bob.requestBodySearch()
* const reqBody = esb.requestBodySearch()
* .agg(
* bob.filterAggregation(
* esb.filterAggregation(
* 't_shirts',
* bob.termQuery('type', 't-shirt')
* ).agg(bob.avgAggregation('avg_price', 'price'))
* esb.termQuery('type', 't-shirt')
* ).agg(esb.avgAggregation('avg_price', 'price'))
* )
* .size(0);
*
Expand Down
Loading

0 comments on commit 894d7f8

Please sign in to comment.