php 分页 查询 es,php-如何使分页elasticsearch?
我是Elasticsearch的新手.
我不知道要分頁.
我的代碼:
require_once 'app/init.php';
if(isset ($_GET['q'])) {
$q = $_GET['q'];
$query = $es->search([
'index' => 'user',
'type' => 'profile',
'body' => [
'query' => [
'bool' => [
'should' => [
'match' => ['bio' => $q]
]
]
]
]
]);
if ($query['hits']['total'] >=1) {
$results= $query['hits']['hits'];
}
}
?>
Search | ESSearch
if (isset($results)) {
foreach ($results as $r) {
?>
}
}
?>
以及如何進行這樣的分頁:
解決方法:
您在這里需要兩件事,總頁數和從一頁導航到另一頁的方式.
當您使用簡單的Query-> filter-> bool查詢elassticsearch時
它在響應JSON中返回匹配,即結果總數.用您想要在應用程序上顯示的結果數除以它們,您將獲得頁面.
在您的PHP-elasticsearch請求對象中使用from和size屬性,并在頁面之間導航時不斷變化.查詢示例(考慮第3頁和第10頁的尺寸)
{
"from": 20,
"size": 10,
"query": {
"bool": {
"must": [
{
"term": {
"FIELD": {
"value": "VALUE"
}
}
}
]
}
}
}
標簽:elasticsearch,php
來源: https://codeday.me/bug/20191119/2036683.html
總結
以上是生活随笔為你收集整理的php 分页 查询 es,php-如何使分页elasticsearch?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java new 删除吗,java泛型对
- 下一篇: 玉米油QBBAH0025S是什么意思?