1.0.19 • Published 9 years ago
itemsapi-node v1.0.19
itemsapi-node
Node.js client for ItemsAPI - node.js & elasticsearch search server for web and mobile. For more low level info go to documentation
$ npm install itemsapi-node --save
Init client:
var ItemsAPI = require('itemsapi-node');
var client = new ItemsAPI('http://yourLocalOrHerokuUrl.com/api/v1', 'cities');
Items
Search items
var facets = {
country:['Canada', 'India']
};
client.search({
sort: 'most_votes',
query: '',
page: 1,
aggs: facets,
per_page: 12
}).then(function(res) {
console.log(res);
//console.log(JSON.stringify(res, null, 2));
})
Example response:
{ meta: { query: '', sort: 'most_votes', search_time: 20 },
pagination: { page: '1', per_page: '12', total: 67 },
data:
{ items:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ],
aggregations: { country: [Object], distance_ranges: [Object] },
sortings: { country: [Object], distance: [Object], city: [Object] }
}
}
Similar items
client.similar('item-id', {
fields: ['tags']
}).then(function(res) {
console.log(res);
})
Get item
client.getItem(id)
.then(function(result) {
console.log(result);
})
Add item
client.addItem(data)
.then(function(result) {
console.log(result);
})
Delete item
client.deleteItem(id)
.then(function(result) {
console.log(result);
})
Add items in bulk
client.addBulkItems(cities)
.then(function(res) {
console.log('added ' + cities.length + 'elements');
})
Collections
Get collection
client.getCollection()
.then(function(result) {
console.log(result);
})
Example response:
{
name: 'cities',
type: 'cities',
index: 'cities',
meta: { title: 'Cities' },
defaults: { sort: 'city' },
schema: {
city: { type: 'string', store: true, index: 'not_analyzed' },
province: { type: 'string', store: true },
province_icon: { type: 'string', display: 'image' },
country: { type: 'string', index: 'not_analyzed', store: true },
country_icon: { type: 'string', display: 'image' },
geo: { type: 'geo_point' }
},
sortings: {
country: {
title: 'Country',
type: 'normal',
order: 'asc',
field: 'country'
},
distance: { title: 'Distance', type: 'geo', order: 'asc', field: 'geo' },
city: { title: 'City', type: 'normal', order: 'asc', field: 'city' }
},
table: {},
aggregations: {
country: { type: 'terms', field: 'country', size: 10, title: 'Country' },
distance_ranges: {
type: 'geo_distance',
field: 'geo',
ranges: [Object],
unit: 'km',
title: 'Distance ranges [km]'
}
}
}
Add collection
client.addCollection(collection)
.then(function(result) {
console.log(result);
})
Get all collections
client.getCollections()
.then(function(result) {
console.log(result);
})
Update collection partially
client.partialUpdateCollection({
index: 'new-index-name',
type: 'new-type-name',
})
.then(function(result) {
console.log(result);
})
1.0.19
9 years ago
1.0.18
9 years ago
1.0.17
9 years ago
1.0.16
9 years ago
1.0.15
9 years ago
1.0.14
9 years ago
1.0.12
9 years ago
1.0.11
9 years ago
1.0.10
9 years ago
1.0.9
9 years ago
1.0.8
9 years ago
1.0.7
10 years ago
1.0.6
10 years ago
1.0.5
10 years ago
1.0.4
10 years ago
1.0.3
10 years ago
1.0.2
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago