How to Use Different Analyzers with Elasticsearch

Prerequisites

The following products must be installed before continuing:

  • Elasticsearch
  • Kibana
  • BA Insight Connectivity Hub

Create a New Elasticsearch Index

Note: Important!
To use a custom or a different analyzer, you must create a new Elasticsearch index. It is not possible to modify the analyzer of a field for an existing index.

To specify a built-in or a custom analyzer for a field, other than the standard analyzer, follow these steps:

  1. Start Elasticsearch and Kibana.
  2. Navigate to the local Kibana home page instance at (http://localhost:5601).
  3. Click on the Dev tools to open the console.

  4. Create a new Elasticsearch index by using the following code snippet, with the following adjustments:

    1. Replace new_index_name with the desired name for the Elasticsearch index.
    2. Specify the field(s) which should use a different analyzer.
      1. In the code snippet below, the content property of the FileContent property will use a custom analyzer.
    3. Replace your_analyzer_name with a build-in analyzer (for example the language analyzer english) or a custom analyzer.

    4. Add the exact field if you want to have exact matches on that property.

      Copy
      PUT new_index_name
      {
        "mappings" : {
          "properties" : {
            "FileContent" : {
              "properties" : {
                "content" : {
                  "type" : "text",
                  "analyzer": "your_analyzer_name",
                  "fields" : {
                    "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                    },
                    "exact": {
                      "type": "text"              }
                  }
                }
              }
            }
          }
        }
      }
  5. Run the command.

Push Items to the Newly Created Index.

  1. Navigate to the BAInsight ConnectivityHub home page.

  2. Create a new "Web service content" source with the same name as the newly created Elasticsearch index.
  3. Run a "Target Full Update" task on this new content source.

Modify the Elasticsearch Query

  1. Use the newly created index as a backend in SmartHub.

  2. Add the quote_field_suffix property to the Elasticsearch query by merging the following JSON object with the original JSON request using the steps from How to Modify the Elastic Search Query by using a Scripting Stage.

    Copy
    "{\"query\": {\"bool\": {\"must\": [{\"query_string\": {\"fields\": [ \"FileContent.content\"],\"quote_field_suffix\": \".exact\"}}]}}}"