Hibernate 搜索和 elasticsearch:mapper_parsing_exception + analyzer [...] 未找到字段 [...]

Hibernate search and elasticsearch: mapper_parsing_exception + analyzer [...] not found for field [...]

我正在使用休眠搜索自动为特定实体创建索引

@Entity
@Indexed
public class Entity extends BaseEntity {

    private static final long serialVersionUID = -6465422564073923433L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @Field(bridge = @FieldBridge(impl = PropertyFieldBridge.class))
    private List<PropertyValue> properties = new ArrayList<>(); // PropertyValue is an abstract

}

字段桥正在创建字符串字段,格式为:pt_[a-zA-Z0-9]+_i18n。

然后我创建了一个动态模板来处理翻译后的字段:

PUT {{elasticsearch}}/com.orm.entity.entity.entity/com.orm.entity.entity.Entity/_mapping
{
  "com.gamila.api.orm.entity.entity.Entity": {
    "dynamic_templates": [
      {
        "my_analyzer": {
          "match_mapping_type": "string",
          "match_pattern": "regex",
          "match": "^pt_[a-zA-Z0-9]+_i18n",
          "mapping": {
            "type": "text",
            "analyzer": "portugueseAnalyzer"
          }
        }
      }
    ]
  }
}

但是当我创建一个实体时它总是returns一个错误:

Response: 400 'Bad Request' with body 
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "analyzer [portugueseAnalyzer] not found for field [pt_name_i18n]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "analyzer [portugueseAnalyzer] not found for field [pt_name_i18n]"
  },
  "status": 400
}

PortugueseAnalyser 是通过以下方式定义的:

public class Analyzer implements ElasticsearchAnalysisDefinitionProvider {

    @Override
    public void register(ElasticsearchAnalysisDefinitionRegistryBuilder builder) {
        builder.analyzer("portugueseAnalyzer")
                .withTokenizer("standard")
                .withTokenFilters("lowercase", "portugueseStemmer", "portugueseStop", "edge_ngram_3");

        builder.tokenFilter("portugueseStemmer")
                .type("stemmer").param("language", "portuguese");
        builder.tokenFilter("portugueseStop")
                .type("stop").param("stopwords", "_portuguese_");
    }

}

有人可以告诉我我做错了什么吗?我已经在 Whosebug 中浏览了一些问题,但没有成功。

PS:我正在使用来自 AWS

的弹性搜索 (5.6)

提前致谢

当 Hibernate Search 5 将映射推送到 Elasticsearch 时,它只会包含映射中某处实际使用的分析器的分析器定义。在你的例子中,就 Hibernate Search 而言,分析器没有被使用,所以它被忽略了。

作为 Hibernate Search 5 中的解决方法,您可以声明一个使用分析器但永远不会填充的虚拟字段。您可以找到如何执行此操作的示例 here.