Docs
Guides
Filter By Array value

You can filter your search results by array of string values. This is useful for filtering by documents with many authors or tags.

Setup a String field

To filter by string, you must first add a keyword to your index.

Indexing the following document into Elasticsearch will create a tags field that can be used for filtering.

{
  "tags": ["ecommerce", "FW23"]
}

and your mapping will look like this:

{
  "properties": {
    "tags": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword"
        }
      }
    }
  }
}

Filter Attribute Configuration

Add a filter attribute to your index configuration. The filter attribute will be used to filter your search results by date.

 {
  "filter_attributes": [
    { attribute: 'tags', field: 'tags.keyword', type: 'string' },
  ]
 }
 

Alternatively, you can also add the attribute under facet_attributes to make it available for faceting.

 {
  "facet_attributes": [
    { attribute: 'tags', field: 'tags.keyword', type: 'string' }
  ]
 }
 

The attribute name must be unique in both filter_attributes and facet_attributes. If you want to use the same attribute for both filtering and faceting, add it to facet_attributes only.

Using Filter Attributes

You can use the filter attribute in your search query to filter your search results by date within configure.

Syntax Examples

Filters must follow the Elasticsearch Query String (opens in a new tab) format.

 "tags:ecommerce" # author is John
 "author:ecommerce OR tags:fw23" # author is John or Jane

Example

 client.configure({
  filters: 'tags:ecommerce'
 })