How to Use Different Analyzers with Elasticsearch
Prerequisites
The following products must be installed before continuing:
- Elasticsearch
- Kibana A source-available data visualization dashboard for Elasticsearch
- BA Insight Connectivity Hub
Create a New Elasticsearch Index
To use a custom or a different analyzer, 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:
- Start Elasticsearch and Kibana.
- Navigate to the Kibana home page (http://localhost:5601).
-
Click on the "Dev tools" button to open the console.
-
Create a new Elasticsearch index by using the following code snippet, with the following adjustments:
- Replace new_index_name with the desired name for the Elasticsearch index.
- Specify the field(s) which should use a different analyzer. In the code snippet below, the content property of the FileContent property will use a custom analyzer.
-
Replace your_analyzer_name with a build-in analyzer (for example the language analyzer english) or a custom analyzer.
-
Add the exact field if you want to have exact matches on that property.
CopyPUT new_index_name
{
"mappings" : {
"properties" : {
"FileContent" : {
"properties" : {
"content" : {
"type" : "text",
"analyzer": "your_analyzer_name",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
},
"exact": {
"type": "text" }
}
}
}
}
}
}
}
- Run the command.
Push Items to the Newly Created Index.
-
Navigate to the BA Insight Connectivity Hub home page.
- Create a new "Web service content" source with the same name as the newly created Elasticsearch index.
- Run a "Target Full Update" task on this new content source.
Modify the Elasticsearch Query
-
Use the newly created index as a backend The search engine your SmartHub instance uses to perform queries. SmartHub can be configured to use more than one search engine. in SmartHub.
-
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\"}}]}}}"