Example of the popular open-source search and analytics engine – Elasticsearch to power a simple search system in ASP.NET Core using RazorPages.
- RazorPages (NET Core 3.1 / C# language).
- NEST - Official Elasticsearch Client.
Key features follow:
- Distributed and scalable, including the ability for sharding and replicas.
- Documents uses JSON format.
- All interactions are done over a REST API.
- Many software like popular Kibana allow interrogation and analysis of data.
- Loads of client-side libraries for all popular languages.
Example pages:
- Title Search - allow to search via Title, when no "Term" is given, then we return first ten books from the database. Given search text, we return items containing searched text.
- Page Count - This page returns range aggregation of the pages of the book (this is done by using the "Aggregate" function).
- Categories - This page returns the total count for appearing categories (aggregation on text fields) in the whole database.
Single index in example dataset:
{
"title":"string",
"isbn":"string",
"pageCount":0,
"thumbnailUrl":"string",
"shortDescription":"string",
"longDescription":"string",
"status":"string",
"authors":"string",
"categories":"string"
}
Assuming you are running Elasticsearch engine in Docker on port 9200, to load your dataset from JSON file, execute the following command:
curl -XPOST localhost:9200/books/book/_bulk --data-binary @dataset.json -H "Content-Type: application/json"
Ensure that your file will have an empty newline and the end of the file. Additionally, if using PowerShell, make sure to use backtick before @
character.
A comprehensive article about Elasticsearch can be found at Knowi portal: Elasticsearch: What It Is, How It Works, And What It’s Used For.