gpt4 book ai didi

php - Elasticsearch搜索在索引后延迟提取最新数据

转载 作者:行者123 更新时间:2023-12-03 01:52:49 25 4
gpt4 key购买 nike

我正在使用 PHP官方官方驱动程序连接到 Elasticsearch(v 2.3),每当我索引一个新文档时,它需要从 5秒 60秒才能将其纳入我的过滤结果中。如何将延迟时间减少到零?

这是我的索引查询

        # Document Body
$data = [];
$data['time'] = $time;
$data['unique'] = 1;
$data['lastACtivity'] = $time;
$data['bucket'] = 20,
$data['permission'] = $this->_user->permission; # Extracts User Permission
$data['ipaddress'] = $this->_client->ipaddress(); # Extracts User IP Address

# Construct Index
$indexRequest = [
'index' => 'gorocket',
'type' => 'log',
'refresh' => true,
'body' => $data
];

# Indexing Document
$confirmation = $client->index( $indexRequest );

这是我的搜索过滤器查询
# Query array
$query =[ 'query' => [
'filtered' => [
'filter' => [
'bool' => [
'must' =>[
[
'match' => [ 'unique' => 1 ]
],
[
'range' => [
'lastACtivity' => [
'gte' => $from,
'lte' => $to
],
'_cache' => false
]
]
],
'must_not' => [
[ 'match' => [ 'type' => 'share' ] ],
]
]
]
]
]
];

# Prepare filter parameters
$filterParams = [
'index' => 'gorocket',
'type' => 'log',
'size' => 20,
'query_cache' => false,
'body' => $query
];
$client->search($filterParams);

谢谢。

最佳答案

为新文档建立索引时,可以指定refresh参数,以使新文档可立即用于下一次搜索操作。

$params = [
'index' => 'my-index',
'type' => 'my-type',
'id' => 123,
'refresh' => true <--- add this
];
$response = $client->index($params);

如果正在使用 refresh操作,则 bulk参数也可用。

但是请注意,刷新频率过高可能会影响性能 negative impacts

关于php - Elasticsearch搜索在索引后延迟提取最新数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39037845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com