| I have a scenario in which indexing works perfectly fine in a simple hibernate-search Elasticsearch integration setup, but the same fails when sharding is enabled. On debugging I see that the json data generated by hibernate search with sharding enabled is incorrect. More details below:
@Entity
public class AT {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "ARRM_IDE", nullable = false)
private A arr;
private Date dateType;
(and other fields)
}
@Entity
public class A {
@Id
@SequenceGenerator(name = "C_SEQUENCE", sequenceName = "S_ARRM_01")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "C_SEQUENCE")
@Column(name = "IDE_ARR")
private Long id;
}
SearchMapping mapping = new SearchMapping();
mapping.entity(AT.class).indexed()
.property("dateType", ElementType.FIELD)
.field()
.store(Store.YES)
.analyze(Analyze.NO)
.property("arr", ElementType.FIELD)
.indexEmbedded()
.entity(A.class).indexed()
.property("id", ElementType.FIELD).documentId().name("arrId")
.field()
.store(Store.YES)
.analyze(Analyze.NO)
;
without sharding in place the schema mapping and the insert data are like this:
{"dynamic":"strict","properties":{"__HSearch_TenantId":{"type":"string","index":"not_analyzed"},"arr":{"properties":{"id":{"type":"long","store":true,"index":"not_analyzed","boost":1.0}}},"dateType":{"type":"date","store":true,"index":"not_analyzed","boost":1.0}}}"
"{"dateType":"2016-06-22T00:53:19Z","arr":{"id":15302}}"
I added the following to enable sharding
<property name="hibernate.search.at.sharding_strategy" value="com....ATShardIdentifierProvider" />
with this the mapping is same as above and insert data is as follows:
"{"dateType":"2016-06-22T01:05:08Z","id":15402}"
and the indexing clearly then fails with:
Status: 400
Error message: {"root_cause":[{"type":"strict_dynamic_mapping_exception","reason":"mapping set to strict, dynamic introduction of [id] within [AT] is not allowed"}],"type":"strict_dynamic_mapping_exception","reason":"mapping set to strict, dynamic introduction of [id] within [AT] is not allowed"}
Cluster name: null
Cluster status: 400
I am attaching a zip file containing a self contained testcase that can be used to reproduce this issue easily. We have to either fix it or explicitly state that it is not a supported configuration and throw a proper error. |