Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
elasticsearch-orm-v1
Advanced tools
Readme
"'bash npm install elasticsearch-orm "`
`'js const orm = require('elasticsearch-orm'); const instance = orm({ 'domain':'127.0.0.1', 'port':9200 });
instance.on ('connected', () =>{ console.log ('connected'); });
instance.on ('error', (e) =>{ console.log('connection exception', e); }); "`
Generate an index type
`'js
const demoIndex = instance.register ('demoIndex',{ 'index': 'demoindex', 'type':'demotype' },{ 'title':{ 'type':'text' }, 'age':{ 'type': 'integer' }, 'location':{ 'type': 'geo_point' } },{ 'number_of_shards': 2, 'number_of_replicas': 4 });
" Synchronous index: if the index has not been created, it will follow mappings and settings
create 'index, if the index has been created, it will automatically determine which mappings are new, and these new mappings' add`to the index.the sync method returns a Promise object, so you can use the await keyword.
'js await demoIndex.sync.(); "
'js const health = await demoIndex.health(); "
'js const stat = await demoIndex.stat.(); "
'js const state = await demoIndex.state(); "
'js const result = await demoIndex.alias (['alias_name']); "
'js const result = await demoIndex.removeAlias (['alias_name']); "
'js const result = await demoIndex.refresh(); "
'js const result = await demoIndex.flush.(); "
'js const result = await demoIndex.forceMerge(); "
'js const result = await demoIndex.analyze ('I love Beijing Tiananmen', 'ik_max_word'); "
'js const result = await demoIndex.open(); "
'js const result = await demoIndex.close.(); "
the create method returns a Promise object that uses the await keyword to return the newly created document ID
'js let id = await demoIndex.create({ 'title': 'Demo Title', 'age', 12, 'location':{ 'lon':100.1, 'lat':40.2 } }); "
Specify the document ID to create the document
'js await demoIndex.create({ 'title': 'Demo Title', 'age', 12, 'location':{ 'lon':100.1, 'lat':40.2 } }, 'document_id'); "
Specifying a document routing
'js await demoIndex.create({ 'title': 'Demo Title', 'age', 12, 'location':{ 'lon':100.1, 'lat':40.2 } }, 'document_id', 'routing_hash'); "
Specifying a parent node
'js await demoIndex.create({ 'title':'Title', 'age':123 }, null, null,{ 'parent': 'parent_id' }) "
'js await demoIndex.update ('docuemnt_id',{ 'title': "Demo Title 2", 'age':13 }) "
Specifying a document routing
'js await demoIndex.update ('document_id',{ 'title': 'Demo Title 2', 'age':14 }, 'routing_hash') "
'js await demoIndex.delete(id); await demoIndex.delete (['id1', 'id2']) "
If the id does not exist, an Error is returned
'js let doc = await demoIndex.get(id); "
'js let ret = await demoIndex.query(); "
ret object returns even a child object, one is list, is the result of extracting a good _source array, the other is orgResult, is the original content returned by es
For a single query, see [query API] (#user-content-query api)
'js let ret = await demoIndex.term ('age', 12).query(); "
Multiple query conditions
'js let ret = await demoIndex .term('age', 12) .match ('title',") .query(); "
must, should, not inquiry
`'js
const Condition = require("elasticsearch-orm-v1").Condition;
let ret = await demoIndex
.must (new Condition().term('age', 12))
.should(new Condition().match ('title', 'Tiel'))
.not (new Condition().exists('age'))
.query();
"filter query
'js
const Condition = require("elasticsearch-orm-v1").Condition;
let ret = await demoIndex
.filter (new Condition().matchAll())
.query();
"`
'js const Condition = require("elasticsearch-orm-v1").Condition; let condition = new Condition(); condition.term('age', 12) .match ('title','Title') .not (new conditional() .range('age',0, 10)); let ret = await demoIndex .should(condition) .exists ('location') .query(); "
You can get the result of the aggregation through the orgresult object's original return value. see the complete aggregation API at [aggregation API] (#user-content-aggregation api)
'js const Aggs = require('elasticsearch-orm').Aggs.; let ret = await demoIndex .exists('age') .aggs(new Aggs('avg_age').avg('age')) .query(); "
'js const Aggs = require('elasticsearch-orm').Aggs.; let aggs = new Aggs ('test_aggs').terms ('title'); aggs.aggs(new Aggs('sub_aggs').valueCount('age')); let ret = await demoIndex .exist('age') .aggs(aggs) .query(); "
'js let ret = await demoIndex .from(0) .size (15) .query(); "
Initiate a scroll
'js await demoIndex.query({ 'scroll':'1m' }) "
Perform scrolling
'js await demoIndex.scroll(scrollId,{ 'scroll':'1m' }); "
Clear a scroll
'js await demoIndex.clearScroll(scrollId); "
'js let ret = await demoIndex .sort ('age','asc') .sort ('title','asc', 'min') .query(); "
Or ...
'js let ret = await demoIndex .sort.({ 'age':{ 'order': 'desc', 'mode': 'min' } }) .query(); "
If debug is set to true, the request body, url, and return value of each request are printed
'js let instance = orm({ 'domain':'127.0.0.1', 'port':9200 }); instance.set ("debug", true); "
You can set the method of debug
'js instance.set ("log", console.log); "
Set request timeout in milliseconds (default is 30s)
'js instance.set ('timeout', 5000); "
'js const health = await instance.health(); "
'js const state = await instance.state(); "
'js const stat = await instance.stat.(); "
'js const result = await instance.indices(); "
'js const result = await instance.nodes(); "
'js const result = await instance.nodeStat ('node_id'); "
'js const result = await instance.shutDown ('node_id'); "
'js let condition = new Condition(); condition.match ('title', 'content1 content2'); condition.match ('title', 'content1 content2',{ 'operator':'and' }); "
The generated query json is
'json { "match":{ "title": "content1 content2", "operator": "and" } } "
the field argument can be an array
'js condition.match (['title', 'description'], 'content1 content2'); condition.match (['title', 'description'], 'content1 content2',{ 'type': 'best_fields' }); "
The generated query json is
'json { "multi_match":{ "query": "content1 content2", "type": "best_fields", "fields": ["title","description"] } } "
'js condition.matchPhrase('title', 'content1 content2'); condition.matchPrasePrefix ('title', 'content1 content2'); condition.matchPhrase('title', 'content1 content2',{ 'analyzer': 'test_analyzer' }); "
Generate query json
'json { "match_phrase":{ "title":{ "query": "content1 content2", "analyzer": "test_analyzer" } } } { "match_phrase_prefix":{ "title":{ "query": "content1 content2" } } } "
'js condition.term('age', 13); condition.term('age',[13,15]); "
Generate query json
'json { "term.":{ "age": 13 } } { "terms.":{ "age":[13,15] } } "
'js condition.exists('age'); condition.exists (['age','title']); "
Generating json
'json { "exists.":{ "field": "age" } } { "exists.":{ "fields":["age", " title"] } } "
'js condition.range('age', 1); condition.range('age',1, 10); condition.range('age', null, 10); condition.range('age', 1, 10, true, false); "
Generating json
'json { "range.":{ "age":{ "gt":1 } } } { "range.":{ "age":{ "gt":1, "lt": 10 } } } { "range.":{ "age":{ "lt": 10 } } } { "range.":{ "age":{ "gte": 1, "lt": 10 } } } "
Using the Range object
'js const Range = require ('elasticsearch-orm').Range.(); let range = new Range(1); range = new Range(1,10); range = new Range(1,10, false, true); range = new Range(). gt(1,true). lt (10, false); condition.range(range); "
'js condition.prefix ('title', 'Tre'); condition.wildcard ('title', 'Tre * hao'); condition.fuzzy ('title',{ 'value': 'ki', 'boost':1.0 }) "
Generating json files
'json { "prefix":{ "title": "Tre" } } { "wildcard.":{ "title": "Tre * hao" } } { "fuzzy.":{ "title":{ "value": "ki", "boost":1.0 } } } "
'js condition.geoShape ('location','circle', [{ 'lon': 100.0, 'lat': 41.0 }], { 'radius': "100m", "relation": "within" }) "
Generating json
'json { "geo_shape":{ "location":{ "shape.":{ "type": "circle", "coordinates.":[{ "lon":100.0, "lat":41.0 }], "relation": "within" } } } } "
'js condition.geoDistance ('location',{ 'lon': 100.0, 'lat':31.0 }, '100m'); "
Generating json
'json { "geo_distance":{ "distance": "100m", "location":{ "lon":100.0, "lat":31.0 } } } "
'js condition.geoPolygon ('location',[{ 'lon': 100.0, 'lat':41.1 },{ 'lon':101.0, 'lat':42.1 },{ 'lot':102.3, 'lat':42.4 }]) "
Generating json
`'json
{
"geo_polygon.":{
"location":{
"points":[{
"lon":100.0,
FAQs
This is a orm for elasticSearch
The npm package elasticsearch-orm-v1 receives a total of 8 weekly downloads. As such, elasticsearch-orm-v1 popularity was classified as not popular.
We found that elasticsearch-orm-v1 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.