Skip to content

Repository files navigation

Search, made easy

Searchkit is an open source toolkit which helps you build a great search experience with Elasticsearch.

See why use Searchkit

Searchkit to simplify using Elasticsearch for Search:

  • Powerful Browser / Node.js SDK client for Elasticsearch
  • Out-of-the-box React Search State & components
  • Optional Integrations with GraphQL, Node.js REST APIs
  • A great Search experience without needing to be an expert in Elasticsearch

Highlights

Code Sandbox Examples

api-setup-2

Quick Intro to SDK

From a configuration

importSearchkit,{MultiMatchQuery,RefinementSelectFacet,RangeFacet,DateRangeFacet,TermFilter}from'@searchkit/sdk'constsearchkitConfig={host: 'http://127.0.0.1:9200/',// elasticsearch instance urlindex: 'movies',// search indices namehits: {fields: ['title','plot','poster']},query: newMultiMatchQuery({fields: ['plot','title^4'],highlightFields: ["title"]}),sortOptions: [{id: 'relevance',label: 'Relevance',field: '_score'},{id: 'released',label: 'Recent Releases',field: {released: 'desc'}}],filters: [newTermFilter({identifier: "writer",field: "writers",label: "Writers"})],facets: [newRefinementSelectFacet({identifier: 'type',field: 'type.raw',label: 'Type'multipleSelect: true}),newRangeFacet({identifier: 'metascore',field: 'metaScore',label: 'Metascore',range: {min: 0,max: 100,interval: 5}}),newDateRangeFacet({identifier: 'released',field: 'released',label: 'Released'})]}constrequest=Searchkit(config)constresponse=awaitrequest.query("heat").setFilters([{identifier: "metascore",min: 10,max: 90},{identifier: 'writers',value: 'writer1'},{identifier: 'released',dateMin: '2021-01-01T10:10:10.000Z',dateMax: '2022-01-01T10:10:10.000Z'}]).setSortBy("released").execute({facets: true,hits: {size: 10,from: 0}})

Will provide a response like this

{
"hits": {
"items": [
{
"fields": {
"title": "title",
"plot": "plot text",
"poster": "http://cdn.url/poster"
},
"highlight": {},
"id": "1"
}
// ...9 further items
],
"page": {
"from": 0,
"pageNumber": 0,
"size": 10,
"total": 4162,
"totalPages": 417
}
},
"facets": [
{
"display": "ListFacet",
"entries": [
{
"count": 83,
"label": "J.J. Abrams",
},
{
"count": 74,
"label": "Jeffrey Lieber",
},
{
"count": 73,
"label": "Damon Lindelof",
},
{
"count": 53,
"label": "James Manos Jr.",
},
{
"count": 53,
"label": "Jeff Lindsay",
},
],
"identifier": "writers",
"label": "Writers",
"type": "RefinementSelectFacet",
},
{
"display": "ListFacet",
"entries": [
{
"count": 73,
"label": "Naveen Andrews",
},
{
"count": 56,
"label": "Jennifer Carpenter",
},
{
"count": 56,
"label": "Michael C. Hall",
},
{
"count": 53,
"label": "Emilie de Ravin",
},
{
"count": 42,
"label": "Jared Padalecki",
},
],
"identifier": "actors",
"label": "Actors",
"type": "RefinementSelectFacet",
},
],
"sortedBy": "released",
"summary": {
"appliedFilters": [
{
"display": "ListFacet",
"id": "writers_writer1",
"identifier": "writers",
"label": "Writers",
"type": "ValueSelectedFilter",
"value": "writer1",
},
{
"display": "ListFacet",
"id": "actors_actors",
"identifier": "actors",
"label": "Actors",
"type": "ValueSelectedFilter",
"value": "actors",
},
{
"display": "RangeFacet",
"id": "actors_actors",
"identifier": "metascore",
"label": "Metascore",
"type": "ValueSelectedFilter",
"min": "10",
"max": "90"
},
],
"disabledFilters": [],
"query": "heat",
"sortOptions": [{
"id": "relevance",
"label": "Relevance",
},
{
"id": "released",
"label": "Recent Releases",
},
{
"id": "title-released",
"label": "Recent Titles",
},
],
"total": 4162
}
}

React Integration

We provide a thin React client which integrates with Searchkit's SDK or Searchkit GraphQL API. It maintains search state (pagination, filtering and querying) and provides SearchState via a hook.

React Components

import{FacetsList,SearchBar,Pagination,ResetSearchButton,SelectedFilters}from'@searchkit/elastic-ui'import{useSearchkitSDK}from'@searchkit/sdk/lib/esm/react-hooks'import{useSearchkitVariables}from'@searchkit/client'constPage=()=>{constvariables=useSearchkitVariables()const{ data, loading }=useSearchkitSDK(config,variables)constFacets=FacetsList([])return(<EuiPage><EuiPageSideBar><SearchBarloading={loading}/><EuiHorizontalRulemargin="m"/><Facetsdata={data?.results}loading={loading}/></EuiPageSideBar><EuiPageBodycomponent="div"><EuiPageHeader><EuiPageHeaderSection><EuiTitlesize="l"><SelectedFiltersdata={data?.results}loading={loading}/></EuiTitle></EuiPageHeaderSection><EuiPageHeaderSection><ResetSearchButtonloading={loading}/></EuiPageHeaderSection></EuiPageHeader><EuiPageContent><EuiPageContentHeader><EuiPageContentHeaderSection><EuiTitlesize="s"><h2>{data?.results.summary.total} Results</h2></EuiTitle></EuiPageContentHeaderSection></EuiPageContentHeader><EuiPageContentBody><HitsListdata={data}/><EuiFlexGroupjustifyContent="spaceAround"><Paginationdata={data?.results}/></EuiFlexGroup></EuiPageContentBody></EuiPageContent></EuiPageBody></EuiPage>)}

See quickstart guide

NPM Packages

Sponsors

QBOX Elasticsearch hosting. They have kindly provided us an elasticsearch instance for our demo site.

FAQ

Can I upgrade from Searchkit v2?

Searchkit has undergone a total rewrite so whilst it should be straightforward to move onto, any code written for searchkit legacy wouldn't work on Searchkit v3.

Do I need to expose my Elasticsearch instance to the browser?

No! You dont expose your elasticsearch cluster to the browser, you can use the Search GraphQL API that sits in between elasticsearch and the browser.

Do I need to run a Node.js Server?

No! You can use the searchkit/sdk within the browser too.

About

Node.js & Browser SDK & React UI components for Elasticsearch.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages