Skip to content

Commit

Permalink
HSEARCH-4845 Use a different field for retrieving a root object id in…
Browse files Browse the repository at this point in the history
… the Lucene backend

- Temporary use a change until this is addressed in main

(cherry picked from commit f646ae1)
  • Loading branch information
marko-bekhta committed Jun 5, 2023
1 parent cabdf3d commit b7f405a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ private List<Document> assembleDocuments(MultiTenancyStrategy multiTenancyStrate
// We own the document content, so we finalize it ourselves.
Document document = documentContent.finalizeDocument( multiTenancyStrategy, tenantId, routingKey );
document.add( MetadataFields.searchableMetadataField( MetadataFields.typeFieldName(), MetadataFields.TYPE_MAIN_DOCUMENT ) );
document.add( MetadataFields.searchableRetrievableMetadataField( MetadataFields.idFieldName(), id ) );
document.add( MetadataFields.searchableMetadataField( MetadataFields.idFieldName(), id ) );
document.add( MetadataFields.retrievableMetadataField( MetadataFields.idDocValueFieldName(), id ) );

// In the list of documents, a child must appear before its parent,
// so we let children contribute their document first.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected DocumentReferenceValues(CollectorExecutionContext executionContext) {
@Override
public final void context(LeafReaderContext context) throws IOException {
this.currentLeafMappedTypeName = metadataResolver.resolveMappedTypeName( context );
this.currentLeafIdDocValues = DocValues.getBinary( context.reader(), MetadataFields.idFieldName() );
this.currentLeafIdDocValues = DocValues.getBinary( context.reader(), MetadataFields.idDocValueFieldName() );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class IdentifierValues implements Values<String> {

@Override
public void context(LeafReaderContext context) throws IOException {
this.currentLeafIdDocValues = DocValues.getBinary( context.reader(), MetadataFields.idFieldName() );
this.currentLeafIdDocValues = DocValues.getBinary( context.reader(), MetadataFields.idDocValueFieldName() );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@
public class MetadataFields {

private static final FieldType METADATA_FIELD_TYPE_WITH_INDEX;
private static final FieldType METADATA_FIELD_TYPE_WITH_INDEX_WITH_DOCVALUES;
private static final FieldType METADATA_FIELD_TYPE_WITH_DOCVALUES;
static {
METADATA_FIELD_TYPE_WITH_INDEX = new FieldType();
METADATA_FIELD_TYPE_WITH_INDEX.setTokenized( false );
METADATA_FIELD_TYPE_WITH_INDEX.setOmitNorms( true );
METADATA_FIELD_TYPE_WITH_INDEX.setIndexOptions( IndexOptions.DOCS );
METADATA_FIELD_TYPE_WITH_INDEX.freeze();

METADATA_FIELD_TYPE_WITH_INDEX_WITH_DOCVALUES = new FieldType();
METADATA_FIELD_TYPE_WITH_INDEX_WITH_DOCVALUES.setTokenized( false );
METADATA_FIELD_TYPE_WITH_INDEX_WITH_DOCVALUES.setOmitNorms( true );
METADATA_FIELD_TYPE_WITH_INDEX_WITH_DOCVALUES.setIndexOptions( IndexOptions.DOCS );
METADATA_FIELD_TYPE_WITH_INDEX_WITH_DOCVALUES.setDocValuesType( DocValuesType.BINARY );
METADATA_FIELD_TYPE_WITH_INDEX_WITH_DOCVALUES.freeze();
METADATA_FIELD_TYPE_WITH_DOCVALUES = new FieldType();
METADATA_FIELD_TYPE_WITH_DOCVALUES.setTokenized( false );
METADATA_FIELD_TYPE_WITH_DOCVALUES.setOmitNorms( true );
METADATA_FIELD_TYPE_WITH_DOCVALUES.setIndexOptions( IndexOptions.NONE );
METADATA_FIELD_TYPE_WITH_DOCVALUES.setDocValuesType( DocValuesType.BINARY );
METADATA_FIELD_TYPE_WITH_DOCVALUES.freeze();
}

private static final String INTERNAL_FIELD_PREFIX = "__HSEARCH_";

private static final String ID_FIELD_NAME = internalFieldName( "id" );

private static final String ID_DOCVALUE_FIELD_NAME = internalFieldName( "id_docvalue" );

private static final String ROUTING_KEY_FIELD_NAME = internalFieldName( "routing_key" );

private static final String TENANT_ID_FIELD_NAME = internalFieldName( "tenantId" );
Expand Down Expand Up @@ -64,14 +66,18 @@ public static IndexableField searchableMetadataField(String name, String value)
return new Field( name, value, METADATA_FIELD_TYPE_WITH_INDEX );
}

public static IndexableField searchableRetrievableMetadataField(String name, String value) {
return new Field( name, new BytesRef( value ), METADATA_FIELD_TYPE_WITH_INDEX_WITH_DOCVALUES );
public static IndexableField retrievableMetadataField(String name, String value) {
return new Field( name, new BytesRef( value ), METADATA_FIELD_TYPE_WITH_DOCVALUES );
}

public static String idFieldName() {
return ID_FIELD_NAME;
}

public static String idDocValueFieldName() {
return ID_DOCVALUE_FIELD_NAME;
}

public static String routingKeyFieldName() {
return ROUTING_KEY_FIELD_NAME;
}
Expand Down
6 changes: 5 additions & 1 deletion documentation/src/main/asciidoc/migration/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ Hibernate Search's requirements did not change in version {hibernateSearchVersio
[[data-format]]
== Data format and schema changes

Indexes created with Hibernate Search {hibernateSearchPreviousStableVersionShort}
Elasticsearch indexes created with Hibernate Search {hibernateSearchPreviousStableVersionShort}
can be read from and written to with Hibernate Search {hibernateSearchVersion}.

Reading and writing to Lucene indexes created with Hibernate Search {hibernateSearchPreviousStableVersionShort}
using Hibernate Search {hibernateSearchVersion} may lead to exceptions, since there were incompatible changes applied to internal fields.
You must recreate your Lucene indexes and reindex your database. The easiest way to do so is to use link:{hibernateSearchDocUrl}#indexing-massindexer[the `MassIndexer`] with link:{hibernateSearchDocUrl}#indexing-massindexer-parameters-drop-and-create-schema[`dropAndCreateSchemaOnStart(true)`].

If your Hibernate Search mapping includes `GeoPoint` fields that are using the default value for the `projectable` option,
and are using either the default value or `Sortable.NO` for the `sortable` option, Elasticsearch schema validation
will fail on startup because of missing docvalues on those fields.
Expand Down

0 comments on commit b7f405a

Please sign in to comment.