searchkit
React + Vue Search UI for Elasticsearch & Opensearch. Compatible with Algolia's Instantsearch and Autocomplete components.
Top Related Projects
Official Elasticsearch client library for Node.js
⚡️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.
Next-Generation full text search library for Browser and Node.js
JS Search is an efficient, client-side search library for JavaScript and JSON objects
Tiny and powerful JavaScript full-text search engine for browser and Node
A bit like Solr, but much smaller and not as bright
Quick Overview
Searchkit is an open-source search UI framework that helps developers build search experiences for their applications. It provides a set of React components and a GraphQL API that can be integrated into any web application to add powerful search functionality.
Pros
- Flexible and Customizable: Searchkit allows developers to easily customize the search UI to match the branding and design of their application.
- Scalable and Performant: Searchkit is built on top of Elasticsearch, which provides a scalable and performant search solution.
- Extensive Documentation: The project has detailed documentation that covers installation, configuration, and usage of the various components.
- Active Community: Searchkit has an active community of contributors and users, which helps ensure the project is well-maintained and supported.
Cons
- Learning Curve: Integrating Searchkit into an existing application may require a significant amount of setup and configuration, which can be challenging for developers who are new to the framework.
- Dependency on Elasticsearch: Searchkit is tightly coupled with Elasticsearch, which means that developers must have a working Elasticsearch cluster in order to use the framework.
- Limited Functionality: While Searchkit provides a lot of functionality out of the box, it may not be suitable for more complex or specialized search use cases.
- Potential Performance Issues: Depending on the size and complexity of the search index, Searchkit may experience performance issues, especially when dealing with large datasets.
Code Examples
Here are a few examples of how to use Searchkit in a React application:
- Rendering a Search Box:
import { SearchBox } from "@searchkit/client";
const SearchPage = () => {
return (
<div>
<SearchBox
placeholder="Search..."
onSearch={(query) => console.log(`Searching for: ${query}`)}
/>
</div>
);
};
- Rendering Search Results:
import { HitsGrid, Hits } from "@searchkit/client";
const SearchPage = () => {
return (
<div>
<HitsGrid>
<Hits
itemComponent={({ result }) => (
<div>
<h3>{result.title}</h3>
<p>{result.description}</p>
</div>
)}
/>
</HitsGrid>
</div>
);
};
- Implementing Faceted Search:
import { FacetsList, Facets } from "@searchkit/client";
const SearchPage = () => {
return (
<div>
<Facets>
<FacetsList>
<FacetsList.Facet
key="category"
title="Category"
field="category.keyword"
/>
<FacetsList.Facet
key="price"
title="Price"
field="price"
type="RangeFacet"
/>
</FacetsList>
</Facets>
</div>
);
};
Getting Started
To get started with Searchkit, follow these steps:
- Install the required packages:
npm install @searchkit/client @searchkit/schema @searchkit/elasticsearch-plugin
- Set up your Elasticsearch cluster and configure the Searchkit schema:
import { SearchkitSchema, SearchkitQueryService } from "@searchkit/schema";
import { ElasticsearchPlugin } from "@searchkit/elasticsearch-plugin";
const schema = new SearchkitSchema({
types: [
{
id: "product",
fields: [
{ id: "title", type: "text" },
{ id: "description", type: "text" },
{ id: "category", type: "keyword" },
{ id: "price", type: "number" },
],
},
],
});
const queryService = new SearchkitQueryService({
host: "http://localhost:9200",
index: "products",
});
const plugin = new ElasticsearchPlugin({
schema,
queryService,
});
Competitor Comparisons
Official Elasticsearch client library for Node.js
Pros of elasticsearch-js
- Official Elasticsearch client library, ensuring compatibility and up-to-date features
- Comprehensive API coverage for all Elasticsearch operations
- Extensive documentation and community support
Cons of elasticsearch-js
- Steeper learning curve for beginners
- Requires more boilerplate code for common search scenarios
- Less abstraction for complex search operations
Code Comparison
elasticsearch-js:
const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })
const result = await client.search({
index: 'my-index',
body: { query: { match: { title: 'search' } } }
})
Searchkit:
import { SearchkitManager } from "searchkit"
const searchkit = new SearchkitManager("http://localhost:9200/")
const results = await searchkit.search({
query: { match: { title: "search" } }
})
Summary
Elasticsearch-js provides a more comprehensive and official solution for interacting with Elasticsearch, offering full API coverage and extensive documentation. However, it may require more setup and code for common search scenarios.
Searchkit, on the other hand, offers a higher-level abstraction and simpler API for building search interfaces, making it easier for developers to implement common search features quickly. It may not cover all Elasticsearch functionalities but provides a more user-friendly approach for typical search use cases.
⚡️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.
Pros of Instantsearch
- More comprehensive UI components and widgets out-of-the-box
- Better documentation and extensive examples
- Larger community and ecosystem support
Cons of Instantsearch
- Tied to Algolia's proprietary search engine
- Steeper learning curve for complex customizations
- Potentially higher costs for large-scale applications
Code Comparison
Searchkit:
import { SearchkitProvider, SearchBox, Hits } from '@searchkit/react'
const App = () => (
<SearchkitProvider>
<SearchBox />
<Hits />
</SearchkitProvider>
)
Instantsearch:
import { InstantSearch, SearchBox, Hits } from 'react-instantsearch-dom'
const App = () => (
<InstantSearch indexName="your_index_name" searchClient={searchClient}>
<SearchBox />
<Hits />
</InstantSearch>
)
Both libraries offer similar basic components, but Instantsearch requires specifying an index name and search client. Searchkit is more flexible in terms of backend integration, while Instantsearch is tightly coupled with Algolia's services.
Instantsearch provides a richer set of pre-built UI components, making it easier to create complex search interfaces quickly. However, this comes at the cost of being locked into Algolia's ecosystem.
Searchkit offers more flexibility in terms of backend integration and customization, but may require more development effort for advanced features. It's better suited for projects that need to work with various search engines or have specific backend requirements.
Next-Generation full text search library for Browser and Node.js
Pros of FlexSearch
- Lightweight and fast full-text search library with zero dependencies
- Supports multiple search modes (fuzzy, prefix, suffix, etc.) and customizable tokenization
- Can be used in both browser and Node.js environments
Cons of FlexSearch
- Limited to in-memory search, not suitable for large-scale or distributed search scenarios
- Lacks advanced features like faceted search or aggregations out of the box
- May require more manual configuration and integration compared to Searchkit
Code Comparison
FlexSearch:
const index = new FlexSearch();
index.add(1, "John Doe");
index.search("John");
Searchkit:
const searchkit = new Searchkit({
connection: { host: 'http://localhost:9200' },
searchOnLoad: true
});
Key Differences
- FlexSearch is a standalone search library, while Searchkit is built on top of Elasticsearch
- Searchkit provides a more comprehensive search solution with UI components and advanced features
- FlexSearch is better suited for smaller datasets and client-side search, while Searchkit excels in large-scale, server-side search applications
Use Cases
- FlexSearch: Client-side search, small to medium-sized datasets, offline-capable applications
- Searchkit: Large-scale search applications, complex querying needs, integration with Elasticsearch
JS Search is an efficient, client-side search library for JavaScript and JSON objects
Pros of js-search
- Lightweight and dependency-free, making it easy to integrate into various projects
- Supports client-side searching, which can be faster for small to medium-sized datasets
- Simple API and straightforward implementation
Cons of js-search
- Limited advanced search features compared to Searchkit's Elasticsearch integration
- May not scale well for large datasets or complex search requirements
- Lacks built-in UI components and React integration
Code Comparison
js-search:
var search = new JsSearch.Search('id');
search.addIndex('title');
search.addIndex('author');
search.addDocuments(books);
var results = search.search('john');
Searchkit:
const searchkit = new SearchkitManager("http://localhost:9200/");
const results = searchkit.search({
query: { match: { title: "john" } },
size: 10
});
Summary
js-search is a lightweight, client-side search library ideal for small to medium-sized datasets and simple search requirements. It offers easy integration and a straightforward API but lacks advanced features and scalability for larger projects.
Searchkit, on the other hand, provides a more robust search solution with Elasticsearch integration, advanced search capabilities, and built-in UI components. It's better suited for larger datasets and complex search requirements but may require more setup and infrastructure.
Choose js-search for simple, client-side search needs, and Searchkit for more advanced, scalable search implementations.
Tiny and powerful JavaScript full-text search engine for browser and Node
Pros of MiniSearch
- Lightweight and dependency-free, making it easy to integrate into various projects
- Supports in-memory full-text search, ideal for client-side applications
- Offers flexible search options, including fuzzy search and field-specific boosting
Cons of MiniSearch
- Limited to in-memory search, not suitable for large-scale or server-side applications
- Lacks advanced features like faceted search and aggregations
- Requires manual index management and updates
Code Comparison
MiniSearch:
const miniSearch = new MiniSearch({
fields: ['title', 'text'],
storeFields: ['title', 'category']
})
miniSearch.addAll(documents)
const results = miniSearch.search('query')
Searchkit:
const searchkit = new Searchkit({
connection: {
host: 'http://localhost:9200/'
},
searchOnLoad: true
})
const results = await searchkit.query({
query: 'query'
})
MiniSearch is more focused on simplicity and client-side search, while Searchkit provides a more comprehensive solution for Elasticsearch integration. MiniSearch is better suited for smaller datasets and browser-based applications, whereas Searchkit offers more advanced features and scalability for larger, server-side search implementations.
A bit like Solr, but much smaller and not as bright
Pros of Lunr.js
- Lightweight and client-side, suitable for small to medium-sized search applications
- No external dependencies, easy to integrate into existing projects
- Works well with static sites and offline applications
Cons of Lunr.js
- Limited scalability for large datasets or complex search requirements
- Lacks advanced features like faceted search and geospatial queries
- Requires loading entire index into memory, which can be inefficient for large datasets
Code Comparison
Lunr.js:
var idx = lunr(function () {
this.field('title')
this.field('body')
this.add({
"title": "Lunr",
"body": "Like Solr, but much smaller, and not as bright."
})
})
Searchkit:
const searchkit = new SearchkitManager("http://demo.searchkit.co/api")
const searchbox = new SearchBox({
field: "title",
placeholder: "Search",
autofocus: true
})
While Lunr.js focuses on creating and searching an in-memory index, Searchkit provides a higher-level abstraction for building search UIs with Elasticsearch. Lunr.js is more suitable for smaller, client-side search implementations, while Searchkit offers more robust features for larger-scale search applications with server-side indexing and querying.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Elasticsearch Search UI Components
Searchkit is an open source library which helps you build a great search experience with Elasticsearch. Works with Javascript, React, Vue, Angular, and more.
Website | Demos | Documentation | Discord
Searchkit provides a Search UI for Elasticsearch or Opensearch. With Searchkit, you can use Instantsearch components like Searchbox, refinement filters and results (and many more!) to build a search experience.
Searchkit is great for anyone who want to build a search experience quickly.
Searchkit simplifies Search UI with Elasticsearch:
- UI Search Components for React, Vue, Angular, and more
- Searchkit Node API proxies Elasticsearch requests from the browser.
- Ability to use Elasticsearch Query DSL for advanced queries
Searchkit AI Bot
Searchkit Bot will help you understand this repository better. You can ask for code examples, installation guide, debugging help and much more.
Demos
Quick Start Guides
Tutorials
Codesandbox Examples
Code Examples (on Github)
Proxy Elasticsearch Quick Starts
Video Tutorials
Or checkout our documentation for more examples.
Installation
Either install via npm or yarn
npm install searchkit @searchkit/api @searchkit/instantsearch-client
or via CDN
<script src="https://cdn.jsdelivr.net/npm/@searchkit/instantsearch-client@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
<script src="https://cdn.jsdelivr.net/npm/searchkit@latest"></script>
Setup Elasticsearch
Searchkit requires Elasticsearch 7.0 or higher or Opensearch 2.4 or higher.
Below we are using Docker to run Elasticsearch.
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.6.2
docker network create elastic
docker run --name elasticsearch --net elastic -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e http.cors.enabled=true -e "http.cors.allow-origin='*'" -e http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization -e http.cors.allow-credentials=true -e network.publish_host=localhost -e xpack.security.enabled=false docker.elastic.co/elasticsearch/elasticsearch:8.6.2
then lets add an index and some data
curl --location --request PUT 'http://localhost:9200/products' \
--header 'Content-Type: application/json' \
--data-raw '{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"description": {
"type": "text"
},
"price": {
"type": "integer"
},
"categories": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}'
curl --location --request POST 'http://localhost:9200/products/_doc' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Apple iPhone 12 Pro Max",
"description": "The iPhone 12 Pro Max is the most powerful iPhone ever. It has a 6.7-inch Super Retina XDR display, a Ceramic Shield front cover, and a triple-camera system with a LiDAR scanner. It also has a 5G connection, a 6-core CPU, and a 4-core GPU. The iPhone 12 Pro Max is available in 128GB, 256GB, and 512GB storage options.",
"categories": ["phones", "apple"],
"price": 800
}'
curl --location --request POST 'http://localhost:9200/products/_doc' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Apple iPhone 12 Pro",
"description": "The iPhone 12 Pro is the most powerful iPhone ever. It has a 6.1-inch Super Retina XDR display, a Ceramic Shield front cover, and a triple-camera system with a LiDAR scanner. It also has a 5G connection, a 6-core CPU, and a 4-core GPU. The iPhone 12 Pro is available in 128GB, 256GB, and 512GB storage options.",
"categories": ["phones", "apple"],
"price": 700
}'
Setup Searchkit
Searchkit compatible with all Instantsearch frameworks. Below is an example using react-instantsearch.
import Searchkit from "searchkit"
import Client from '@searchkit/instantsearch-client'
// import your InstantSearch components
import { InstantSearch, SearchBox, Hits, RefinementList, Pagination, RangeInput } from 'react-instantsearch';
const sk = new Searchkit({
connection: {
host: 'http://localhost:9200',
// with an apiKey
// https://www.searchkit.co/docs/guides/setup-elasticsearch#connecting-with-api-key
// apiKey: '##########'
// with a username/password
// https://www.searchkit.co/docs/guides/setup-elasticsearch#connecting-with-usernamepassword
//auth: {
// username: "elastic",
// password: "changeme"
//}
},
search_settings: {
search_attributes: [{ field: 'title', weight: 3 }, 'actors', 'plot'],
result_attributes: ['title', 'actors', 'poster', 'plot'],
highlight_attributes: ['title'],
facet_attributes: [
{ attribute: 'actors', field: 'actors.keyword', type: 'string' },
{ attribute: 'imdbrating', type: 'numeric', field: 'imdbrating' }
]
}
})
const searchClient = Client(sk);
const App = () => (
<InstantSearch
indexName="imdb_movies"
searchClient={searchClient}
>
<SearchBox />
<div className="left-panel">
<RefinementList attribute="actors" searchable={true} limit={10} />
<RangeInput attribute="imdbrating" />
</div>
<div className="right-panel">
<Hits />
<Pagination />
</div>
</InstantSearch>
}
follow along with the Getting Started guide.
Hide Elasticsearch from the browser
Searchkit Node API allows you to proxy requests to Elasticsearch from the browser. This is useful if you want to hide Elasticsearch from the browser, or if you want to add user permission filters to the query.
Query Customisation
Searchkit has an out the box query builder, but you can also customise the query by passing a getQuery function to the apiClient.
const results = await apiClient.handleRequest(req.body, {
getQuery: (query, search_attributes) => {
return [
{
combined_fields: {
query,
fields: search_attributes,
},
},
];
},
});
Semantic Query Search
Searchkit supports KNN query search. Below is an example of a KNN query search.
const results = await client.handleRequest(req.body, {
getKnnQuery(query, search_attributes, config) {
return {
field: 'dense-vector-field',
k: 10,
num_candidates: 100,
// supported in latest version of Elasticsearch
query_vector_builder: {
text_embedding: {
model_id: 'cookie_model',
model_text: query
}
}
}
}
});
Follow along with the Semantic Search tutorial.
Advanced Customisation
You can also override the entire query with request hooks. Below is an example of a request hook that adds a rescore query to the first search request.
You can apply this at beforeSearch
and afterSearch
.
const results = await client.handleRequest(req.body, {
hooks: {
beforeSearch: (searchRequests) => {
const uiRequest = searchRequests[0]
return [
{
...uiRequest,
body: {
...uiRequest.body,
rescore: {
window_size: 100,
query: {
rescore_query: {
match: {
plot: {
query: uiRequest.body.query,
operator: "and",
},
},
},
query_weight: 1,
rescore_query_weight: 10,
}
}
}
},
searchRequests.slice(1, searchRequests.length)
]
},
}
});
read more in the api docs here.
Query Rules
Query rules allows you to customize the behavior of the search experience. You can use query rules to boost or filter results, or to change the ranking of results, based on a set of conditions.
Below is an example of a query rule that boosts results for movies with Dan Aykroyd or Charlie Sheen, and filters results to only show movies if the query is the word "movie".
{
id: '1',
conditions: [
[
{
context: 'query',
value: 'movie',
match_type: 'exact'
}
]
],
actions: [
{
action: 'QueryBoost',
query: 'actors:"Dan Aykroyd" OR actors:"Charlie Sheen"',
weight: 2
},
{
action: 'QueryFilter',
query: 'type:"movie"'
}
]
}
read more at Query Rules docs.
NPM Packages
- Searchkit Documentation
- @searchkit/api Documentation
- @searchkit/instantsearch-client Documentation
FAQ
Q: Do I need to expose Elasticsearch to the public internet?
Searchkit proxies requests to Elasticsearch.
Searchkit offers both options, either perform the search directly from the browser, or use the Searchkit API to proxy requests to Elasticsearch. Directly from the browser offers great developer experience & prototyping. Once you are ready to deploy, you can use the Searchkit API to proxy requests to Elasticsearch.
Q: Do I need to use React?
You can use React, React Native, Vue, Angular. You dont even need to use a frontend framework, you can use plain Javascript and HTML with instantsearch.js widgets.
Q: Which version of Elasticsearch is supported?
Searchkit is compatible with Elasticsearch 7.0 and above + Opensearch 2.0 and above.
Q: Do you support Android and iOS?
Potentially. Searchkit API mimics the Algolia API, so it should be possible to use the Algolia Instantsearch client with Searchkit API with a few tweaks. If you are interested in this, please let us know.
Q: Why would I use Searchkit instead of Algolia?
Elasticsearch has alot of advantages over Algolia. You might want to use Elasticsearch as a cheaper alternative to Algolia, especially if you have a large dataset. You might want to run Elasticsearch on your own infrastructure, or have greater control over the query relevance.
Top Related Projects
Official Elasticsearch client library for Node.js
⚡️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.
Next-Generation full text search library for Browser and Node.js
JS Search is an efficient, client-side search library for JavaScript and JSON objects
Tiny and powerful JavaScript full-text search engine for browser and Node
A bit like Solr, but much smaller and not as bright
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot