Elastic Search

How to set up Elastic Search on a site with one or multiple indexes

  1.  Go to the site(s) that you want to index the items that will be searched.  It does not have to be the same site where the search box will be located.
  2. Turn on the Elastic Press Plugin and build the index.
  3. Go to Elastic Press >> Index Health and copy the index name (something like todaystagewilliamsedu-post-270 )
  4. Go to the site where you want Elastic powering your search and go to Options in the WP Admin
  5. Toggle on "Use Elastic to  power..."
  6. Enter the index name that you copied earlier in the now visible "Elastic Index" field.  If combining more than one index, enter the names as a comma delimited list. (example: todaystagewilliamsedu-post-270,magazinestagewilliamsedu-post-181
  7. Toggle "Show post types..." on or off depending on if you would like to show the post type name tag in the results.  (in many cases this will be off, because they are all 'post')
  8. If your site has a standard WP search box, and is in M20 or M21, the search results should now be supplied from the Elastic Index you created and set in the site's options.

How to add a typeahead search box

(requires Beaver Builder in M20 or M21)

  1. Go to the page or part that you would like to add the search box.
  2. Click on "Beaver Builder" to start the BB editor
  3. Click on the +, then the modules drop-down ("standard modules") and choose "Williams"
  4. Drag "Elastic Module" onto the page
  5. When the module editor opens, it should display the index(es) that are connected in the site options in the WordPress admin and give a choice to hide/show the post type name.  This toggle only applies to the typeahead and not the results screen that was already set in the site options.
  6. Save the module and publish the page.
  7. Congrats your site now has a search box that shows the first ten results in a type ahead overlay and if you hit enter, a standard results screen with pagination for deep search dives.

Adding additional meta to the index

By default, once you turn on Elastic search in the site options any time you create a new post the featured image and post type name are automatically added to the index, but if you want to add this for every existing post it can be done with a simple WP-CLI command:

wp update-elastic-meta --url=magazine.stage.williams.edu --cpt=stories

Where the --url is the site that you are adding the extra meta for and the --cpt is the post type.

Adding to the fields that are searched

By default, once a site is using Elastic search it searches post_title^10, post_content, but it is possible to add additional fields. If your field is being indexed, it can be added to WordPress Admin >> Options >> Additional Elastic Fields with any valid Elastic multi_match weighting. For example on the Today site, meta.book_author.value^10 has been added to search whenever the book author has a value with a weight of times ten.

Clear search

Example: Search today.williams from the comfort of demo.williams