async function testSearch () { const result = await client.search({ index, type, body: { query: { match: { 'Title': 'Hound' } } } }) console.log('testSearch', result) }
test('client.search with abort', function userLandCode (t) { resetAgent(3, done(t, 'POST', '/_search', '{"q":"pants"}', true)) agent.startTransaction('foo') var client = new elasticsearch.Client({ host: host }) var query = { q: 'pants' } var req = client.search(query) setImmediate(() => { req.abort() agent.endTransaction() agent.flush() }) })
app.get('/openAt/:hh-:mm-:midi/:page', function (req, response) { esC.search({index: 'restaurants', body: constructBody(req.params.hh, req.params.mm, req.params.midi, req.params.page * 10)}, function(err, res, stat) { if(err) response.send("Error while searching: " + err) else { if(req.params.page * 10 > res.hits.total) return response.send(`Only ${Math.ceil(res.hits.total / 10)} pages exist for this query.`) endpoint = (req.params.page * 10 + 10) <= res.hits.total ? (req.params.page * 10 + 10) : res.hits.total out = `Showing ${req.params.page * 10} to ${endpoint} out of ${res.hits.total} restaurants open at ${req.params.hh}:${req.params.mm} ${req.params.midi}: <br><br>` res.hits.hits.forEach((hit, index) => out += `${hit._source.name_en} <br>`) response.send(out) } }) })
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 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}`); } }
async search(index, type, body) { return await this.client .search({ index: index, type: (this.env.ES_MAJOR > 5) ? 'doc' : type, body: body }); }
test('client.search with callback', function userLandCode (t) { resetAgent(done(t, 'POST', '/_search', '{"q":"pants"}')) agent.startTransaction('foo') var client = new elasticsearch.Client({ host: host }) var query = { q: 'pants' } client.search(query, function (err) { t.error(err) agent.endTransaction() agent.flush() }) })
getLastInfohashes(min, max, callback) { this.client.search({ index: "torrent", body: { _source: false, from: min, size: max - min + 1, sort: [{ "ID": { "order": "asc" } }] } }, function (error, response) { if (error) { console.log("error GetLastInfohashes"); } else { callback(this._decodeGetLastInfohashes(response)); } }.bind(this)); }
function search(ind, ty, text) { return client.search({ index: ind, type: ty, scroll: '10s', body: { query: { match: { productname: text } }, } }) }
async filterItemsBySiteId(siteId, indexName, fullDoc) { return await this.client.search({ index: indexName, body: { "_source": fullDoc ? true : "_id", "query": { "constant_score": { "filter": { "term": { siteId } } } } } }) }
const searchDoc = async function(indexName, mappingType, payload){ return await esClient.search({ index: indexName, type: mappingType, body: payload }); }
const searchDoc = async function(indexName, mappingType, payload){ return await esClient.search({ index: indexName, type: mappingType, body: payload }); }
function getAll(ind, ty) { return client.search({ index: ind, type: ty, scroll: '10s', body: { query: { match_all : {} }, } }) }
const searchDoc = async function(indexName, mappingType, payload){ return await esClient.search({ index: indexName, type: mappingType, body: payload }); }
/** Query ES index for the provided term */ queryTerm (term, offset = 0) { const body = { from: offset, query: { multi_match: { "type": "best_fields", "query": term, "lenient": true } }, highlight: { fields: {"*": {}}, "pre_tags": ["<em>"], "post_tags": ["</em>"], } }; return client.search({ index, type, body }) }