我使用官方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);
谢谢。
答案 0 :(得分:1)
索引新文档时,您可以指定refresh
参数,以便在下次搜索操作时立即使用新文档。
$params = [
'index' => 'my-index',
'type' => 'my-type',
'id' => 123,
'refresh' => true <--- add this
];
$response = $client->index($params);
refresh
参数在bulk
操作中也可用。如果您正在使用它。
请注意,通常情况下,刷新可能会有negative impacts的效果。
答案 1 :(得分:0)
提供了刷新选项,需要一个值(以秒为单位)来刷新索引。例如,如果您在索引中更新某些内容,它将被写入索引但在索引刷新之前尚未准备好进行读取。
刷新可以设置为true,以便在发生任何更改时立即刷新索引。这需要非常仔细地考虑,因为很多时候,它会降低您的性能,因为每次小操作都需要刷新,而且许多批量刷新会使索引繁忙。
提示:使用elasticsearch插件(如kopf)并查看更多此类选项(如刷新率)进行配置。