Hello,
I’m currently running Hibernate 5.2.15.Final, Hibernate Search 5.10.5.Final, and Elasticsearch 6.4. I have an an issue similar to the following issue Sorting on dynamic fields
This has nothing to do with sorting, but rather the created data type in elasticsearch/lucene. I’m creating an index field with a dynamic name based off of productId as follows:
@IndexedEmbedded
@Field( index = Index.YES, store = Store.NO, bridge = @FieldBridge( impl = IntegerAttributeDescriptionFieldBridge.class ), analyze = Analyze.NO )
public IntegerAttribute getIntegerAttribute()
{
if ( getIntegerAttributeValue() != null )
{
IntegerAttribute value = new IntegerAttribute();
value.setId( getAttributeId() );// UUID data type
value.setValue( getIntegerAttributeValue() ); ///Integer
return value;
}
return null;
}
In the field bridge, I have the following code:
@Override
public void set( String name, Object value, Document document, LuceneOptions luceneOptions )
{
if ( value != null )
{
IntegerAttribute integerIndex = (IntegerAttribute)value;
String dynamicFieldName = buildName( name, integerIndex.getId() );
Integer fieldValue = integerIndex.getValue();
log.info( "indexing attribute '{}' with value {} and trying to add with dynamic field name '{}'", name, fieldValue, dynamicFieldName );
// below works as storing the value as an integer, but I want the name to be the ID
luceneOptions.addNumericFieldToDocument( name, fieldValue, document );
// this creates the desired name for the attribute, but the value is stored as a String
luceneOptions.addNumericFieldToDocument( dynamicFieldName, fieldValue, document );
}
}
private String buildName( String name, UUID id )
{
return name.substring( 0, name.lastIndexOf( "." ) + 1 ).concat( id.toString() );
}
The problem is when I create the dynamic field - no matter how I define the field type - it ends up creating it as Text rather than an int. If I use the default name passed in - it correctly creates the field type as an int. But unfortunately, I have to perform a range queries against collections where the field (ie, the ID of the product) so that doesn’t work for me. The code above produces the following JSON in elasticsearch:
{
"id": "54976542-0c7a-4796-ba30-a755af916123",
"integerAttribute": 211,
"04976542-0c7a-4796-ba30-a755af916002": "211"
}
What I’m looking for is:
{
"id": "54976542-0c7a-4796-ba30-a755af916123",
"04976542-0c7a-4796-ba30-a755af916002": 211
}
The latter allows me to do range queries. What gives? Is this something that’s even possible? It looks like it should be? Please advise!
Thanks!