冷技巧 / elasticsearch
Requires
- composer/installers: ^1.0.8
- elasticsearch/elasticsearch: ~7.13.0
Requires (Dev)
- coldtrick/sniffs: dev-master
Conflicts
- elgg/elgg: <4.1
This package is auto-updated.
Last update: 2023-06-02 08:40:59 UTC
README
为 Elgg 实现的 Elasticsearch
需求
需要一个正常工作的 ElasticSearch 服务器。另外,在您的 Elgg 安装中分钟 cron 也必须正常工作。分钟 cron 用于更新索引,以包含所有必要的更改(创建/更新/删除)。
当前支持的 ElasticSearch 版本是:7.4.x
配置
设置
插件设置允许您配置以下内容
- 主机:需要配置 1 个或多个主机(完整 URL + 可选端口号)。您可以使用逗号分隔提供更多主机。
- 索引:用于索引 Elgg 数据和搜索查询的索引名称
- 搜索别名(可选):用于搜索查询的别名名称,这允许轻松地在多个索引中进行搜索
索引管理
索引管理页面(在管理侧边栏的“管理”->“Elasticsearch”->“索引”下找到)允许您对 ElastisSearch 服务器上所有可用的索引执行各种操作。以下操作受支持
- 创建:如果插件设置页面中配置的索引尚不可用,则可以执行此操作。它将创建用于搜索的默认索引配置。
- 别名:向索引添加/删除配置的别名(这允许跨多个索引进行搜索)
- 删除:这将从服务器中删除索引(此操作无法撤销)
管理
日志文件
根据您的 Elgg 站点的日志级别,还将记录 ElasticSearch PHP 客户端库。日志将显示在所有其他 Elgg 日志相同的位置。
统计信息
您可以在“管理”->“Elasticsearch”->“统计”页面上找到各种统计信息。Elgg 统计报告关于 Elgg 数据库中应包含索引的实体数量。它还报告了需要添加/更新/删除的实体数量以及目前正在等待分钟 cron 处理的实体。
还会显示来自弹性集群的一些统计信息,例如状态和版本信息。
您还可以在此页面上找到所有可用索引的统计信息。
CLI 命令
CLI 命令可用于与默认的 elgg-cli
命令一起使用
elasticsearch:sync
此命令将同步所有挂起的实体到Elasticsearch索引。这在数据库重索引过程中非常有用,因为需要索引很多实体。在这种情况下使用常规的cron任务可能需要很长时间。
推荐
使用Search Advanced插件来添加额外的搜索功能。如果两者都启用,此插件提供菜单以排序/排列结果。
开发者
插件钩子
'boostable_types', 'elasticsearch'
返回一个数组,包含用于在Elasticsearch中配置提升的类型.subtype。
格式
[
'type.subtype',
]
默认为Elasticsearch注册的可搜索类型/subtype。
'config:index', 'elasticsearch'
返回一个数组,包含用于Elasticsearch的索引配置。
'config:mapping', 'elasticsearch'
返回一个数组,包含用于Elasticsearch的映射配置。
'export:counters', 'elasticsearch'
返回要导出到Elasticsearch的计数器数组。
格式
[
'counter_name' => counter_value
]
参数包含
entity
: 正在导出的ElggEntity
'export:metadata_names', 'elasticsearch'
返回要导出到Elasticsearch的元数据名称数组。
参数包含
entity
: 正在导出的ElggEntity
'index_entity_type_subtypes', 'elasticsearch'
返回一个数组,包含允许由Elasticsearch索引的类型/subtype。
格式
[ 'type' => ['subtype1', 'subtype2'], ]
默认为Elgg中注册的所有可搜索类型/subtype。
'index:entity:prevent', 'elasticsearch'
如果提供的实体不应添加到Elasticsearch索引,则返回true
参数包含
entity
: 即将索引的ElggEntity
默认: false
'index:entity:type', 'elasticsearch'
返回一个字符串,指定实体应索引的类型/subtype。这在搜索期间的类型过滤中使用(例如,所有博客)
参数包含
entity
: 即将索引的ElggEntity
default
: 此实体的默认类型/subtype
默认: {entity_type}.{entity_subtype}
(例如,object.blog
)
'params', 'elasticsearch'
返回一个数组,包含用于初始化\ColdTrick\ElasticSearch\Client
Elasticsearch客户端的参数。
'search', 'type_subtype_pairs'
返回一个数组,包含允许由Elasticsearch搜索的类型/subtype。
格式
[ 'type' => ['subtype1', 'subtype2'], ]
默认为Elgg中注册的所有可搜索类型/subtype。
'search_params', 'elasticsearch'
返回用于搜索的\ColdTrick\ElasticSearch\Di\SearchService
。这允许您更改Elasticsearch中的搜索参数。
参数包含
search_params
: Elgg搜索提供的搜索参数数组
'to:entity:before', 'elasticsearch'
在将其转换为ElggEntity
之前更改Elasticsearch命中数据
参数包含
hit
:来自Elasticsearch的结果search_params
: Elgg搜索提供的搜索参数数组
'to:entity', 'elasticsearch'
根据Elasticsearch的搜索结果数据返回一个ElggEntity
。
参数包含
hit
:来自Elasticsearch的结果search_params
: Elgg搜索提供的搜索参数数组
传递给elgg_search
的参数
field_boosting
在传递给elgg_search
的参数中,您可以添加一个配置来控制Elasticsearch中的字段提升。将键field_boosting
添加到包含字段名及其提升值的数组中。
示例
[ 'field_boosting' => [ 'title' => 2, // title is worth double 'description' => 0.5 // description is worth half ], ]