elasticsearch-recipes-nest-angular icon indicating copy to clipboard operation
elasticsearch-recipes-nest-angular copied to clipboard

A recipes search engine made using .NET core with Elasticsearch's NEST. It is the finished application from my 4 part tutorial on Elasticsearch on https://devadventures.net

This is the finished application if you were to follow my 4 part tutorial on Elasticsearch and NEST

The application

The application is pretty simple, but extremely flexible in terms of searching data.

Application

Behind the scenes, the user inputted query is converted to a query_string query that is sent to Elastic. The query_string query provides native support for a number of search syntax options, but we're mostly interested in wildcards, boolean operators, phrase matching and boosting.

The user inputted string is proccessed in the following way:

  • Exact phrases to look for are marked with quotes ("an example phrase").
  • Each word/phrase that isn't marked in any way (example) will be present in the result set's ingredients.
  • Each word/phrase that is marked with a minus (-example) will not be present in the result set's ingredients.
  • Each word/phrase can be boosted to become more relevant (score higher) in the search results.

So, if we want to look for recipes containing garlic, tomatoes, chopped onions and not containing eggs and red-pepper flakes, we'll have to input the query string:

garlic^2 tomatoes -egg "chopped onions" -"red-pepper flakes"* // Order doesn't matter

As you can see, we've boosted the garlic. This means that recipes where garlic appears more frequently will score higher.

The asterisk symbol following the egg is called a wildcard query. It means that it's going to look for words that start with egg and continue with anything else, no matter the length (for example, egg* is going to match eggs, eggplant, eggbeater, etc.), very similar to SQL's like.

You can substitute the asterisk with a "?" sign, which will indicate that Elastic should look for just a single missing letter.

This spits out the result: Result ...

How to run

In order to run the application, you must install and run elastic then execute the following steps:

  1. Clone the repository.
  2. Open the project in Visual Studio and restore packages (Ctrl + Shift + K, Ctrl + Shift + R).
  3. Run the application (Ctrl + F5).

In order to make use of the search functionality, you must have some recipes indexed in your elastic cluster.

First, make sure that the cluster url in appsettings.json is correctly configured then:

  1. Download the openrecipes dump json file.
  2. Extract the json file in project-root\src\ElasticsearchRecipes\Data (create the Data folder if it doesn't exist).
  3. While the application is running, make a get request to appurl/api/index/file?fileName=openrecipes-big.json.
  4. In a few minutes you should see a json response confirming that the indexation was valid.

Everything should be set-up and you are free to play around.