hapifhir / hapi-fhir

đŸ”¥ HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
1.95k stars 1.3k forks source link

$reindex does not update lucene / elastic index #5864

Open jnugh opened 2 months ago

jnugh commented 2 months ago

Describe the bug The $reindex operation does not recreate the resourcetable index when advancedHSearchIndexing is enabled. Even though data is being indexed when writing resources using POST / PUT.

To Reproduce Steps to reproduce the behavior:

  1. Set up a server with elasticsearch index (using jpa starter enable: advanced_lucene_indexing, elasticsearch.*, hibernate.search.backend.type: elasticsearch)
  2. Create some Resources (e.g. using POST / PUT)
  3. Delete data from the elasticsearch index (or switch the options from above on at this point)
  4. POST to /fhir/$reindex
  5. Da a search e.g. using _contents

Expected behavior It should return matching results after reindex, even though they have been manually removed from the index.

Environment (please complete the following information):

Additional context I did some debugging already. When updating an entity the lucene indexer creates a new elasticsearch document when https://github.com/hapifhir/hapi-fhir/blob/master/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java#L2282

        return myTransactionService
                .withRequest(theRequest)
                .withTransactionDetails(theTransactionDetails)
                .withRequestPartitionId(requestPartitionId)
                .onRollback(onRollback)
                .execute(updateCallback);

is being called inside the update method. During reindex this dos not happen. reindex calls reindexSearchParameters which correctly updates the index tables but does not write the resource itself. Thus never reaching the search index logic.

FloK8 commented 6 days ago

I have the same problem. Any update on this?