Yes, i create these properties dynamically, with template, these properties are strings:
IndexSchemaObjectField propertyField = context.indexSchemaElement().objectField(“property”);
propertyField.fieldTemplate(“propertyTemplate”, context.typeFactory().asString()
.sortable(Sortable.YES)
)
and then in bridge if product has any property
DocumentElement propertyFieldElement = target.addObject(fieldReference);
document.addValue(fieldName, propertyValue); //addValue(“A”, “A”), addValue(“B”, “B”)
in product search function I have
provider.addHibernateSearchSortField(Product.PROPERTY_A) //sorty by property.A
and sort function:
.sort(f → {
CompositeSortComponentsStep<?> composite = f.score().then().composite();
for (String sortField : sortFields) {
composite.add(f.field(sortField).missing().last());
}
return composite;
})
Mapping doesn’t change, only data that are indexed change every week. So sometimes product doesn’t have these properties required to sort.
When HS generate request to ES (sorting part in ElasticsearchStandardFieldSort.java)
if ( indexNames().size() > 1 ) { // is that restriction necessary?
unmappedType = builder.field.type().elasticsearchTypeAsJson(); //can be for example“keyword”
}
else {
unmappedType = null; // for single index always null
}
and then
if ( unmappedType != null && !DataTypes.SCALED_FLOAT.equals( unmappedType.getAsString() ) ) {
// There are multiple target indexes; some of them may not declare the field.
// Instruct ES to behave as if the field had no value in that case.
UNMAPPED_TYPE.set( innerObject, unmappedType );
}
So if HS knows that properties are string type then why cannot he just set proper unmapped_type for single index search? Or why cannot I choose to add unmapped_type or not?
Thank you for really fast reply.