弹性搜索。找不到自定义分析器
Elasticsearch. Can not find custom analyzer
我有这样的模型:
@Getter
@Setter
@Document(indexName = "indexName", type = "typeName")
@Setting(settingPath = "/elastic/elastic-setting.json")
public class Model extends BaseModel {
@Field(type = FieldType.String, index = FieldIndex.analyzed, analyzer = "customAnalyzer")
private String name;
}
我里面有弹性-setting.json../resources/elastic/elastic-setting.json:
{
"index": {
"number_of_shards": "1",
"number_of_replicas": "0",
"analysis": {
"analyzer": {
"customAnalyzer": {
"type": "custom",
"tokenizer": "uax_url_email"
}
}
}
}
}
我清理了我的弹性数据库,当我启动我的应用程序时出现异常:
MapperParsingException[analyzer [customAnalyzer] not found for field [name]]
我的代码有什么问题?
请帮助我!
编辑
Val,我认为@Setting 就像是对@Document 的补充,但看起来它们可以互换。
就我而言,我还有另一个模型,其中:
@Document(indexName = "indexName", type = "anotherTypeName")
所以,首先我为另一个模型创建名称为 "indexName" 的索引,接下来在弹性准备模型时,它看到名称为 "indexName" 的索引已经创建,并且他没有使用 @Setting。
现在我有另一个问题。
如何将自定义分析器添加到 java 代码中已创建的索引,例如在 InitializingBean 中。类似的东西 - 我的分析器创建了吗?不-创建。是 - 不创建。
像这样修改您的 elastic-setting.json
文件:
{
"index": {
"number_of_shards": "1",
"number_of_replicas": "0"
},
"analysis": {
"analyzer": {
"customAnalyzer": {
"type": "custom",
"tokenizer": "uax_url_email"
}
}
}
}
}
请注意,您需要先删除索引并重新创建。
更新
您当然可以通过 Java 代码添加自定义分析器,但是,您将无法更改现有映射以使用该分析器,因此您最好擦除索引并使用适当的 elastic-setting.json
JSON 文件从头开始重新创建它。
对于瓦尔:
是的,我用这样的东西。
以前,我在我的一个实体 class 中添加了 @Setting,但是当我启动应用程序时,已经创建了同名索引,在 Spring 数据使用 @Setting 分析实体之前,索引没有已修改,因为已创建同名索引。
现在我在抽象 baseModel 上添加注解 @Setting(path = "elastic-setting.json"),首先扫描高层层次结构 class 并创建分析器。
我有这样的模型:
@Getter
@Setter
@Document(indexName = "indexName", type = "typeName")
@Setting(settingPath = "/elastic/elastic-setting.json")
public class Model extends BaseModel {
@Field(type = FieldType.String, index = FieldIndex.analyzed, analyzer = "customAnalyzer")
private String name;
}
我里面有弹性-setting.json../resources/elastic/elastic-setting.json:
{
"index": {
"number_of_shards": "1",
"number_of_replicas": "0",
"analysis": {
"analyzer": {
"customAnalyzer": {
"type": "custom",
"tokenizer": "uax_url_email"
}
}
}
}
}
我清理了我的弹性数据库,当我启动我的应用程序时出现异常:
MapperParsingException[analyzer [customAnalyzer] not found for field [name]]
我的代码有什么问题? 请帮助我!
编辑
Val,我认为@Setting 就像是对@Document 的补充,但看起来它们可以互换。 就我而言,我还有另一个模型,其中:
@Document(indexName = "indexName", type = "anotherTypeName")
所以,首先我为另一个模型创建名称为 "indexName" 的索引,接下来在弹性准备模型时,它看到名称为 "indexName" 的索引已经创建,并且他没有使用 @Setting。
现在我有另一个问题。 如何将自定义分析器添加到 java 代码中已创建的索引,例如在 InitializingBean 中。类似的东西 - 我的分析器创建了吗?不-创建。是 - 不创建。
像这样修改您的 elastic-setting.json
文件:
{
"index": {
"number_of_shards": "1",
"number_of_replicas": "0"
},
"analysis": {
"analyzer": {
"customAnalyzer": {
"type": "custom",
"tokenizer": "uax_url_email"
}
}
}
}
}
请注意,您需要先删除索引并重新创建。
更新
您当然可以通过 Java 代码添加自定义分析器,但是,您将无法更改现有映射以使用该分析器,因此您最好擦除索引并使用适当的 elastic-setting.json
JSON 文件从头开始重新创建它。
对于瓦尔: 是的,我用这样的东西。 以前,我在我的一个实体 class 中添加了 @Setting,但是当我启动应用程序时,已经创建了同名索引,在 Spring 数据使用 @Setting 分析实体之前,索引没有已修改,因为已创建同名索引。
现在我在抽象 baseModel 上添加注解 @Setting(path = "elastic-setting.json"),首先扫描高层层次结构 class 并创建分析器。