Reputation: 1195
I am trying to use the synonym feature in elastic search
Below is my elastic search configuration
<elasticsearch:node-client id="client" local="true"/>
<bean name="elasticsearchTemplate" class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
As per the documentation , it is mentioned to place the synonym file relative to the config directory of Elastic Search.
But in my case I want to pass the synonym text programatically while creating the index. The user will have option to add additional entries in the synonym file and application will refresh the index and analyze the data again using the updated synonym file
While creating index , there is an option to pass settings
elasticSearchTemplate.createIndex(MyClass.class , Map settings )
eg: elasticsearchTemplate.createIndex(Entity.class, "max_result_window = 15000");
But the synonym setting is within the Analyzer module .
Kindly revert back if this can be passed as settings while creating index
Upvotes: 0
Views: 636
Reputation: 1195
The closest solution I found is below .
@Document(indexName = "myindex", type = "mytype")
@Setting(settingPath = "/mysetting/mysetting.json")
public class Employee implements Serializable {
@Id
private String employeeId;
@Field(type = FieldType.String, analyzer = "synonym_analyzer")
private String transformedTitle ;
Below is the mysetting.json
{
"index": {
"number_of_shards": "1",
"number_of_replicas": "0",
"analysis": {
"analyzer": {
"synonym_analyzer": {
"tokenizer": "whitespace",
"filter": [
"synonym_filter"
]
}
},
"filter": {
"synonym_filter": {
"type": "synonym",
"synonyms": [
"english,british",
],
"ignore_case": "true"
}
}
}
}
}
Upvotes: 0