Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/benninkcorien/hugo-local-elastic-win

Localhost (windows) Hugo site with elastic search for content including wildcards and consecutive words
https://github.com/benninkcorien/hugo-local-elastic-win

Last synced: about 2 months ago
JSON representation

Localhost (windows) Hugo site with elastic search for content including wildcards and consecutive words

Awesome Lists containing this project

README

        

# How to get this running locally on Windows 11.

![](screenshot.png)

## install Elasticsearch

https://www.elastic.co/downloads/elasticsearch

Unzip into C:\elasticsearch-8.14.3\

### set the correct values for your setup/system

Rename all occurences of *indexname* to the name you want the index to have on ElasticSearch

Files to change:

- static\js\server.js
- pythonscripts\index-with-elastic-search.py

Replace all occurences of *F:\HugoBookSearchElasticGithubGithub*
With the correct path you've cloned this git to.

Files to change:

- pythonscripts/index-with-elastic-search.py
- 00startall.py

Replace all occurences of *yourelasticpassword*
(See below for how to set a password)

Files to change:

- pythonscripts\index-with-elastic-search.py
- static\js\server.js

Change filepaths to the correct locations in

- 00startall.py

# Run everything

Use yarn (or npm) to install everything listed in package.json

> yarn install

## Start servers.

This is not the best way to do it, but my Python is better than my package.json scripts and this works well enough.

> python 00startall.py

3 command line windows will open,

- 1 will run ElasticSearch
- 1 will run the NodeJS server that connects the site to ElasticSearch and returns results
- 1 will run the hugo server.

## Add posts
Add markdown files in /content or subfolders of /content.

If something stops working, you may have messed up frontmatter. See frontmatter-default.md for an example.

## ! RUN THE INDEX SCRIPT AFTER YOU ADD FILES
(this should be automated at some point)
If you don't index them, they won't be found when you search.

Set the value of clear_index to *True* or *False* depending on if you want to clear the ElasticSearch Index and add everything again (useful if you messed something up) or if you only want to add new files

> python -m pip install markdown python-frontmatter
>
> python index-with-elastic-search.py

# ## Live site
Go to localhost:1313/ and you should see Hugo, Search should also work for exact matches, wildcards and consecutive words, when you click on a result, the full post with show and the term(s) you searched for will be highlighted in yellow.

----

If you need to troubleshoot something, these are useful :

## Build the site manually
> hugo
or
> hugo --gc --minify

If you have a lot of files, this can take a while.

# Start Hugo server manually
> hugo server

# Start NodeJS server manually
> cd static\js
> node server.js

# Test if node is returning results

http://localhost:3000/search?q=randomwordtotestsearch

This should show JSON in your browser.

# Start ElasticSearch manually
"C:\elasticsearch-8.14.3\bin\elasticsearch.bat"
"C:\elasticsearch-8.14.3\config" -- xpack.security.http.ssl.enabled: false

## Empty elasticsearch index [indexname]
curl -u elastic:yourelasticpassword -X DELETE "http://localhost:9200/indexname"

# Test if Elasticsearch is returning results

curl -X GET "localhost:9200/indexname/_search?pretty" -H "Content-Type: application/json" -u elastic:yourelasticpassword -d "{\"query\": {\"multi_match\": {\"query\": \"randomwordtotestsearch \", \"fields\": [\"title\", \"author\", \"content\"]}}}"

---

# Set or reset your ElasticSearch password. USER is 'elastic'!
> cd C:\elasticsearch-8.14.3\bin
> $ elasticsearch-reset-password -u elastic

This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.

Password for the [elastic] user successfully reset.
New value: *yourelasticpassword*