
Security News
CISA Kills Off RSS Feeds for KEVs and Cyber Alerts
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
angular-elastic-builder-tienvx
Advanced tools
Angular Module for building an Elasticsearch Query
This is an Angular.js directive for building an Elasticsearch query. You just give it the fields and can generate a query for it. Its layout is defined using Bootstrap classes, but you may also choose to just style it yourself.
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.
Notice: this plugin requires:
Install angular elastic builder along with its dependencies.
bower install angular-elastic-builder-tienvx -S
Includes js and css files into your app.
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="bower_components/angular-bootstrap-datetimepicker/src/css/datetimepicker.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="bower_components/angular-elastic-builder-tienvx/angular-elastic-builder.css">
<script type="text/javascript" src="bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="bower_components/moment/moment.js"></script>
<script type="text/javascript" src="bower_components/angular/angular.min.js"></script>
<script type="text/javascript" src="bower_components/angular-bootstrap-datetimepicker/src/js/datetimepicker.js"></script>
<script type="text/javascript" src="bower_components/angular-bootstrap-datetimepicker/src/js/datetimepicker.templates.js"></script>
<script type="text/javascript" src="bower_components/angular-recursion/angular-recursion.min.js"></script>
<script type="text/javascript" src="bower_components/angular-date-time-input/src/dateTimeInput.js"></script>
<script type="text/javascript" src="bower_components/angularjs-dropdown-multiselect/src/angularjs-dropdown-multiselect.js"></script>
<script type="text/javascript" src="bower_components/angular-elastic-builder-tienvx/angular-elastic-builder.js"></script>
Then make sure that it's included in your app's dependencies during module creation.
angularmodule('appName', [ 'angular-elastic-builder' ]);
Then you can use it in your app
/* Controller code */
/**
* The elasticBuilderData object will be modified in place so that you can use
* your own $watch, and/or your own saving mechanism
*/
$scope.elasticBuilderData = {};
$scope.elasticBuilderData.query = [];
/**
* This object is the lookup for what fields
* are available in your database, as well as definitions of what kind
* of data they are
*/
$scope.elasticBuilderData.fields = {
'test.number': { field: 'age', title: 'Age', type: 'number', minimum: 18 },
'test.term': { field: 'first_name', title: 'First Name', type: 'term' },
'test.boolean': { field: 'status', title: 'Status', type: 'boolean' },
'test.multi': { field: 'state', title: 'State', type: 'multi', choices: [ {id: 'AZ', label: 'Arizona'}, {id: 'CA', label: 'California'}, {id: 'CT', label: 'Connecticut'} ]},
'test.contains': { field: 'name', title: 'Name', type: 'contains'},
'test.date': { field: 'dob', title: 'DOB', type: 'date' },
'test.date2': { field: 'registration_date', title: 'Registration Date', type: 'date' },
'test.match': { field: 'about', title: 'About', type: 'match' },
'test.select': { field: 'gender', title: 'Gender', type: 'select', choices: [ {id: 'male', label: 'Male'}, {id: 'female', label: 'Female'}, {id: 'other', label: 'Other'} ] },
'test.parent.term': { field: 'name', parent: 'company', title: 'Company Name', type: 'term' }
};
To use contains field, your mapping should be:
"name": {
"type": "keyword",
"fields": {
"analyzed": {
"type": "text"
}
}
},
<div data-elastic-builder="elasticBuilderData"></div>
The above elasticFields would allow you create the following form:
Which represents the following Elasticsearch Query:
{
"size": 0,
"bool": {
"must": [
{
"bool": {
"must": [
{
"term": {
"dob": "2016-04-08T16:16:48+0700"
}
},
{
"range": {
"age": {
"gte": 21
}
}
},
{
"range": {
"age": {
"lt": 64
}
}
},
{
"match_phrase": {
"name.analyzed": "Andrew"
}
}
]
}
},
{
"term": {
"status": 0
}
},
{
"terms": {
"state": [
"AZ",
"CT"
]
}
},
{
"term": {
"name": "Andrew Barnes"
}
},
{
"bool": {
"must_not": {
"term": {
"first_name": "Andrew"
}
}
}
},
{
"exists": {
"field": "first_name"
}
},
{
"range": {
"registration_date": {
"gte": "now",
"lte": "now+7d"
}
}
},
{
"match": {
"about": "my name is andrew"
}
},
{
"term": {
"gender": "male"
}
},
{
"has_parent": {
"parent_type": "company",
"query": {
"term": {
"name": "GO1"
}
}
}
}
]
}
}
type
: This determines how the fields are displayed in the form.
'number'
: In addition to Generic Options, gets ">", "≥", "<", "≤", "="'term'
: In addition to Generic Options, gets "Equals" and "! Equals"'contains'
: In addition to Generic Options, gets "Equals", "! Equals", "Contains Phrase", "! Contains Phrase"'match'
: In addition to Generic Options, gets "Contains Any Words" and "Contains All Words" and "Contains Phrase"'boolean'
: Does not get Generic Options. Gets true
and false
'multi'
: Does not get Generic Options. Gets options defined in choices. Allowed to select multiple options.'select'
: Does not get Generic Options. Gets options defined in choices. Allowed to select single option.'date'
: In addition to Generic Options, gets ">", "≥", "<", "≤", "="Generic Options
If you want to pass in an initial state (or if you make changes to the query externally), you'll need to
set the configuration flag needsUpdate
to true
. Any time this flag changes to true
, this directive
will overwrite the current state and data with whatever is now defined in your configuration object.
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.
FAQs
Angular Module for building an Elasticsearch Query
We found that angular-elastic-builder-tienvx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.