Indexing and Query

Configuring the Elasticsearch Mapping

Updated: October 16, 2020

This documentation page talks about the many aspects you can tune for improving the search experience for your users when it comes to full-text search. This page is limited to full-text searches querying the Elasticsearch index, which is the recommended index for performing full-text searches.

Here are some examples of common changes of the Elasticsearch mapping.

All examples below should be done in a custom template that redefines the Elasticsearch mapping.

Customizing the Language

The Nuxeo code uses a full-text analyzer named fulltext. This is an alias that points to the en_fulltext analyzer by default.

To change it to the French analyzer for instance, move the following line into the fr_fulltext:

 "alias" : "fulltext"

If you dump the mapping from the Elasticsearch HTTP API (or using an Elasticsearch plug-in like head or kopf), you will see that alias are replaced by the target.

If you want to do case insensitive search using an ILIKE operation:

  1. Make sure that the lowercase_analyzer is defined in your settings (available since 6.0-HF01).
  2. Declare your field as a multi_field with a lowercase index:

    "my:field" : {
      "type" : "multi_field",
      "fields" : {
        "my:field" : {
          "include_in_all" : "true",
          "type" : "string"
        },
        "lowercase" : {
          "type": "string",
          "analyzer" : "lowercase_analyzer"
        }
      }
    }
    

Adding a New Full-Text Field

To use the full-text search syntax on a custom field you need to create a multi_field with a fulltext index like this:

"my:text" : {
  "type" : "multi_field",
  "fields" : {
    "my:text" : {
      "include_in_all" : "true",
      "type" : "string"
    },
    "fulltext" : {
      "type": "string",
      "analyzer" : "fulltext"
    }
  }
}

Note that if you:

  • don't perform non fulltext search on this field
  • don't use this field with a IS NULL or IS NOT NULLoperation
  • don't sort on this field

Then you can disable the default index on the field by adding after the second "[my:text](http://mytext)" : {

  "index" : "no",

Suppose you want to exclude my:secret field from the ecm:fulltext search:

 "my:secret" : {
    "type" : "string",
    "include_in_all" : false
 }