重复索引字段定义:

Duplicate index field definition:

如何处理这种情况?这是我的实体 class

中定义的 属性
@Column(nullable = false)
@NotNull
@ApiModelProperty(required = true)
@Size(min = 3, max = 255)
@GenericField(sortable = Sortable.YES)
@FullTextField(analyzer = "lowercaseWhitespaceAnalyzer")
private String title;

异常:

HSEARCH400520: Duplicate index field definition: 'title'. Index field names must be unique. Look for two property mappings with the same field name, or two indexed-embeddeds with prefixes that lead to conflicting index field names, or two custom bridges declaring index fields with the same name.

我是否需要创建两个单独的字段,如文档中所示:

@FullTextField
@KeywordField(name = "title_sort", normalizer = "myNormalizer", sortable = Sortable.YES)
private String title;

如果我尝试这个得到下面的异常:

Invalid value. Expected 'lowercaseWhitespaceAnalyzer', actual is 'null' field 'context': attribute 'type': failures: - Invalid value. Expected 'text', actual is 'keyword' attribute 'analyzer': failures: - Invalid value. Expected 'lowercaseWhitespaceAnalyzer', actual is 'null' field 'context_sort': failures: - Missing property mapping

Do I need to create two separate fields as shown in the documentation like:

是的,确实如此。

If I tried this getting below exception:

Invalid value. Expected 'lowercaseWhitespaceAnalyzer', actual is 'null' field 'context': attribute 'type': failures: - Invalid value. Expected 'text', actual is 'keyword' attribute 'analyzer': failures: - Invalid value. Expected 'lowercaseWhitespaceAnalyzer', actual is 'null' field 'context_sort': failures: - Missing property mapping

如果您查看此错误的完整上下文(您未在此处包含),您会注意到它说的是“Elasticsearch 架构验证失败”之类的内容。

简而言之,Elasticsearch 上已经存在的索引架构与 Hibernate Search 实现您用注释描述的内容所需的架构不匹配。

您应该删除 Elasticsearch 架构并 re-create 它(您将丢失所有索引数据并需要重新索引)。您可以手动完成,也可以让 Hibernate Search 为您完成;参见 this section of the documentation