mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-06 21:45:36 +00:00
perf: 优化ES模块
This commit is contained in:
parent
58cb49b125
commit
ed8e443f3a
@ -19,7 +19,7 @@ class ElasticSearchBase
|
|||||||
*
|
*
|
||||||
* @var \Elastic\Elasticsearch\Client
|
* @var \Elastic\Elasticsearch\Client
|
||||||
*/
|
*/
|
||||||
public $client;
|
protected $client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前操作的索引名称
|
* 当前操作的索引名称
|
||||||
@ -279,4 +279,30 @@ class ElasticSearchBase
|
|||||||
return ['error' => $e->getMessage(), 'hits' => ['total' => ['value' => 0], 'hits' => []]];
|
return ['error' => $e->getMessage(), 'hits' => ['total' => ['value' => 0], 'hits' => []]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 索引名称
|
||||||
|
*/
|
||||||
|
const indexName = 'default';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取索引名称
|
||||||
|
* @param string $index 索引名称
|
||||||
|
* @param string|null $prefix 索引前缀
|
||||||
|
* @param string|null $subfix 索引后缀
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function indexName($index = '', $prefix = '', $subfix = '')
|
||||||
|
{
|
||||||
|
$index = $index ?: static::indexName;
|
||||||
|
$prefix = $prefix ?: env('ES_INDEX_PREFIX', '');
|
||||||
|
$subfix = $subfix ?: env('ES_INDEX_SUFFIX', '');
|
||||||
|
if ($prefix) {
|
||||||
|
$index = rtrim($prefix, '_') . '_' . $index;
|
||||||
|
}
|
||||||
|
if ($subfix) {
|
||||||
|
$index = $index . '_' . ltrim($subfix, '_');
|
||||||
|
}
|
||||||
|
return $index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,8 @@ use Illuminate\Support\Facades\Log;
|
|||||||
*/
|
*/
|
||||||
class ElasticSearchKeyValue extends ElasticSearchBase
|
class ElasticSearchKeyValue extends ElasticSearchBase
|
||||||
{
|
{
|
||||||
|
const indexName = 'key_value_store';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造函数
|
* 构造函数
|
||||||
* @return ElasticSearchBase
|
* @return ElasticSearchBase
|
||||||
@ -27,15 +29,6 @@ class ElasticSearchKeyValue extends ElasticSearchBase
|
|||||||
/** *********************************** 键值存储方法 ******************************************************** */
|
/** *********************************** 键值存储方法 ******************************************************** */
|
||||||
/** ******************************************************************************************************** */
|
/** ******************************************************************************************************** */
|
||||||
|
|
||||||
/**
|
|
||||||
* 键值存储索引名称
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function indexName()
|
|
||||||
{
|
|
||||||
return "key_value_store" . env("ES_INDEX_SUFFIX", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建键值存储索引
|
* 创建键值存储索引
|
||||||
* @return array
|
* @return array
|
||||||
@ -55,8 +48,8 @@ class ElasticSearchKeyValue extends ElasticSearchBase
|
|||||||
'properties' => [
|
'properties' => [
|
||||||
'key' => ['type' => 'keyword'],
|
'key' => ['type' => 'keyword'],
|
||||||
'value' => ['type' => 'text', 'fields' => ['keyword' => ['type' => 'keyword']]],
|
'value' => ['type' => 'text', 'fields' => ['keyword' => ['type' => 'keyword']]],
|
||||||
'created_at' => ['type' => 'date'],
|
'created_at' => ['type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis'],
|
||||||
'updated_at' => ['type' => 'date']
|
'updated_at' => ['type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis']
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -97,8 +90,8 @@ class ElasticSearchKeyValue extends ElasticSearchBase
|
|||||||
'key' => $key,
|
'key' => $key,
|
||||||
'value' => is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value,
|
'value' => is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value,
|
||||||
'namespace' => $namespace,
|
'namespace' => $namespace,
|
||||||
'created_at' => date('Y-m-d H:i:s'),
|
'created_at' => date('Y-m-d\TH:i:s\Z', strtotime(date('Y-m-d H:i:s'))),
|
||||||
'updated_at' => date('Y-m-d H:i:s')
|
'updated_at' => date('Y-m-d\TH:i:s\Z', strtotime(date('Y-m-d H:i:s')))
|
||||||
];
|
];
|
||||||
|
|
||||||
// 索引文档
|
// 索引文档
|
||||||
|
|||||||
@ -14,6 +14,8 @@ use Illuminate\Support\Facades\Log;
|
|||||||
*/
|
*/
|
||||||
class ElasticSearchUserMsg extends ElasticSearchBase
|
class ElasticSearchUserMsg extends ElasticSearchBase
|
||||||
{
|
{
|
||||||
|
const indexName = 'dialog_user_msg';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造函数
|
* 构造函数
|
||||||
* @return ElasticSearchBase
|
* @return ElasticSearchBase
|
||||||
@ -28,15 +30,6 @@ class ElasticSearchUserMsg extends ElasticSearchBase
|
|||||||
/** *********************************************** 基础 ************************************************** */
|
/** *********************************************** 基础 ************************************************** */
|
||||||
/** ******************************************************************************************************** */
|
/** ******************************************************************************************************** */
|
||||||
|
|
||||||
/**
|
|
||||||
* 索引名称
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function indexName()
|
|
||||||
{
|
|
||||||
return "dialog_user_msg" . env("ES_INDEX_SUFFIX", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建聊天系统索引 - 使用父子关系
|
* 创建聊天系统索引 - 使用父子关系
|
||||||
* @return array
|
* @return array
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user