Rebuild search index from MySQL or Maven

Hi guys !

Does anyone know if it is possible to rebuild the OpenMRS database search index with either:

  • a MySQL command
  • or a Maven command ?

Something similar as to what happens when I go in the Administration/Search Index page and click on “Rebuild Search Index” http://localhost:8080/openmrs/admin/maintenance/searchIndex.htm

Can you give some bit of background of what you want to accomplish? :smile:

@dkayiwa

Here is the context: We currently have a CI server that weekly restores a database on a Dev server. We’ve noticed that the auto-complete fields in the HFE forms won’t work on this install until we do a Rebuild Search Index.

So we’d like to have Jenkins to automatically start an index rebuild when a new DB is restored. A Maven goal or a MySQL command looks like something very easy to run from Jenkins.

Hope that clarifies the question. Thanks

IIRC it’s a Java process (a Spring service). Not sure if it’s possible to invoke it from command line, probably not.

Would it help to simply copy over the lucene folder from the application data directory?

Yes, that would be a decent solution. I’ll give it a try and let you know

Also, could we expose a REST endpoint for this?

I guess the only API would be: POST …/conceptsearchindex { “update”: true }

-Darius

1 Like

That’d be great ! I’ll read through the documentation to find more details.

And do you think that if the task is properly worded and documented in JIRA, that could be something to work on for GSoC students ? (I have few other issues in mind that may fit too)

@mksrom it may be too small for GSOC. :smile: But generally, feel free to create tickets for things you feel would be useful to the community. We have a good number of potential GSOC students, and others, looking for intro and advanced tickets to work on.

As part of the CI task that resets the database, you need to execute a sql query to clear the value of the search.indexVersion global property before you restart openmrs, that will trigger the index to get rebuilt on start up

Thanks a lot @wyclif, this is perfect !

UPDATE global_property 
SET    global_property.property_value = "" 
WHERE  global_property.property = 'search.indexVersion';

Does the job, thanks.

1 Like

Can you create the JIRA task anyway? If the UI is angularized the WS is still needed.

@lluismf no need to do that, the SystemSettingResource already exists to expose CRUD operations for GPs via rest

@wyclif I disagree with this. I think we should move towards having consumer-friendly REST endpoints for all parts of managing the OpenMRS system.

Right now you’d have to do something like:

POST .../systemsetting/search.indexVersion
{ "propertyValue": "" }

This is not intuitive at all (and I’m not even sure it would work, with the dot in the GlobalProperty’s name, so you might need to do an extra call to find the UUID first).

Instead we should support something like:

DELETE .../conceptsearchindex

Did this ever get implemented?

1 Like

please even after rebuilding the search index i still search for clients