Search Elastic

From SocialStack

The elastic search module works alongside the Search Crawler to extract pages from the site into an elastic search instance to enable site wide search

The module registers itself to listen for the search crawler events and creates locale based indexes in the elastic repo for any pages it receives

When indexing the pages, if there is a primary data type then this will also be indexed against the page in primaryObject, this can then be used in query values as explained below

The indexing process is controlled by execution of the search crawler via the site automations

The module contains a Readme.txt file which gives help for the initial setup of elastic but the creation of the indexes/content are all automated.

Installation

The basic setup steps are

  1. Install the following socialstack modules
    • Api/SearchCrawler
    • Api/SearchElastic
    • UI/SiteSearch
  2. Mark any pages not to be indexed
  3. Install Elastic Search (see Readme.txt in the repo for help and guidance)
  4. Configure the sizing/scale in the elasticsearch.yml file (mainly vm memory usage)
  5. Start Elastic Search for the first time and get the master password and certificate fingerprint
  6. Add the url, credentials and fingerprint values to the module configuration via the ss admin panel
  7. Run the automation to index the site, the indexing progress is shown via the console

The module also contains a postman collection which can be used to quick debug/verify the indexed content

Once indexed there is a UI/SiteSearch module which can be used as the basis of the site search

Endpoints

GET /v1/sitesearch/reset

This removes any indexes from elastic to allow a clean start

POST /v1/sitesearch/query

This is the core search endpoint which currently accepts the following values

queryString
The query value entered by the user and/or the UI/SiteSearch and UI/ContentSearch components, elastic search uses the Lucene query language so you can build complex queries
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
e.g.
Africa AND primaryObject.name:Botswana
primaryObject.price:(>=1000 AND <5000)
((quick AND fox) OR (brown AND fox) OR fox) AND NOT dog
tags
This expects a list of comma separated tags, if any are supplied the query will only return results which contain all the passed tag values
contentTypes
This expects a list of comma separated content types, if any are supplied the query will only return results which contain all the passed content types, these are normally the primary data object for the page
pageSize
This expects the page size and will default to 10 if not populated
pageIndex
This expects the starting page number and will default to 1
aggregationFields
This expects a list of comma separated field names, if any are supplied then aggregations/facets are returned for the fields, a good example of this can be be found in UI/ContentSearch component

UI Components

UI/ContentSearch

This provides a good example with filtering and paging

The component will also allow you to override the default values/titles for any aggregation using the aggregationOverrides property, this can be useful to add grouping to values such as regions/countries etc

{
	"t": "UI/ContentSearch",
	"d": {
		"aggregationFields": "tags,primaryObject.price,primaryObject.style2",
		"contentTypes": "ItineraryPageDataType",
		"aggregationOverrides": [
			{
				"name": "primaryObject.price",
				"label": "Price",
				"buckets": [
					{
						"label": "&pound;3500",
						"key": "3500"
					},
					{
						"label": "&pound;5000",
						"key": "5000"
					},
					{
						"label": "&pound;7500",
						"key": "7500"
					}
				]
			},
			{
				"name": "tags",
				"label": "Tags",
				"buckets": [
					{
						"label": "Africa2",
						"key": "Africa"
					},
					{
						"label": "Botswana2",
						"key": "Botswana"
					}
				]
			}
		]
	},
	"i": 4
}