## Adding Custom Fields as facet filter in Faceted Search

SearchBlox fields such as title, keywords, language, etc., as well as custom fields such as **_meta fields_** for HTTP collections, author and subject fields for file collections can be added as facets in faceted search. All fields indexed through CSV, Database and MongoDB collections can also be added as facets in faceted search.

### Steps to Add Facets

**Step 1:** Stop SearchBlox.

**Step 2:** For custom fields in HTTP, File collection, RSS collection and custom collections, add the fields in _../webapps/searchblox/WEB-INF/mapping.json_.

For custom fields in CSV collections, add the snippet in _./webapps/searchblox/WEB-INF/csv.json_. In Database collections, add the snippet in _./webapps/searchblox/WEB-INF/jdbc.json_. And for MongoDB collections, add the snippet in _./webapps/searchblox/WEB-INF/mongodb.json_.

**Example:** Add the following snippet in mapping.json, csv.json, jdbc.json or mongodb.json based on the collection for each custom field. Enter the name of the custom field in the beginning "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:** In order to add these facets, the facets need to be updated in ../webapps/searchblox/plugin/facet.js as shown:

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 HTTP, File and Custom collections cannot be searched even if they are added as facets using the steps outlined in the preceding section.

If you need the content from meta fields or custom fields to be searched, add the following mapping to the mapping.json file found within the /searchblox/WEB-INF folder. Restart SearchBlox and then reindex the collection.

"section":{ "type": "text", "copy_to": "custom_all" },

otherwise provide "copy_to": "custom_all" to the existing mapping as shown "customfieldname": { "type": "text", "store": true, "fielddata": true, "analyzer": "comma_analyzer", "copy_to": "custom_all" },

Applicable for HTTP, File, RSS and Custom Collection

## Adding Custom Date fields as facet filter

if you want to use a published date as a facet field with the following meta tag in your HTML page:

<meta name="published" content="2014-03-15T01:50:58"/> or <meta name="published" content="2014-03-15"/> 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 },

Preceding changes are to be made in mapping.json on using HTTP, file or custom collection, jdbc.json on using database collection, csv.json on using CSV collection, mongodb.json on using Mongodb collection and amazons3.json on using AWS S3 collection. Please make sure to clear and reindex for the changes to take effect.

Click here 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-](🔗) The contents of facet.js file are as follows:

In order to add this date facet, the facets need to be updated in ../webapps/searchblox/plugin/facet.js as shown:

### Mapping custom date format

If your date field has a custom date format it has to be mapped in ../searchblox/WEB-INF/mapping.json For example, if your meta date is as shown here

<meta name="published" content="2014-03-12 01:50:58"/>

Mapping to be provided in mapping.json "published": {"type":"date", "store":"yes", "format": "yyyy-MM-dd HH:mm:ss" },