1 # Angular Elasticsearch Query Builder
3 [![NPM version][npm-image]][npm-url]
4 ![Bower version][bower-image]
5 [![Downloads][downloads-image]][downloads-url]
6 [![Tips][gratipay-image]][gratipay-url]
8 This is an Angular.js directive for building an [Elasticsearch](https://www.elastic.co/) query.
9 You just give it the fields and can generate a query for it. Its layout is defined using [Bootstrap](http://getbootstrap.com/) classes, but you may also choose to just style it yourself.
11 It's still pretty early on, as it doesn't support a whole lot of use-cases, but we need to make it awesome. Contributions accepted.
14 [View an example here](http://dncrews.com/angular-elastic-builder/examples/)
19 Notice: this plugin requires the [Angular Recursion](https://github.com/marklagendijk/angular-recursion) module.
22 First you'll need to download the [dist](https://github.com/dncrews/angular-elastic-builder/tree/master/dist) files and include this JS file to your app (don't forget to substitute `x.x.x` with the current version number), along with the RecursionHelper, if you're not already using it.
24 <script type="text/javascript" src="/angular-recursion.min.js"></script>
25 <script type="text/javascript" src="/angular-elastic-builder.min.js"></script>
28 Then make sure that it's included in your app's dependencies during module creation.
31 angularmodule('appName', [ 'angular-elastic-builder' ]);
34 Then you can use it in your app
39 * The elasticBuilderData object will be modified in place so that you can use
40 * your own $watch, and/or your own saving mechanism
42 $scope.elasticBuilderData = {};
43 $scope.elasticBuilderData.query = [];
46 * This object is the lookup for what fields
47 * are available in your database, as well as definitions of what kind
50 $scope.elasticBuilderData.fields = {
51 'some.number.field': { type: 'number' },
52 'some.term.field': { type: 'term' },
53 'some.boolean.field': { type: 'term', subType: 'boolean' },
54 'multi.selector': { type: 'multi', choices: [ 'AZ', 'CA', 'CT' ]}
59 <div data-elastic-builder="elasticBuilderData"></div>
62 The above elasticFields would allow you create the following form:
63 ![Screenshot][screenshot-image]
65 Which represents the following Elasticsearch Query:
78 "some.boolean.field": "0"
85 "some.term.field": "Hello World"
94 "some.number.field": {
101 "some.number.field": {
113 - `type`: This determines how the fields are displayed in the form.
114 - Currently supported:
115 - `'number'`: in addition to Generic Options, gets ">", "≥", "<", "≤", "="
116 - `'term'`: in addition to Generic Options, gets "Equals" and "! Equals"
117 - `'boolean'`: Does not get Generic Options. Gets `true` and `false`
118 - These are actually "equals 0" and "equals 1" for the database query
121 - In addition to any specific options for fields, all fields also get a "Exists" and "! Exists" option
124 ## External Changes && Initial State
125 If you want to pass in an initial state (or if you make changes to the query externally), you'll need to
126 set the configuration flag `needsUpdate` to `true`. Any time this flag changes to `true`, this directive
127 will overwrite the current state and data with whatever is now defined in your configuration object.
131 To work on this module locally, you will need to clone it and run `gulp watch`. This will ensure that your changes get compiled properly. You will also need to make sure you run `gulp` to build the "dist" files before commit.
134 [npm-image]: https://img.shields.io/npm/v/angular-elastic-builder.svg
135 [npm-url]: https://www.npmjs.org/package/angular-elastic-builder
136 [bower-image]: https://img.shields.io/bower/v/angular-elastic-builder.svg
137 [downloads-image]: https://img.shields.io/npm/dm/angular-elastic-builder.svg
138 [downloads-url]: https://www.npmjs.org/package/angular-elastic-builder
139 [gratipay-image]: https://img.shields.io/gratipay/dncrews.svg
140 [gratipay-url]: https://www.gratipay.com/dncrews/
141 [screenshot-image]: https://raw.githubusercontent.com/dncrews/angular-elastic-builder/master/screenshot.png