Custom Fields in Search
Adding Custom Fields as facet filter in Faceted Search
SearchBlox lets you add facets in faceted search using standard fields like title, keywords, and language, as well as custom fields such as meta fields (for web collections), author and subject (for file collections), and fields from CSV, Database, and MongoDB collections.
Steps to Add Facets
Important:
When a new Collection is created, corresponding mapping.json file will be created inside
../webapps/ROOT/WEB-INF/mappings/collectionsfolder.
Example : mapping_001.json
Step 1:
Stop SearchBlox.
Step 2:
For custom fields in any collection, add the fields in the mapping.json file located in ../webapps/ROOT/WEB-INF/mappings/collections folder.
Example:
Add this snippet in mapping.json (e.g., mapping_001.json) for each custom field. Start with the custom field name:
"customfieldname": {
"type": "text",
"store": true,
"fielddata": true,
"analyzer": "comma_analyzer"
},
Example:
"subject": {
"type": "text",
"store": true,
"fielddata": true,
"analyzer": "comma_analyzer"
},

Add the preceding snippet without making any syntax errors. Add the field after another field without missing any commas.
Step 3:
To add these facets, update the facets in ../webapps/ROOT/search/facet.js as shown:
"facets": [{
"field": "colname",
"display": "Collection Name",
"size": "10"
},
{
"field": "subject",
"display": "Subject",
"size": "10"
},
{
"field": "contenttype",
"display": "File Type",
"size": "10"
},
{
"field": "keywords",
"display": "keywords",
"size": "10"
},
{
"field": "lastmodified",
"display": "Last Modified",
"dateRange": [{
"name": "Last 24 hours",
"calendar": "days",
"value": "1"
},
{
"name": "Past Week",
"calendar": "days",
"value": "7"
},
{
"name": "Past Month",
"calendar": "months",
"value": "1"
},
{
"name": "Past Year",
"calendar": "years",
"value": "1"
}
]
}
],
Step 4:
Start SearchBlox and reindex.
- Custom fields will only be added as filter facets using the preceding steps.
- Custom fields can either appear as filter facets or they can be searched. Both cannot happen simultaneously.
- If you want custom fields to be searchable, follow the instructions in the following section.
Please note that a field can be mapped only once in the JSON file
Making Custom Fields Searchable
By default, custom fields from WEB, File, and Custom collections cannot be searched, even if they are added as facets.
To make meta fields or custom fields searchable:
Add the following snippet in mapping.json (in /ROOT/WEB-INF), then restart SearchBlox and reindex the collection:
"section":{
"type": "text",
"copy_to": "custom_all"
},
Or, if the field already exists, add "copy_to": "custom_all" to its mapping:
"customfieldname": {
"type": "text",
"store": true,
"fielddata": true,
"analyzer": "comma_analyzer",
"copy_to": "custom_all"
},
Applicable for WEB, File and Custom Collection
Adding Custom Date fields as facet filter
If you want to use a published date as a facet field, use the following meta tag in your HTML page:
or Note: The format of date should be as shown above You need to add the following mapping to the mapping.json file found within the /searchblox/WEB-INF folder, and then create a new collection to index the web pages:"published":{
"type": "date",
"store": true
},
Make these changes in the specific mapping.json file of the collection you are using.
- After making the changes, clear and reindex the collection so the updates take effect.
For more information:
https://searchblox.zendesk.com/hc/en-us/articles/201888250-Can-I-use-my-own-field-for-a-custom-date-and-use-it-for-sorting-
- To add this date facet, update the facets in
../webapps/ROOT/search/facet.jsas shown:
{
"field": "published",
"display": "Published Date",
"dateRange": [{
"name": "Last 24 hours",
"calendar": "days",
"value": "1"
},
{
"name": "Past Week",
"calendar": "days",
"value": "7"
},
{
"name": "Past Month",
"calendar": "months",
"value": "1"
},
{
"name": "Past Year",
"calendar": "years",
"value": "1"
}
]
}
Mapping custom date format
If your date field uses a custom date format, it must be mapped in ../ROOT/WEB-INF/mappings/collections/ in the relevant mapping.json.
For example, if your meta date is like this:
Mapping to be provided in mapping.json
"published":
{"type":"date",
"store":"yes",
"format": "yyyy-MM-dd HH:mm:ss"
},
Updated about 1 month ago
