Skip to main content

Results Hits Configuration

Performs a query to Elasticsearch returning documents within the index. Searchkit will transform the response into a friendly API

const skConfig = {
host: 'http://127.0.0.1:9200/', // elasticsearch instance url
index: 'movies', // search indices name
hits: {
fields: ['title', 'plot', 'poster'],
highlightFields: ['title'],
},
};

const response = await Searchkit(config).execute({
hits: {
from: 0,
size: 10,
includeRawHit: true,
},
});

example of response

{
"hits": {
"items": [
{
"fields": {
"title": "title",
"plot": "plot text",
"poster": "http://cdn.url/poster"
},
"highlight": {},
"id": "idofDocument",
"rawHit": { ... } // raw hit from elasticsearch. Returned only if includeRawHit is true
}
// ...9 further items
],
"page": {
"from": 0,
"pageNumber": 0,
"size": 10,
"total": 4162,
"totalPages": 417
}
},
"sortedBy": undefined,
"summary": {
"appliedFilters": [],
"disabledFilters": [],
"query": "",
"sortOptions": [],
"total": 4162
}
}

Options​

OptionDescription
frompage start of the request
sizenumber of hits to return
includeRawHitBoolean. When true, will return the raw elasticsearch document in the response under rawHit