我正在尝试使用elastic search中的同义词功能
下面是我的弹性搜索配置
<elasticsearch:node-client id="client" local="true"/>
<bean name="elasticsearchTemplate" class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>根据文档,提到要相对于Elastic Search的config目录放置同义词文件。
但在我的例子中,我希望在创建索引时以编程方式传递同义词文本。用户将可以选择在同义词文件中添加其他条目,应用程序将刷新索引,并使用更新后的同义词文件再次分析数据
创建索引时,有一个传递设置的选项
elasticSearchTemplate.createIndex(MyClass.class , Map settings )例如:elasticsearchTemplate.createIndex(Entity.class, "max_result_window = 15000");
但是同义词设置在Analyzer模块中。
如果这可以在创建索引时作为设置传递,请恢复
发布于 2017-04-05 16:20:59
下面是我找到的最接近的解决方案。
@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 ;下面是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"
}
}
}
}
}https://stackoverflow.com/questions/42728319
复制相似问题