Technology

Improve WikiJS Search


Out of the box, wikijs uses the “Database – Basic” as its search option which works ok for simple content but there are better options that you can enable.

I recommend switching to ElasticSearch, it will greatly improve the search quality and the overall user experience of finding content in wikijs. When using basic or advanced postgresql search, I often would type in text that exists but were too complicated for the search to find and the results would return nothing. Now with Elasticsearch, I find the results are what I was expecting and when no results are found, its interface does a better job to handling that.

Adding Elasticsearch Container

If you are in a docker-ized environment for wikijs, you can easily add elasticsearch by adding a new service to your docker-compose.

  elasticsearch:
    image: elasticsearch:7.17.6
    restart: unless-stopped
    environment:
      discovery.type: single-node
      ES_JAVA_OPTS: "-Xms2G -Xmx2G"

Currently wikijs can only work with elasticsearch 6.x or 7.x but not 8.x.

Also make sure to set the Java shared memory size to your liking (ES_JAVA_OPTS line). This line isn’t needed but if you don’t set it, elasticsearch will use half of the system memory by default. While more memory will make it work faster, if your are running a small wikijs, you don’t need to dedicate that much memory.

You don’t need to worry about persistent storage for elasticsearch, if the container gets deleted, wikijs will rebuild the index from the database.

Enabling Elasticsearch in WikiJS

Now in wikijs, you will need to go into the Administration settings to switch search providers

Then from the left sidebar select Modules > Search Engine

Toggle the Search Engine from Database – Basic to Elasticsearch

Set the Elasticsearch Version to 7.x (unless you are running a 6.x)

Set the Host to http://elasticsearch:9200 (since we are in the same docker-compose file, containers can DNS resolve other containers and they can access each other ports without publicly setting them)

Then hit Apply and Rebuild Index — give your new search a try. It should build the index in just a few seconds.

Followup

So after using this for months, the one complaint I have is if your server/container restarts, sometimes the search doesn’t work until you go in and click Rebuild Index again. Not a huge deal, but if you are looking for truly hands off, don’t log into this unless a support ticket comes in. You may not appreciate that. I wish it would auto rebuild on its own.

OPTIONAL: Analyzer Options

You have the options to change the analyzer but truthfully, simple is probably the best use if you have code content in your wikijs.

standard – breaks text with a grammar based tokenization, good for most spoken languages

simple – (WIKIJS DEFAULT) breaks text into tokens at any non-letter character, such as numbers, spaces, hyphens and apostrophes, discards non-letter characters, and changes uppercase to lowercase.

whitespace – breaks text into tokens at any non-letter character

stop – this uses a filter to remove “stop” words from the search. WikiJS doesn’t expose the custom field, so the default English stop words are removed (a, an, and, are, as, at, be, but, by, for, if, in, into, is, it, no, not, of, on, or, such, that, the, their, then, there, these, they, this, to, was, will, with)

openanalytics 139606 views

I'm a 35 year old UIUC Computer Engineer building mobile apps, websites and hardware integrations with an interest in 3D printing, biotechnology and Arduinos.


View Comments
There are currently no comments.

This site uses Akismet to reduce spam. Learn how your comment data is processed.