class ElasticSearchAdapter implements SearchAdapterInterface

Elastic Search Adapter Uses an Elastic Search Server for indexing and search operations in XELOS

Traits

Constants

protected ELASTIC_TYPE_NAME

ES7+ does only have a single type per index and is using _doc as dummy type

Properties

SearchController $mod
protected Client|null $elastic_client

ElasticSearch Client - is initialized on first getElasticSearchClient() call

protected string $recommendedESVersion

What is the expected/recommended elasticsearch version for this code?

protected string $elastic_index_name

ElasticSearch Index Name

protected string|null $elastic_alias_name

We will use the alias name as primary method to read, write to the index Default is {$elastic_index_name}-alias = xelos-alias

protected string $elastic_index_version

Increase this manually if changes to the index were made which required re-indexing Please note that not all operations can be done with a local reindex and may require an XELOS reindex process. You should cover this in MAJOR releases and with a proper install event.

protected int $elastic_shard_count

When using a single instance, using 1 shard will save memory When using a cluster, you should have at least 3 shards otherwise they cannot be balanced ES Defaults (v6=5, v7=1)

protected int $elastic_replica_count

When using a single instance, no replica will be started, even with replica=1 (Status will stay yellow) When using a cluster, you should use at least 1 replica - but we can also use 2 replica for more read performance ES Default: 1

protected int $elastic_tentant_id

Ability to use a shared elastic index

protected bool $aliasAccessOnly

When we have limited access - we may need to reduce some requests or they will fail and throw errors

Methods

__construct()

No description

string|null
_reindex(string $oldIndex, string $newIndex, bool $waitForCompletion = false)

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html

addToIndex(SearchIndexRecord $searchIndexRecord)

No description

void
bulkUpdateDocumentsByCallback(array $documentIds, callable $callback, string[] $requiredFields = ['_id', 'meta_data'])

Mass Update to update a few search index attributes for many documents at once This command will not create new Index entries but only update existing ones

cleanIndex()

No description

cleanupOldIndicesAndSnapshots()

Remove old Monitoring Indices todo: Might NOT be a good idea if ES is a shared instance.. , add config option and trigger in maintenance cron

bool
createIndexIfNotExists()

Create index if it does not exist and creation is possible

bool
createSnapshot()

Code is only here for documentation purposes / Work in Progress Requirement: add path.repo in config (e.g. path.repo=/usr/share/elasticsearch/data/backup )

createUpdateFilteredAlias(string $indexName = null, string $aliasName = null)

No description

bool
createUserAndRoleForAlias(string $user, string $password = null)

User will get access to the alias pointing to their index

deleteUserAndRole($user)

No description

string
getAliasName()

Get Elastic Index Name with Version suffix

array
getAttachmentFileExtensions(SearchIndexRecord $searchIndexRecord)

Returns all found file extensions of all attachments of SearchIndexRecord.

string
getAttachmentFulltextContent(SearchIndexRecord $searchIndexRecord)

Returns the fulltext content of all attachments of SearchIndexRecord.

string
getAttachmentsHash(SearchIndexRecord $searchIndexRecord)

Returns a combined hash string of all file contents of the attachments of SearchIndexRecord.

getDocumentIndexCollectionFromIndex(string $searchTerm, int $updatedSinceTimestamp = 0, string $pointInTimeReference = null, int $searchAfterReference = null, int $hitCount = null, bool $withSearchIndexInformation = false)

Returns a document index collection of search results without rights, instance access or group security checks.

Client
getElasticSearchClient()

Returns a connected Elastic Search Client Object

array
getFromIndex(DocumentIndex $DocumentIndex)

No description

bool
getHasRestrictedAccess()

No description

array
getIndexInfo()

No description

array
getIndexSchemaStatus()

Returns true if the index schema is uptodate, false if not.

array
getIndexSetting()

Get Index Settings

UIComponent|null
getMaintenanceUI()

No description

array[]
getSearchUpdateDSL(SearchUpdateRecord $searchUpdateRecord)

No description

array
getSnapshots()

Get list of snapshots taken

string
getUnsupportedElasticSearchVersion()

Get unsupported elastic search version

string
getVersionedIndexName()

Get Elastic Index Name with Version suffix This should be used when trying to create or delete index, use getAliasName for Search and Queries

bool
isSecurityPackAvailable()

Can we use xPackSecurity Features?

removeFromIndex(DocumentIndex $DocumentIndex)

No description

restoreSnapshot($nameOfSnapshotToRestore)

Restore a Snapshot, this function is not

search(array $query, array $options = [])

No description

setMod(SearchController $mod)

Used during Module Transition to allow a partial move to new Adapter Design

Details

at line 121
__construct()

No description

at line 792
protected string|null _reindex(string $oldIndex, string $newIndex, bool $waitForCompletion = false)

Parameters

string $oldIndex
string $newIndex
bool $waitForCompletion

If true, the request blocks until the operation is complete. Defaults to false.

Return Value

string|null

TASK ID

at line 150
addToIndex(SearchIndexRecord $searchIndexRecord)

No description

Parameters

SearchIndexRecord $searchIndexRecord

at line 1443
void bulkUpdateDocumentsByCallback(array $documentIds, callable $callback, string[] $requiredFields = ['_id', 'meta_data'])

Mass Update to update a few search index attributes for many documents at once This command will not create new Index entries but only update existing ones

Parameters

array $documentIds

List of document ids which shall be processed / updated

