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 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'); } }); }
test('should add documents with random ids', async (t) => { const index = 'load_random_index'; const loader = esFixtures.bootstrap(index, type); const data = [{ name: 'Jotaro', standName: 'Star Platinum' }, { name: 'Jolyne', standName: 'Stone Free' }]; await loader.load(data); // check it was inserted correctly const searchResult = (await loader.client.search({ index: index })).hits.hits; const result1 = searchResult.some(result => result._source.name === 'Jotaro'); const result2 = searchResult.some(result => result._source.name === 'Jolyne'); t.is(searchResult.length, 2); t.true(result1); t.true(result2); });
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); }
const resources = []; hits.forEach((hit) => { const resource = hit._source; resource.mimeType = mime.lookup(resource.uri_path) || 'other'; if (resource.initiatorType === 'xmlhttprequest') {