**# HAPI FHIR JPA Lucene/Elasticsearch Indexing

The HAPI JPA Server supports optional indexing via Hibernate Search when configured to use Lucene or Elasticsearch. This is required to support the _content, or _text search parameters.

6.11Experimental Extended Lucene/Elasticsearch Indexing

 

Additional indexing is implemented for simple search parameters of type token, string, and reference. These implement the basic search, as well as several modifiers: This experimental feature is enabled via the setAdvancedLuceneIndexing() property of DaoConfig.

String search

The Extended Lucene string search indexing supports the default search, as well as the modifiers defined in https://www.hl7.org/fhir/search.html#string.

  • Default searching matches by prefix, insensitive to case or accents
  • :exact matches the entire string, matching case and accents
  • :contains extends the default search to match any substring of the text
  • :text provides a rich search syntax as using a modified Simple Query Syntax.

Token search

The Extended Lucene Indexing supports the default token search by code, system, or system+code, as well as with the :text modifier. The :text modifier provides the same modified Simple Query Syntax used by string :text searches.
See https://www.hl7.org/fhir/search.html#token.

Modified Simple Query Syntax

The :text search for token and string, Hapi provides a modified version of the Simple Query Syntax provided by Lucene and Elasticsearch. Terms are delimited by whitespace, or query punctuation "()|+'. Literal uses of these characters must be escaped by ''. When the query only contains one or more bare terms, they are each converted to a prefix search to match the behaviour of a normal string search. When multiple terms are present, they must all match (i.e. AND). For OR behaviour use the | operator between terms. But if any special SQS syntax is active, the query is used as is. To ensure that the query is used as-is, quote bare terms with the " or character. E.g. `without any special syntax characters

Examples:

Fhir Query StringExecuted QueryMatchesNo MatchNote
SmitSmit*John SmithJohn Smi
Jo SmitJo* Smit*John SmithJohn FrankMultiple bare terms are AND
frank | johnfrank | johnFrank SmithFranklin SmithSQS characters disable prefix wildcard
'frank''frank'Frank SmithFranklin SmithQuoted terms are exact match

Quantity search

The Extended Lucene Indexing supports the quantity search.
See https://www.hl7.org/fhir/search.html#quantity.

URI search

The Extended Lucene Indexing supports the URI search.
See https://www.hl7.org/fhir/search.html#uri.

Date search

We support date searches using the eq, ne, lt, gt, ge, and le comparisons.
See https://www.hl7.org/fhir/search.html#date.

Supported Parameters for all resources

ParameterSupportedtype
_idno
_lastUpdatedyesdate
_tagyestoken
_profileyesURI
_securityyestoken
_textyesstring
_contentyesstring
_listno
_hasno
_typeno

Additional supported Parameters

ParameterSupportedtype
_sourceyesURI

ValueSet autocomplete extension

The Extended Lucene Indexing supports an extension of the $expand operation on ValueSet with a new contextDirection value of existing. In this mode, the context parameter is interpreted as a SearchParameter reference (by resource type and code), and the filter is interpreted as a query token. The expansion will contain the most frequent Coding values matching the filter. E.g. the query

GET /ValueSet/$expand?contextDirection=existing&context=Observation.code:text&filter=press

will return a ValueSet containing the most common values indexed under Observation.code whose display text contains a word starting with "press", such as http://loinc.org|8478-0 - "Mean blood pressure". This extension is only valid at the type level, and requires that Extended Lucene Indexing be enabled.

Resource Storage

As an experimental feature with the extended indexing, the full resource can be stored in the search index. This allows some queries to return results without using the relational database. Note: This does not support the $meta-add or $meta-delete operations. Full reindexing is required when this option is enabled after resources have been indexed.