callable $callback

Function to be called for each document entry. Retrieves the requiredFields + ES document infos as an $hit array parameter

string[] $requiredFields

Return Value

void

Exceptions

NoNodeAvailableException

at line 505
cleanIndex()

No description

Exceptions

NoNodeAvailableException

at line 1330
protected cleanupOldIndicesAndSnapshots()

Remove old Monitoring Indices todo: Might NOT be a good idea if ES is a shared instance.. , add config option and trigger in maintenance cron

at line 695
protected bool createIndexIfNotExists()

Create index if it does not exist and creation is possible

Return Value

bool success

at line 1241
bool createSnapshot()

Code is only here for documentation purposes / Work in Progress Requirement: add path.repo in config (e.g. path.repo=/usr/share/elasticsearch/data/backup )

Return Value

bool success

at line 1345
protected createUpdateFilteredAlias(string $indexName = null, string $aliasName = null)

No description

Parameters

string $indexName
string $aliasName

at line 1377
protected bool createUserAndRoleForAlias(string $user, string $password = null)

User will get access to the alias pointing to their index

Parameters

string $user
string $password

Return Value

bool

TRUE if user was created, FALSE if user was updated

at line 1417
protected deleteUserAndRole($user)

No description

Parameters

$user

at line 829
string getAliasName()

Get Elastic Index Name with Version suffix

Return Value

string

in AttachmentTrait at line 47
protected array getAttachmentFileExtensions(SearchIndexRecord $searchIndexRecord)

Returns all found file extensions of all attachments of SearchIndexRecord.

Returns empty array if there are no attachments.

Parameters

SearchIndexRecord $searchIndexRecord

Return Value

array

in AttachmentTrait at line 18
protected string getAttachmentFulltextContent(SearchIndexRecord $searchIndexRecord)

Returns the fulltext content of all attachments of SearchIndexRecord.

Returns empty string if there are no attachments.

Parameters

SearchIndexRecord $searchIndexRecord

Return Value

string

in AttachmentTrait at line 73
protected string getAttachmentsHash(SearchIndexRecord $searchIndexRecord)

Returns a combined hash string of all file contents of the attachments of SearchIndexRecord.

Returns empty string if there are no attachments.

Parameters

SearchIndexRecord $searchIndexRecord

Return Value

string

at line 1542
DocumentIndexCollection getDocumentIndexCollectionFromIndex(string $searchTerm, int $updatedSinceTimestamp = 0, string $pointInTimeReference = null, int $searchAfterReference = null, int $hitCount = null, bool $withSearchIndexInformation = false)

Returns a document index collection of search results without rights, instance access or group security checks.

Parameters

string $searchTerm
int $updatedSinceTimestamp
string $pointInTimeReference
int $searchAfterReference
int $hitCount
bool $withSearchIndexInformation

Return Value

DocumentIndexCollection

Exceptions

ClientResponseException
MissingParameterException
ServerResponseException

at line 525
Client getElasticSearchClient()

Returns a connected Elastic Search Client Object

Make private as soon as old elastic search document has been migrated

Return Value

Client

Exceptions

NoNodeAvailableException

at line 278
array getFromIndex(DocumentIndex $DocumentIndex)

No description

Parameters

DocumentIndex $DocumentIndex

Return Value

array

= [ '_index'=>'xelos-v0001', 'found'=>true, '_source'=>[ 'document_index_id'=>int, 'title'=>string, 'last_index_update'=>'2019-12-13T13:12:12' ]]

Exceptions

NoNodeAvailableException

at line 836
bool getHasRestrictedAccess()

No description

Return Value

bool

at line 317
array getIndexInfo()

No description

Return Value

array

Array contains information with keys: document_count, instance_list, index_size

at line 846
array getIndexSchemaStatus()

Returns true if the index schema is uptodate, false if not.

Return Value

array

= ['errorState'=>true|false,'message' => string 'message']

Exceptions

Exception

at line 964
array getIndexSetting()

Get Index Settings

Return Value

array

at line 1150
UIComponent|null getMaintenanceUI()

No description

Return Value

UIComponent|null

at line 1118
array[] getSearchUpdateDSL(SearchUpdateRecord $searchUpdateRecord)

No description

Parameters

SearchUpdateRecord $searchUpdateRecord

Return Value

array[]

at line 1282
array getSnapshots()

Get list of snapshots taken

Return Value

array

[['snapshot'=>'nameOfSnapShot', 'version'=>'6.8.19', 'start_time' => '...', 'state'=>'SUCCESS']]

at line 544
string getUnsupportedElasticSearchVersion()

Get unsupported elastic search version

Return Value

string

at line 820
protected string getVersionedIndexName()

Get Elastic Index Name with Version suffix This should be used when trying to create or delete index, use getAliasName for Search and Queries

Return Value

string

at line 686
protected bool isSecurityPackAvailable()

Can we use xPackSecurity Features?

Return Value

bool

at line 239
removeFromIndex(DocumentIndex $DocumentIndex)

No description

Parameters

DocumentIndex $DocumentIndex

Exceptions

NoNodeAvailableException

at line 1303
restoreSnapshot($nameOfSnapshotToRestore)

Restore a Snapshot, this function is not

Parameters

$nameOfSnapshotToRestore

No description

Parameters

array $query
array $options

at line 310
setMod(SearchController $mod)

Used during Module Transition to allow a partial move to new Adapter Design

Parameters

SearchController $mod SearchController