async getExistingDoc(collection, id) { try { const doc = await this.esClient.search({ index: collection.index, type: collection.type, q: `_id:${id}`, size: 1, version: Boolean(collection.versionType), }); return { parentId: doc.hits.hits[0]._parent || null, version: doc.hits.hits[0]._version || null, } } catch(err) { logger.error(`cannot find item of type ${collection.type} with id ${id}`); } }
function GetAllTodos(req, res) { var start = monitor(); client.search({ index:'todo', type: 'todo', q: '*', _sourceInclude: 'todo_id, todo, completed, tags, author, completeddate, duedate' }, function(error, response){ if(error){ res.end(JSON.stringify(error)); } else { var results = []; results = response.hits.hits.map(function(hit){ return hit._source }); res.header('Content-Type', 'application/json'); res.end(JSON.stringify(results)); monitor(start, 'GetAllTodos'); } }); }
async function testSearch2 () { const result = await client.search({ index, type, body: { query: { match: { 'Text': 'opium den sherlock' } }, highlight: { fields: { Text: {} } } } }) console.log('testSearch2', result) for (let hit of result.hits.hits) { console.log(hit._source.Text) console.log(hit.highlight.Text) } }
function testSearchAll() { ESClient.search({ index: "imdb", body: { size: 10, from: 0, query: { match_all: {} } } }) .then(results => { console.log("|Test SearchAll|"); console.log("-----------------------------------"); console.log("Response Body: "); console.log(results); console.log(`found ${results.hits.total} items in ${results.took}ms`); console.log("returned 10 imdb titles:"); results.hits.hits.forEach((hit, index) => console.log(`\t${index} - ${hit._source.title}`) ); }) .catch(console.error); }
body: query }).then(function(body) { if (body.hits.hits.length === 0) { return res.badRequest({error: 'Nothing Found'}); 'count': body.hits.hits.length, 'total_edits': body.aggregations.totalChanges.value, 'total_contributors': body.aggregations.userTotal.buckets.length, 'total_results': body.hits.total, 'next_results': '?' + underscore(params) .map(function(val, key) { for (var i = 0; i < body.hits.hits.length; i++) { var es_results = body.hits.hits[i]._source; for (var j = 0; j < sails.config.osm.fields_to_remove.length; j++) { delete es_results[sails.config.osm.fields_to_remove[j]];